import{c as x,e as k,j as _,m as Q,n as G,o as Z,p as V,q,r as J}from"./chunk-FTZQQK5T.js";import{T as P,U as R,V as S,W as H}from"./chunk-6M5IHSHH.js";import{Ce as g,J as h,Le as v,Ye as p,_e as T,dd as j,ib as N,ie as $,kd as u,kf as U,lg as F,md as D,pd as m,pf as f,r as O,ra as d,re as A,sa as M,te as L,ua as a,va as c,ve as y,ye as I}from"./chunk-5LB5MWMX.js";import{a as E,b as w}from"./chunk-QWWW7GFA.js";var B=(()=>{class r{constructor(t){this.converter=t}convert(t,e){return e===void 0&&(e=E({},t)),this.removeDuplicatePromotions(t,e),this.handleQuoteCode(t,e),t.entries&&(e.entries=t.entries.map(i=>w(E({},i),{product:this.converter.convert(i.product,F),promotions:this.converter.convert({item:i,promotions:e?.appliedProductPromotions},R)}))),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(n=>JSON.stringify(n));return i===s.indexOf(JSON.stringify(e))})}static{this.\u0275fac=function(e){return new(e||r)(a(p))}}static{this.\u0275prov=d({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),W=(()=>{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}static{this.\u0275fac=function(e){return new(e||r)}}static{this.\u0275prov=d({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})(),Y=(()=>{class r{constructor(){this.logger=c(g),this.http=c(m),this.occEndpointsService=c(v),this.converterService=c(p)}getCartAccessCode(t,e){return this.http.post(this.getCartAccessCodeEndpoint(t,e),null).pipe(h(i=>{throw f(i,this.logger)}),U({shouldRetry:T,maxTries:2}),this.converterService.pipeable(G))}getCartAccessCodeEndpoint(t,e){return this.occEndpointsService.buildUrl("cartAccessCode",{urlParams:{userId:t,cartId:e}})}static{this.\u0275fac=function(e){return new(e||r)}}static{this.\u0275prov=d({token:r,factory:r.\u0275fac})}}return r})(),z=(()=>{class r{constructor(t,e,i){this.http=t,this.occEndpointsService=e,this.converterService=i}add(t,e,i,o=1,s){let n=this.occEndpointsService.buildUrl("addEntries",{urlParams:{userId:t,cartId:e,quantity:o}});if(n.includes(`quantity=${o}`)){let b=new u({"Content-Type":"application/x-www-form-urlencoded"});return this.http.post(n,{},{headers:b,params:{code:i}}).pipe(this.converterService.pipeable(S))}let l=E({quantity:o,product:{code:i}},s&&{deliveryPointOfService:{name:s}}),C=new u({"Content-Type":"application/json"});return this.http.post(n,l,{headers:C}).pipe(this.converterService.pipeable(S))}update(t,e,i,o,s,n=!1){let l=new u({"Content-Type":"application/json"}),C=this.occEndpointsService.buildUrl("updateEntries",{urlParams:{userId:t,cartId:e,entryNumber:i}});if(s===void 0&&n)return this.http.put(C,{quantity:o},{headers:l}).pipe(this.converterService.pipeable(S));let b={};return s&&(b={deliveryPointOfService:{name:s}}),this.http.patch(C,E({quantity:o},b),{headers:l}).pipe(this.converterService.pipeable(S))}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})}static{this.\u0275fac=function(e){return new(e||r)(a(m),a(v),a(p))}}static{this.\u0275prov=d({token:r,factory:r.\u0275fac})}}return r})(),K={"Content-Type":"application/json"},X=(()=>{class r{constructor(){this.logger=c(g),this.http=c(m),this.occEndpointsService=c(v),this.converterService=c(p)}getRequestHeaders(){return I.createHeader(y,!0,new u(E({},K)))}createCartGuestUser(t,e,i){return this.http.post(this.getCartGuestUserEndpoint(t,e),i,{headers:this.getRequestHeaders()}).pipe(h(o=>{throw f(o,this.logger)}),U({shouldRetry:T,maxTries:2}),this.converterService.pipeable(V))}updateCartGuestUser(t,e,i){return this.http.patch(this.getCartGuestUserEndpoint(t,e),i,{headers:this.getRequestHeaders()}).pipe(h(o=>{throw f(o,this.logger)}),U({shouldRetry:T,maxTries:2}),this.converterService.pipeable(V))}getCartGuestUserEndpoint(t,e){return this.occEndpointsService.buildUrl("cartGuestUser",{urlParams:{userId:t,cartId:e}})}static{this.\u0275fac=function(e){return new(e||r)}}static{this.\u0275prov=d({token:r,factory:r.\u0275fac})}}return r})(),ee=(()=>{class r{constructor(t,e,i){this.http=t,this.occEndpoints=e,this.converter=i,this.logger=c(g)}validate(t,e){let i=this.occEndpoints.buildUrl("validate",{urlParams:{cartId:t,userId:e}});return this.http.post(i,null).pipe(h(o=>{throw f(o,this.logger)}),this.converter.pipeable(q))}static{this.\u0275fac=function(e){return new(e||r)(a(m),a(v),a(p))}}static{this.\u0275prov=d({token:r,factory:r.\u0275fac})}}return r})(),te=(()=>{class r{constructor(t,e,i){this.http=t,this.occEndpoints=e,this.converter=i,this.logger=c(g)}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===A&&(e=I.createHeader(y,!0,e)),e}add(t,e,i){let o=this.getCartVoucherEndpoint(t,e),s=JSON.stringify({}),n=new D().set("voucherId",i),l=this.getHeaders(t);return this.http.post(o,s,{headers:l,params:n}).pipe(h(C=>{throw f(C,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(h(n=>{throw f(n,this.logger)}))}static{this.\u0275fac=function(e){return new(e||r)(a(m),a(v),a(p))}}static{this.\u0275prov=d({token:r,factory:r.\u0275fac})}}return r})(),re=(()=>{class r{constructor(t,e,i){this.http=t,this.occEndpointsService=e,this.converterService=i}loadAll(t){return this.http.get(this.occEndpointsService.buildUrl("carts",{urlParams:{userId:t}})).pipe(O(e=>e.carts??[]),this.converterService.pipeableMany(P))}load(t,e){return e===L?this.loadAll(t).pipe(O(i=>i.find(o=>o.saveTime===void 0))):this.http.get(this.occEndpointsService.buildUrl("cart",{urlParams:{userId:t,cartId:e}})).pipe(this.converterService.pipeable(P))}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(P))}delete(t,e){let i=new u;return t===A&&(i=I.createHeader(y,!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}}),n=new D;return n=n.set("saveCartName",i).set("saveCartDescription",o),this.http.patch(s,n).pipe(O(l=>l.savedCartData),this.converterService.pipeable(P))}addEmail(t,e,i){let o=new u({"Content-Type":"application/x-www-form-urlencoded"});o=I.createHeader(y,!0,o);let s=new D().set("email",i),n=this.occEndpointsService.buildUrl("addEmail",{urlParams:{userId:t,cartId:e}});return this.http.put(n,s,{headers:o})}static{this.\u0275fac=function(e){return new(e||r)(a(m),a(v),a(p))}}static{this.\u0275prov=d({token:r,factory:r.\u0275fac})}}return r})();function ie(){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:"/users/${userId}/carts/${cartId}/save",validate:"users/${userId}/carts/${cartId}/validate?fields=DEFAULT",cartAccessCode:"users/${userId}/carts/${cartId}/accessCode",cartGuestUser:"users/${userId}/carts/${cartId}/guestuser"}}}}}var Ce=(()=>{class r{static{this.\u0275fac=function(e){return new(e||r)}}static{this.\u0275mod=N({type:r})}static{this.\u0275inj=M({providers:[$(ie),{provide:_,useClass:re},{provide:P,useExisting:B,multi:!0},{provide:R,useExisting:W,multi:!0},{provide:x,useClass:z},{provide:k,useClass:te},{provide:J,useClass:ee},{provide:Q,useClass:Y},{provide:Z,useClass:X}],imports:[j]})}}return r})();export{z as a,re as b,Ce as c};