import{a as k}from"./chunk-JAY45DEO.js";import{b as C}from"./chunk-F4GTCTBH.js";import{c as S}from"./chunk-WXQVX7WD.js";import{m as v,n as y,o as x,p as b}from"./chunk-OWZ5YAMH.js";import{a as _}from"./chunk-KXX3UDJ3.js";import{j}from"./chunk-GQAU5ACB.js";import{S as n,fa as l,k as a,la as p,pa as A,qa as P}from"./chunk-ISMRT7VU.js";import{a as o,b as I}from"./chunk-M5TX2NVG.js";function O(t,i){if(t===i)return!0;if(t===null||i===null||typeof t!=typeof i)return!1;if(Array.isArray(t)&&Array.isArray(i))return t.length!==i.length?!1:t.every((e,r)=>O(e,i[r]));if(typeof t=="object"&&typeof i=="object"){let e=Object.keys(t),r=Object.keys(i);return e.length!==r.length?!1:e.every(s=>O(t[s],i[s]))}return!1}function h(t){return t==null}function T(t){return h(t)?!0:Array.isArray(t)||typeof t=="string"?t.length===0:typeof t=="object"?Object.keys(t).length===0:!1}function E(t,i){let e=o({},t);for(let r of i)delete e[r];return e}function g(t){return h(t)?null:k(t,{representation:"complete"})}function B(t){return h(t)?null:new Date(t.setHours(23,59,59,999))}var d=(()=>{class t{static{this.type="[Prices] Set Prices"}constructor(e){this.prices=e}}return t})();var c=class m{static prices(i){return i.prices}setPrices(i,e){i.setState(o({},e.prices))}clearCharacteristics(i){i.setState({prices:[]})}static{this.\u0275fac=function(e){return new(e||m)}}static{this.\u0275prov=p({token:m,factory:m.\u0275fac})}};a([y(d)],c.prototype,"setPrices",null);a([y(C)],c.prototype,"clearCharacteristics",null);a([b()],c,"prices",null);c=a([x({name:"prices",defaults:{prices:[]}})],c);var w=(()=>{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:_})}static{this.\u0275fac=function(r){return new(r||t)(A(j))}}static{this.\u0275prov=p({token:t,factory:t.\u0275fac})}}return t})();var oe=(()=>{class t{constructor(){this._store=P(v),this._priceServiceApi=P(w),this._storeId=this._store.selectSignal(S.selectedStoreId),this._retailStores=this._store.selectSignal(S.stores),this._prices=this._store.selectSignal(c.prices)}get defaultPriceId(){return this._prices().find(r=>r.defaultInStores?.some(s=>s.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()),n(1))}updatePrice(e,r){return this._priceServiceApi.updatePrice(e,this._toUpsertModel(r)).pipe(l(()=>this.getPrices().subscribe()),n(1))}deletePrice(e){return this._priceServiceApi.deletePrice(e).pipe(l(()=>this.getPrices().subscribe()),n(1))}getPrices(e=!1){return this._priceServiceApi.getPrices(e).pipe(l(r=>this._store.dispatch(new d({prices:r}))),n(1))}syncPrice(){return this._priceServiceApi.syncPrice().pipe(n(1))}defaultPrice(e,r=this.defaultPriceId){if(!e.length)return 0;let s=e.find(u=>u.id===r);return s?s.value:0}priceNameById(e=this.defaultPriceId){let r=this._prices().find(s=>s.id===e);return r?r.name:""}updateOrAddPrice(e,r,s){let u=e.findIndex(f=>f.id===r);return u!==-1?e.map((f,D)=>D===u?I(o({},f),{value:s}):f):[...e,{id:r,value:s}]}_toUpsertModel(e){return{type:e.type,name:e.name,from:e.period?g(e.period[0]):null,to:e.period?g(e.period[1]):null}}static{this.\u0275fac=function(r){return new(r||t)}}static{this.\u0275prov=p({token:t,factory:t.\u0275fac})}}return t})();export{O as a,h as b,T as c,E as d,w as e,c as f,g,B as h,oe as i};
//# sourceMappingURL=chunk-JSG72ZNQ.js.map
