import{a as k}from"./chunk-JAY45DEO.js";import{d as I}from"./chunk-RTKDH4JU.js";import{b as U}from"./chunk-IFY4UZPR.js";import{c as y}from"./chunk-UU4K5RCK.js";import{p as A,q as S,r as j,s as C}from"./chunk-JBWPPKX4.js";import{a as _}from"./chunk-7N232KV6.js";import{i as x}from"./chunk-NDLDFKR2.js";import{$ as l,K as p,fa as a,ka as g,la as P}from"./chunk-PVUKHE45.js";import{d as n,n as F}from"./chunk-VD6R3735.js";import{a as d,b}from"./chunk-MZPAXKJS.js";function v(i){return I(i)?null:k(i,{representation:"complete"})}function O(i){return I(i)?null:new Date(i.setHours(23,59,59,999))}F();var f=(()=>{let t=class t{constructor(e){this.prices=e}};t.type="[Prices] Set Prices";let i=t;return i})();var s,o=(s=class{static prices(t){return t.prices}setPrices(t,m){t.setState(d({},m.prices))}clearCharacteristics(t){t.setState({prices:[]})}},s.\u0275fac=function(m){return new(m||s)},s.\u0275prov=a({token:s,factory:s.\u0275fac}),s);n([S(f)],o.prototype,"setPrices",null);n([S(U)],o.prototype,"clearCharacteristics",null);n([C()],o,"prices",null);o=n([j({name:"prices",defaults:{prices:[]}})],o);var D=(()=>{let t=class t{constructor(e){this._http=e}createPrice(e){return this._http.post("/api/price",e)}updatePrice(e,r){return this._http.put(`/api/price/${e}`,r)}deletePrice(e){return this._http.delete(`/api/price/${e}`)}getPrices(e=!1){return e?this._http.post("/api/price/all",{},{headers:_}):this._http.post("/api/price/all",{})}syncPrice(){return this._http.post("/api/price/sync",{},{headers:_})}};t.\u0275fac=function(r){return new(r||t)(g(x))},t.\u0275prov=a({token:t,factory:t.\u0275fac});let i=t;return i})();var ie=(()=>{let t=class t{constructor(){this._store=P(A),this._priceServiceApi=P(D),this._storeId=this._store.selectSignal(y.selectedStoreId),this._retailStores=this._store.selectSignal(y.stores),this._prices=this._store.selectSignal(o.prices)}get defaultPriceId(){return this._prices().find(r=>r.defaultInStores?.some(c=>c.id===this._storeId()))?.id??this._prices()[0].id}get availablePrices(){return this._retailStores().find(e=>e.id===this._storeId())?.availablePriceIds??[]}createPrice(e){return this._priceServiceApi.createPrice(this._toUpsertModel(e)).pipe(l(()=>this.getPrices().subscribe()),p(1))}updatePrice(e,r){return this._priceServiceApi.updatePrice(e,this._toUpsertModel(r)).pipe(l(()=>this.getPrices().subscribe()),p(1))}deletePrice(e){return this._priceServiceApi.deletePrice(e).pipe(l(()=>this.getPrices().subscribe()),p(1))}getPrices(e=!1){return this._priceServiceApi.getPrices(e).pipe(l(r=>this._store.dispatch(new f({prices:r}))),p(1))}syncPrice(){return this._priceServiceApi.syncPrice().pipe(p(1))}defaultPrice(e,r=this.defaultPriceId){if(!e.length)return 0;let c=e.find(u=>u.id===r);return c?c.value:0}priceNameById(e=this.defaultPriceId){let r=this._prices().find(c=>c.id===e);return r?r.name:""}updateOrAddPrice(e,r,c){let u=e.findIndex(h=>h.id===r);return u!==-1?e.map((h,T)=>T===u?b(d({},h),{value:c}):h):[...e,{id:r,value:c}]}_toUpsertModel(e){return{type:e.type,name:e.name,from:e.period?v(e.period[0]):null,to:e.period?v(e.period[1]):null}}};t.\u0275fac=function(r){return new(r||t)},t.\u0275prov=a({token:t,factory:t.\u0275fac});let i=t;return i})();export{D as a,o as b,v as c,O as d,ie as e};
//# sourceMappingURL=chunk-SMAIR2YP.js.map
