1import{f as g}from"./utils.BR8IshTs.js";import{C as N}from"../controllers/cart-save.jFcjyuqg.js";import{i as M,j as P,R as I,t as y,m as b,d as v,a as j,h as w}from"./config.mMsEHLZc.js";import{$ as a}from"./jquery.CBbbV0PI.js";import{R as F}from"../controllers/modals/rejected-products-modal-controller.DnO9SjxZ.js";import{M as q}from"../controllers/modal.CY5gecMM.js";import{L as B}from"./constants.B9AoTy6M.js";import{u as R}from"./UserConfigStore.CQ-GZt0y.js";import{s as c}from"./storage.CX6KZSSv.js";import{a as u,b as H}from"./index.1emf6T2b.js";import{M as T}from"../controllers/modals/max-item-count-modal-controller.BxopoGvo.js";const D="product.add",Mt="product.added",V="product.add-rejected",k="product.set-amount",Pt="product.increase",It="product.increased",yt="product.decrease",bt="product.decreased",vt="product.delete",jt="product.unbind",m="product.deleted",wt="product.change",C=".js-product-container",x=C+".card",Ft=C+'[data-product-is-bound="true"]',qt=C+':not([data-product-is-bound="true"])',Bt="form.js-add-to-cart",Ht="form.js-counter",Vt=".js-add",kt=".js-subtract",xt="form.js-delete-from-cart",Gt="form.js-update-favorite",Xt="[data-error-container]",Wt="product.favorite",Kt="product.favorited",Jt="product.unfavorite",zt="product.unfavorited",G="product.loading",X="product.loaded",Yt="product.error.max-amount",$t="product.error.big-order-amount",Qt="product.amount-ok",Zt="cart_nudge.product_added",te="product.edit",W=".js-bundle-container",K="data-bundle-is-bound",ee=W+":not(["+K+'="true"])',se="form.js-bundle-add-to-cart",ae=".js-bundle-add-to-cart-button",re=".js-bundle-add-more-to-cart-button",oe=".js-bundle-notice",ie="form.js-bundle-delete-from-cart",ne=".js-bundle-delete-from-cart-button",de="bundle.add",J="bundle.added",z="bundle.failed",Y="bundle.deleted";class l extends F{ALLOW_CLICK_OUTSIDE=!1;listen(){this.body.on("click",".js-close-modal, .modal__close",this.resetAmounts),super.listen()}resetAmounts=()=>{const t=this.getModalBox().find("[data-rejected-product-code]");if(t.is("[data-rejected-product-fallback-amount]")){this.adjustRejectedProductAmount(t);return}const e=t.attr("data-rejected-product-code");a(C+'[data-product-code="'+e+'"]').trigger(m),L()};adjustRejectedProductAmount(t){const e=Number.parseFloat(t.attr("data-rejected-product-fallback-amount")??""),s=t.attr("data-rejected-product-code"),i=a(x+'[data-product-code="'+s+'"]').first();e>0&&i.trigger(k,{value:e})}unhook=()=>{super.unhook(),this.body.off("click",".js-close-modal, .modal__close",this.resetAmounts)}}const $="SalesRestrictedError",Q="MaxItemCountReachedError",Z="FestivityMealLeadTimeRestrictedError",tt="InsufficientLeadTimeError",et="SocialCardRestrictedProductError",st="DeliveryMethodRestrictedError",at="MerchandiseCategoryRestrictedError",rt="CustomizedHybrisException";class ot{config=[{type:$,modal:l},{type:Z,modal:l},{type:Q,modal:T},{type:tt,modal:l},{type:et,modal:T},{type:st,modal:l},{type:at,modal:l},{type:rt,modal:T}];getModalForErrorType(t){return this.config.find(e=>e.type===t)}isSupportedError(t){return"errorType"in t?this.config.some(e=>e.type===t.errorType):!1}}class it{products=[];has(t){return this.products.some(e=>e.code===t.code)}add(t){this.has(t)||this.products.push(t)}get(){return this.products}reset(){this.products=[]}}class nt{page;modal;isDisplayingModal=!1;errorTypeConfig;products;constructor(){this.page=a("body"),this.errorTypeConfig=new ot,this.products=new it,this.events()}events(){this.page.on(M,this.resetCounter),this.page.on(P,this.modalClosed)}resetCounter=()=>{this.isDisplayingModal=!1,this.products.reset()};modalClosed=(t,e)=>{e===this.modal&&(this.isDisplayingModal=!1)};getProducts(){return this.products.get()}clearProducts(){this.products.reset()}isSupportedError(t){return t===void 0||!("errorType"in t)?!1:this.errorTypeConfig.isSupportedError(t)}showModal(t,e,s){if(this.products.add({code:t,amount:e}),this.isDisplayingModal||!s.nextModalUrl)return;const i=this.errorTypeConfig.getModalForErrorType(s.errorType);i!==void 0&&(this.isDisplayingModal=!0,this.modal!==void 0&&this.modal.unhook(),this.modal=new i.modal(s.nextModalUrl,"fullscreen-popover"),this.modal.open())}}const dt=new nt,A="gift.deleted";class ce extends q{DELETE_GIFT_FORM_SELECTOR=".js-delete-gift-form";GIFT_SELECTOR=".js-gift-container";constructor(t,e){super(t,e),this.createModal()}listen(){super.listen(),this.body.on("submit",this.DELETE_GIFT_FORM_SELECTOR,this.submit)}submit=t=>{t.preventDefault();
1const e=a(t.currentTarget),s=e.find('[name="productCode"]').val();return e.find('button[type="submit"]').addClass(B),a.ajax({url:e.attr("action"),type:e.attr("method"),data:e.serialize(),headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}}).done(i=>{this.close(),a(this.GIFT_SELECTOR+'[data-product-code="'+s+'"]').trigger(m),this.body.trigger(A)})};unhook=()=>{this.body.off("click",".modal__close",this.close),this.body.off("click",".js-close-modal",this.close),this.body.off("submit",this.DELETE_GIFT_FORM_SELECTOR,this.submit),this.ALLOW_CLICK_OUTSIDE&&this.body.off("click",this.clickOutside)}}const S="[data-async-side-cart-root]",ct="[data-cart-mobile-nav-root]",ut=".js-header-cart",p="cart.after_update",f="cart.get",O="cart.get_complete",h="storefront_cart";class o{static instance;side;header;page;pendingRequests={};requestCounter=0;cartCreationInProgress=!1;refreshOnNavigation=!1;rejectedProducts;isRecalculating=!1;isRefreshing=!1;isCalculated=!0;constructor(){this.side=a(S),this.header=a(ut),this.page=a("body"),this.rejectedProducts=dt,this.afterConstruct()}afterConstruct(){this.events(),this.waitForCart().then(()=>{this.isCalculated=R.state.values.cart_is_calculated,this.isCartNotCalculated()&&this.recalculateCart()})}static getMobileNavigationCart(){return a(ct)}events(){this.side.on("click",".js-open-save-cart-modal",this.saveCart),this.page.on(I,this.refreshCart),this.page.on(y,this.refreshCart),this.page.on(b,this.refreshCart),this.page.on(v,this.refreshCart),this.page.on(j,this.refreshCart),this.page.on(w,this.refreshCart),this.page.on(A,this.refreshCart),this.page.on(Y,this.refreshCart),this.page.on(f,this.getCart),this.page.on(p,this.recalculateCart),this.header.on("click",this.showMiniCartLoader),document.addEventListener(f,this.getCart)}hasPendingRequests=()=>Object.keys(this.pendingRequests).length>0;showPlaceholder=()=>{if(!a("[data-async-side-cart-root]").length)return;const t=c.get(h);if(t){const e=t.value;this.updateHeaderCart(e),this.updateMobileNavigation(e),this.updateSide(e)}};getCart=async()=>{const t=c.get(h);return t&&this.page.trigger(O),await u.get(Storefront.routes.api.cart_get,{headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}}).then(e=>{this.isCalculated=e.data.isCalculated,this.afterProductChanges(e.data),c.set(h,e.data),t||this.page.trigger(O)})};isCartNotCalculated=()=>!this.isCalculated;isCartCalculated=()=>this.isCalculated;recalculateCart=async()=>{if(this.isCartCreated()&&!this.hasPendingRequests()&&!(this.isCartCalculated()||this.isRecalculating||this.isRefreshing))return this.isRecalculating=!0,await u.get(Storefront.routes.cart_recalculated,{headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}}).then(t=>{this.isRecalculating=!1,!this.hasPendingRequests()&&(this.isCalculated=t.data.isCalculated,this.afterProductChanges(t.data),c.set(h,t.data))})};refreshCart=async()=>{if(!(this.hasPendingRequests()||this.isRecalculating))return this.isRefreshing=!0,u.get(Storefront.routes.cart_refresh,{headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}}).then(t=>{this.isRefreshing=!1,this.isCartCreated()||R.commit("UPDATE_VALUE",{key:"cart_is_created",value:!0}),!this.hasPendingRequests()&&(this.isCalculated=t.data.isCalculated,this.afterProductChanges(t.data),c.set(h,t.data))})};saveCart=t=>{t.preventDefault(),new N().open()};mustCreateCart=()=>!this.isCartCreated()&&!this.cartCreationInProgress;isCartCreated=()=>R.state.values.cart_is_created;waitForCart=()=>new Promise(t=>{const e=setInterval(()=>{if(this.isCartCreated())return clearInterval(e),t()},10)});changeAmount=(t,e)=>this.mustCreateCart()?(this.cartCreationInProgress=!0,this.request(t,e)):this.waitForCart().then(()=>this.request(t,e));addBundle=t=>this.mustCreateCart()?(this.cartCreationInProgress=!0,this.bundleRequest(t)):this.waitForCart().then(()=>this.bundleRequest(t));static getProductId(t){return t.find('[name="product"]').val()}static getAmount(t){return t.find('[name="amount"]').val()}request=async(t,e)=>{t.trigger(G);const s=o.getProductId(t),i=o.getAmount(t);this.pendingRequests[this.requestCounter]={product:s,action:e};const U=this.requestCounter;return this.requestCounter++,await u.put(Storefront.routes.cart_product_change,g(t),{headers:{"Content-Type":"application/json",Accept:"application/json","X-Requested-With":"XMLHttpRequest","X-Cart-Update-Timestamp":Date.now()}}).catch(_=>{const E=_ instanceof H?_.response?.data:void 0;if(E&&typeof E=="object"&&this.rejectedProducts.isSupportedError(E)){this.rejectedProducts.showModal(s,i,E),e===D&&a(C+'[data-product-code="'+s+'"]').trigger(V);return}console.error("Cart product change failed",_)}).finally(()=>{t.trigger(X),delete this.pendingRequests[U]}).then(()=>this.refreshCart())};bundleRequest=async t=>{const e=t.attr("action");if(e===void 0)throw new Error("Bundle form has no action URL");return await u.put(e,g(t),{headers:{"Content-Type":"application/json",Accept:"application/json","X-Requested-With":"XMLHttpRequest"}}).catch(s=>{throw console.error(s.response?.statusText??s.message),t.trigger(z),s}).then(s=>(this.refreshCart(),t.trigger(J,s.data),s.data))};afterProductChanges=t=>{this.updateHeaderCart(t),this.updateMobileNavigation(t),this.updateSide(t),this.page.trigger(p,t),this.refreshOnNavigation=!1};updateSide=t=>{if(t?.sideCart!==void 0&&this.side.length){const e=this.getSideContent().scrollTop()??0;
1this.side.html(t.sideCart),this.getSideContent().scrollTop(e),this.side.trigger("contentloaded")}};updateMobileNavigation=t=>{const e=o.getMobileNavigationCart();t?.mobileNavigationCart!==void 0&&e.length&&(e.html(t.mobileNavigationCart),o.getMobileNavigationCart().trigger("contentloaded"))};updateHeaderCart=t=>{t?.headerCart!==void 0&&this.header.length&&(this.header.html(t.headerCart),this.header.removeClass("-opening"),this.header.trigger("contentloaded"))};getSideContent(){return this.side.find(".side-cart__content")}showMiniCartLoader=()=>{this.header.addClass("-opening")}}class lt extends o{afterConstruct(){}}let n=null;async function d(){return n||(await R.dispatch("prepare"),n=o.instance?o.instance:new o,o.instance=n,n)}function ht(){new lt().showPlaceholder()}async function Ct(r,t){await(await d()).changeAmount(r,t)}async function L(){(await d()).refreshCart()}async function Et(r){await(await d()).addBundle(r)}async function Rt(r){const t=a(r);(await d()).changeAmount(t,D)}function _t(){return n?n.refreshOnNavigation:(d(),!1)}async function Tt(){(await d()).refreshOnNavigation=!0}const ue=Object.freeze(Object.defineProperty({__proto__:null,CART_GET:f,CART_GET_COMPLETE_EVENT:O,CART_SIDE_SELECTOR:S,CART_UPDATED_EVENT:p,addBundle:Et,addDeliverySubscription:Rt,changeCartAmount:Ct,initCart:d,isCartRefreshableOnNavigation:_t,refreshCart:L,refreshCartOnNavigation:Tt,showCartPlaceholder:ht},Symbol.toStringTag,{value:"Module"}));export{K as $,Qt as A,ne as B,f as C,$t as D,Gt as E,Wt as F,Jt as G,Kt as H,zt as I,qt as J,Ft as K,Bt as L,xt as M,Xt as N,_t as O,Mt as P,ce as Q,Zt as R,O as S,ee as T,se as U,ae as V,re as W,oe as X,de as Y,J as Z,z as _,Rt as a,Et as a0,ht as a1,d as a2,ue as a3,C as b,m as c,Yt as d,p as e,ie as f,Y as g,L as h,jt as i,S as j,Ht as k,Vt as l,kt as m,Ct as n,V as o,Pt as p,It as q,dt as r,yt as s,bt as t,k as u,te as v,vt as w,wt as x,Tt as y,D as z};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.