import{a as x,c as k,e as Q,f as Z,i as q}from"./chunk-WWG2KFJV.js";import{T as v,U,V as E,W as H}from"./chunk-WZSFHN7K.js";import{Ce as V,Ee as A,J as g,Pe as O,Sf as L,Vf as M,bg as m,eg as F,id as $,if as D,la as l,lf as S,ma as N,md as u,oa as c,od as b,pa as h,pf as C,s as y,td as P,ua as R,ue as j,uf as T}from"./chunk-N6B2OJOY.js";import{a as f,b as w}from"./chunk-GHL4OFBQ.js";var J=(()=>{let r=class r{constructor(t){this.converter=t}convert(t,e){return e===void 0&&(e=f({},t)),this.removeDuplicatePromotions(t,e),this.handleQuoteCode(t,e),t.entries&&(e.entries=t.entries.map(i=>w(f({},i),{product:this.converter.convert(i.product,F),promotions:this.converter.convert({item:i,promotions:e?.appliedProductPromotions},U)}))),e}handleQuoteCode(t,e){t.sapQuote&&(e.quoteCode=t.sapQuote.code)}removeDuplicatePromotions(t,e){t&&t.potentialOrderPromotions&&(e.potentialOrderPromotions=this.removeDuplicateItems(t.potentialOrderPromotions)),t&&t.potentialProductPromotions&&(e.potentialProductPromotions=this.removeDuplicateItems(t.potentialProductPromotions)),t&&t.appliedOrderPromotions&&(e.appliedOrderPromotions=this.removeDuplicateItems(t.appliedOrderPromotions)),t&&t.appliedProductPromotions&&(e.appliedProductPromotions=this.removeDuplicateItems(t.appliedProductPromotions))}removeDuplicateItems(t){return t.filter((e,i,o)=>{let s=o.map(a=>JSON.stringify(a));return i===s.indexOf(JSON.stringify(e))})}};r.\u0275fac=function(e){return new(e||r)(c(m))},r.\u0275prov=l({token:r,factory:r.\u0275fac,providedIn:"root"});let n=r;return n})(),W=(()=>{let r=class r{convert(t,e){return e=this.getProductPromotion(t.item,t.promotions),e}getProductPromotion(t,e){let i=[];return e?.forEach(o=>{if(o.description&&o.consumedEntries)for(let s of o.consumedEntries)this.isConsumedByEntry(s,t)&&i.push(o)}),i}isConsumedByEntry(t,e){let i=t.orderEntryNumber;if(e&&e.entries&&e.entries.length>0){for(let o of e.entries)if(o.entryNumber===i)return!0;return!1}else return i===e?.entryNumber}};r.\u0275fac=function(e){return new(e||r)},r.\u0275prov=l({token:r,factory:r.\u0275fac,providedIn:"root"});let n=r;return n})(),B=(()=>{let r=class r{constructor(t,e,i){this.http=t,this.occEndpointsService=e,this.converterService=i}add(t,e,i,o=1,s){let a=this.occEndpointsService.buildUrl("addEntries",{urlParams:{userId:t,cartId:e,quantity:o}});if(a.includes(`quantity=${o}`)){let I=new u({"Content-Type":"application/x-www-form-urlencoded"});return this.http.post(a,{},{headers:I,params:{code:i}}).pipe(this.converterService.pipeable(E))}let d=f({quantity:o,product:{code:i}},s&&{deliveryPointOfService:{name:s}}),p=new u({"Content-Type":"application/json"});return this.http.post(a,d,{headers:p}).pipe(this.converterService.pipeable(E))}update(t,e,i,o,s,a=!1){let d=new u({"Content-Type":"application/json"}),p=this.occEndpointsService.buildUrl("updateEntries",{urlParams:{userId:t,cartId:e,entryNumber:i}});if(s===void 0&&a)return this.http.put(p,{quantity:o},{headers:d}).pipe(this.converterService.pipeable(E));let I={};return s&&(I={deliveryPointOfService:{name:s}}),this.http.patch(p,f({quantity:o},I),{headers:d}).pipe(this.converterService.pipeable(E))}remove(t,e,i){let o=new u({"Content-Type":"application/x-www-form-urlencoded"}),s=this.occEndpointsService.buildUrl("removeEntries",{urlParams:{userId:t,cartId:e,entryNumber:i}});return this.http.delete(s,{headers:o})}};r.\u0275fac=function(e){return new(e||r)(c(P),c(C),c(m))},r.\u0275prov=l({token:r,factory:r.\u0275fac});let n=r;return n})(),Y=(()=>{let r=class r{constructor(t,e,i){this.http=t,this.occEndpoints=e,this.converter=i,this.logger=h(O)}getCartVoucherEndpoint(t,e){return this.occEndpoints.buildUrl("cartVoucher",{urlParams:{userId:t,cartId:e}})}getHeaders(t){let e=new u({"Content-Type":"application/json"});return t===V&&(e=S.createHeader(D,!0,e)),e}add(t,e,i){let o=this.getCartVoucherEndpoint(t,e),s=JSON.stringify({}),a=new b().set("voucherId",i),d=this.getHeaders(t);return this.http.post(o,s,{headers:d,params:a}).pipe(g(p=>{throw T(p,this.logger)}),this.converter.pipeable(H))}remove(t,e,i){let o=this.getCartVoucherEndpoint(t,e)+"/"+encodeURIComponent(i),s=this.getHeaders(t);return this.http.delete(o,{headers:s}).pipe(g(a=>{throw T(a,this.logger)}))}};r.\u0275fac=function(e){return new(e||r)(c(P),c(C),c(m))},r.\u0275prov=l({token:r,factory:r.\u0275fac});let n=r;return n})(),K=(()=>{let r=class r{constructor(t,e,i){this.http=t,this.occEndpointsService=e,this.converterService=i,this.featureConfigService=h(L)}loadAll(t){return this.http.get(this.occEndpointsService.buildUrl("carts",{urlParams:{userId:t}})).pipe(y(e=>e.carts??[]),this.converterService.pipeableMany(v))}load(t,e){return e===A?this.loadAll(t).pipe(y(i=>i.find(o=>o.saveTime===void 0))):this.http.get(this.occEndpointsService.buildUrl("cart",{urlParams:{userId:t,cartId:e}})).pipe(this.converterService.pipeable(v))}create(t,e,i){let o=JSON.stringify({}),s={};return e&&(s.oldCartId=e),i&&(s.toMergeCartGuid=i),this.http.post(this.occEndpointsService.buildUrl("createCart",{urlParams:{userId:t},queryParams:s}),o).pipe(this.converterService.pipeable(v))}delete(t,e){let i=new u;return t===V&&(i=S.createHeader(D,!0,i)),this.http.delete(this.occEndpointsService.buildUrl("deleteCart",{urlParams:{userId:t,cartId:e}}),{headers:i})}save(t,e,i,o){let s=this.occEndpointsService.buildUrl("saveCart",{urlParams:{userId:t,cartId:e,saveCartName:i,saveCartDescription:o}}),a=new b;return this.featureConfigService?.isEnabled("occCartNameAndDescriptionInHttpRequestBody")&&(a=a.set("saveCartName",i).set("saveCartDescription",o)),this.http.patch(s,a).pipe(y(d=>d.savedCartData),this.converterService.pipeable(v))}addEmail(t,e,i){let o=new u({"Content-Type":"application/x-www-form-urlencoded"});o=S.createHeader(D,!0,o);let s=new b().set("email",i),a=this.occEndpointsService.buildUrl("addEmail",{urlParams:{userId:t,cartId:e}});return this.http.put(a,s,{headers:o})}};r.\u0275fac=function(e){return new(e||r)(c(P),c(C),c(m))},r.\u0275prov=l({token:r,factory:r.\u0275fac});let n=r;return n})(),G=(()=>{let r=class r{constructor(t,e,i){this.http=t,this.occEndpoints=e,this.converter=i,this.logger=h(O)}validate(t,e){let i=this.occEndpoints.buildUrl("validate",{urlParams:{cartId:t,userId:e}});return this.http.post(i,null).pipe(g(o=>{throw T(o,this.logger)}),this.converter.pipeable(q))}};r.\u0275fac=function(e){return new(e||r)(c(P),c(C),c(m))},r.\u0275prov=l({token:r,factory:r.\u0275fac});let n=r;return n})();function X(){return{backend:{occ:{endpoints:{carts:"users/${userId}/carts?fields=carts(DEFAULT,potentialProductPromotions,appliedProductPromotions,potentialOrderPromotions,appliedOrderPromotions,entries(totalPrice(formattedValue),product(images(FULL),stock(FULL)),basePrice(formattedValue,value),updateable),totalPrice(formattedValue),totalItems,totalPriceWithTax(formattedValue),totalDiscounts(value,formattedValue),subTotal(formattedValue),totalUnitCount,deliveryItemsQuantity,deliveryCost(formattedValue),totalTax(formattedValue, value),pickupItemsQuantity,net,appliedVouchers,productDiscounts(formattedValue),user,saveTime,name,description)",cart:"users/${userId}/carts/${cartId}?fields=DEFAULT,potentialProductPromotions,appliedProductPromotions,potentialOrderPromotions,appliedOrderPromotions,entries(totalPrice(formattedValue),product(images(FULL),stock(FULL)),basePrice(formattedValue,value),updateable),totalPrice(formattedValue),totalItems,totalPriceWithTax(formattedValue),totalDiscounts(value,formattedValue),subTotal(formattedValue),totalUnitCount,deliveryItemsQuantity,deliveryCost(formattedValue),totalTax(formattedValue, value),pickupItemsQuantity,net,appliedVouchers,productDiscounts(formattedValue),user,saveTime,name,description",createCart:"users/${userId}/carts?fields=DEFAULT,potentialProductPromotions,appliedProductPromotions,potentialOrderPromotions,appliedOrderPromotions,entries(totalPrice(formattedValue),product(images(FULL),stock(FULL)),basePrice(formattedValue,value),updateable),totalPrice(formattedValue),totalItems,totalPriceWithTax(formattedValue),totalDiscounts(value,formattedValue),subTotal(formattedValue),totalUnitCount,deliveryItemsQuantity,deliveryCost(formattedValue),totalTax(formattedValue, value),pickupItemsQuantity,net,appliedVouchers,productDiscounts(formattedValue),user",addEntries:"users/${userId}/carts/${cartId}/entries",updateEntries:"users/${userId}/carts/${cartId}/entries/${entryNumber}",removeEntries:"users/${userId}/carts/${cartId}/entries/${entryNumber}",addEmail:"users/${userId}/carts/${cartId}/email",deleteCart:"users/${userId}/carts/${cartId}",cartVoucher:"users/${userId}/carts/${cartId}/vouchers",saveCart:h(M).occCartNameAndDescriptionInHttpRequestBody?"/users/${userId}/carts/${cartId}/save":"/users/${userId}/carts/${cartId}/save?saveCartName=${saveCartName}&saveCartDescription=${saveCartDescription}",validate:"users/${userId}/carts/${cartId}/validate?fields=DEFAULT"}}}}}var ue=(()=>{let r=class r{};r.\u0275fac=function(e){return new(e||r)},r.\u0275mod=R({type:r}),r.\u0275inj=N({providers:[j(X),{provide:Q,useClass:K},{provide:v,useExisting:J,multi:!0},{provide:U,useExisting:W,multi:!0},{provide:x,useClass:B},{provide:k,useClass:Y},{provide:Z,useClass:G}],imports:[$]});let n=r;return n})();export{ue as a};