import{a as U}from"./chunk-UXD3EAB2.js";import{s as K}from"./chunk-RY26U3LV.js";import{b as Y}from"./chunk-USCTV2R5.js";import{A as w,B as X,D as A,e as F,f as G,g as L,v as S,x as R}from"./chunk-QYQ7WNYU.js";import{Ld as W,a as P,b as V}from"./chunk-HC2G7LSI.js";function Q(){return{ids:[],entities:{}}}function Z(){function t(c={}){return Object.assign(Q(),c)}return{getInitialState:t}}function _(){function t(c){let o=h=>h.ids,d=h=>h.entities,p=S(o,d,(h,m)=>h.map(M=>m[M])),y=S(o,h=>h.length);return c?{selectIds:S(c,o),selectEntities:S(c,d),selectAll:S(c,p),selectTotal:S(c,y)}:{selectIds:o,selectEntities:d,selectAll:p,selectTotal:y}}return{getSelectors:t}}var s=function(t){return t[t.EntitiesOnly=0]="EntitiesOnly",t[t.Both=1]="Both",t[t.None=2]="None",t}(s||{});function f(t){return function(o,d){let p={ids:[...d.ids],entities:P({},d.entities)},y=t(o,p);return y===s.Both?Object.assign({},d,p):y===s.EntitiesOnly?V(P({},d),{entities:p.entities}):d}}function I(t,c){let o=c(t);return W()&&o===void 0&&console.warn("@ngrx/entity: The entity passed to the `selectId` implementation returned undefined.","You should probably provide your own `selectId` implementation.","The entity that was passed:",t,"The `selectId` implementation:",c.toString()),o}function q(t){function c(a,r){let n=I(a,t);return n in r.entities?s.None:(r.ids.push(n),r.entities[n]=a,s.Both)}function o(a,r){let n=!1;for(let e of a)n=c(e,r)!==s.None||n;return n?s.Both:s.None}function d(a,r){return r.ids=[],r.entities={},o(a,r),s.Both}function p(a,r){let n=I(a,t);return n in r.entities?(r.entities[n]=a,s.EntitiesOnly):(r.ids.push(n),r.entities[n]=a,s.Both)}function y(a,r){let n=a.map(e=>p(e,r));switch(!0){case n.some(e=>e===s.Both):return s.Both;case n.some(e=>e===s.EntitiesOnly):return s.EntitiesOnly;default:return s.None}}function h(a,r){return m([a],r)}function m(a,r){let e=(a instanceof Array?a:r.ids.filter(i=>a(r.entities[i]))).filter(i=>i in r.entities).map(i=>delete r.entities[i]).length>0;return e&&(r.ids=r.ids.filter(i=>i in r.entities)),e?s.Both:s.None}function M(a){return Object.assign({},a,{ids:[],entities:{}})}function b(a,r,n){let e=n.entities[r.id],i=Object.assign({},e,r.changes),u=I(i,t),l=u!==r.id;return l&&(a[r.id]=u,delete n.entities[r.id]),n.entities[u]=i,l}function B(a,r){return O([a],r)}function O(a,r){let n={};return a=a.filter(i=>i.id in r.entities),a.length>0?a.filter(u=>b(n,u,r)).length>0?(r.ids=r.ids.map(u=>n[u]||u),s.Both):s.EntitiesOnly:s.None}function v(a,r){let e=r.ids.reduce((i,u)=>{let l=a(r.entities[u]);return l!==r.entities[u]&&i.push({id:u,changes:l}),i},[]).filter(({id:i})=>i in r.entities);return O(e,r)}function j({map:a,id:r},n){let e=n.entities[r];if(!e)return s.None;let i=a(e);return B({id:r,changes:i},n)}function k(a,r){return x([a],r)}function x(a,r){let n=[],e=[];for(let l of a){let g=I(l,t);g in r.entities?e.push({id:g,changes:l}):n.push(l)}let i=O(e,r),u=o(n,r);switch(!0){case(u===s.None&&i===s.None):return s.None;case(u===s.Both||i===s.Both):return s.Both;default:return s.EntitiesOnly}}return{removeAll:M,addOne:f(c),addMany:f(o),setAll:f(d),setOne:f(p),setMany:f(y),updateOne:f(B),updateMany:f(O),upsertOne:f(k),upsertMany:f(x),removeOne:f(h),removeMany:f(m),map:f(v),mapOne:f(j)}}function $(t,c){let{removeOne:o,removeMany:d,removeAll:p}=q(t);function y(n,e){return h([n],e)}function h(n,e){let i=n.filter(u=>!(I(u,t)in e.entities));return i.length===0?s.None:(r(i,e),s.Both)}function m(n,e){return e.entities={},e.ids=[],h(n,e),s.Both}function M(n,e){let i=I(n,t);return i in e.entities?(e.ids=e.ids.filter(u=>u!==i),r([n],e),s.Both):y(n,e)}function b(n,e){let i=n.map(u=>M(u,e));switch(!0){case i.some(u=>u===s.Both):return s.Both;case i.some(u=>u===s.EntitiesOnly):return s.EntitiesOnly;default:return s.None}}function B(n,e){return v([n],e)}function O(n,e,i){if(!(e.id in i.entities))return!1;let u=i.entities[e.id],l=Object.assign({},u,e.changes),g=I(l,t);return delete i.entities[e.id],n.push(l),g!==e.id}function v(n,e){let i=[],u=n.filter(l=>O(i,l,e)).length>0;if(i.length===0)return s.None;{let l=e.ids,g=[];return e.ids=e.ids.filter((E,T)=>E in e.entities?!0:(g.push(T),!1)),r(i,e),!u&&g.every(E=>e.ids[E]===l[E])?s.EntitiesOnly:s.Both}}function j(n,e){let i=e.ids.reduce((u,l)=>{let g=n(e.entities[l]);return g!==e.entities[l]&&u.push({id:l,changes:g}),u},[]);return v(i,e)}function k({map:n,id:e},i){let u=i.entities[e];if(!u)return s.None;let l=n(u);return B({id:e,changes:l},i)}function x(n,e){return a([n],e)}function a(n,e){let i=[],u=[];for(let E of n){let T=I(E,t);T in e.entities?u.push({id:T,changes:E}):i.push(E)}let l=v(u,e),g=h(i,e);switch(!0){case(g===s.None&&l===s.None):return s.None;case(g===s.Both||l===s.Both):return s.Both;default:return s.EntitiesOnly}}function r(n,e){n.sort(c);let i=[],u=0,l=0;for(;u<n.length&&l<e.ids.length;){let g=n[u],E=I(g,t),T=e.ids[l],J=e.entities[T];c(g,J)<=0?(i.push(E),u++):(i.push(T),l++)}u<n.length?e.ids=i.concat(n.slice(u).map(t)):e.ids=i.concat(e.ids.slice(l)),n.forEach((g,E)=>{e.entities[t(g)]=g})}return{removeOne:o,removeMany:d,removeAll:p,addOne:f(y),updateOne:f(B),upsertOne:f(x),setAll:f(m),setOne:f(M),setMany:f(b),addMany:f(h),updateMany:f(v),upsertMany:f(a),map:f(j),mapOne:f(k)}}function z(t={}){let{selectId:c,sortComparer:o}={selectId:t.selectId??(h=>h.id),sortComparer:t.sortComparer??!1},d=Z(),p=_(),y=o?$(c,o):q(c);return P(P(P({selectId:c,sortComparer:o},d),p),y)}var N=z(),H=N.getInitialState();var C=G({source:"Category Product Card",events:{getPricesByIds:F(),getPricesByIdsSuccess:F(),getPricesByIdsError:F(),clearPrices:L()}});function D(t,c,o){return o?.map(d=>({id:d,changes:{variantPriceTypes:V(P({},c.entities[d]?.variantPriceTypes),{[t]:{priceType:t,price:{status:A.loading}}})}}))||[]}function ee(t,c,o){let d={};return Object.keys(U).forEach(p=>{let y=c.find(M=>M.productPriceType===p),h=t?.[p].price,m;y?m={data:y,status:y.prices?A.success:A.error}:p===o?m=V(P({},h),{status:A.error}):m=h,d[p]={priceType:p,price:m}}),d}function te(t,c,o){return o?.map(d=>({id:d.id,changes:{variantPriceTypes:P({},ee(c.entities[d.id]?.variantPriceTypes,d.prices,t))}}))||[]}function ne(t,c,o){return o?.map(d=>({id:d,changes:{variantPriceTypes:V(P({},c.entities[d]?.variantPriceTypes),{[t]:{priceType:t,price:{status:A.error}}})}}))}function re(t,c){return t?{data:P({},t),status:A.success}:c||{status:A.initial}}function ie(t,c){let o={};return Object.keys(U).forEach(d=>{let p=t.find(h=>h.productPriceType===d),y=c?.variantPriceTypes[d].price;o[d]={priceType:d,price:re(p,y)}}),o}function se(t,c){return t.flatMap(o=>o.variants).map(o=>{let d=c.ids.some(y=>Number(y)===o.id),p;return d&&(p=c.entities[o.id]),{id:o.id,variantPriceTypes:ie(o.prices,p)}})}var Se=R({name:"categoryVariantsPricesSearch",reducer:X(H,w(Y,(t,{result:c})=>N.upsertMany(se(c.content,t),t)),w(C.getPricesByIds,(t,{priceType:c,noPriceIds:o})=>N.updateMany(D(c,t,o),t)),w(C.getPricesByIdsSuccess,(t,{priceType:c,prices:o})=>N.updateMany(te(c,t,o),t)),w(C.getPricesByIdsError,(t,{priceType:c,variantsIds:o})=>N.updateMany(ne(c,t,o),t)),w(C.clearPrices,t=>N.removeAll(t))),extraSelectors:({selectIds:t,selectCategoryVariantsPricesSearchState:c,selectEntities:o})=>{let d=(m,M)=>S(o,b=>b[M]?.variantPriceTypes?.[m].price),p=(m,M)=>S(K.selectVariant(M),d(m,M),(b,B)=>({variantInfo:b,variantPrice:B})),y=(m,M)=>S(o,K.selectGroupVariants(M),(b,B)=>B?.filter(O=>{let v=b[O.id]?.variantPriceTypes?.[m]?.price;return O.stockAvailability!=="noStock"&&O.stockAvailability!=="expired"&&v?.status!==A.loading&&!v?.data?.prices?.length}).map(O=>O.id)||[]);return{selectCurrentVariantAndInStockVariantsWithoutPrice:(m,M,b)=>S(p(m,b),y(m,M),(B,O)=>({currentVariant:B,inStockVariantsWithoutPrice:O})),selectVariantsPrices:o}}});export{C as a,Se as b};