"use strict";(self.webpackChunkui=self.webpackChunkui||[]).push([[33],{121:(e,a,s)=>{s.d(a,{a:()=>p,b:()=>b,c:()=>h,d:()=>g,e:()=>m});var t=s(0),n=s(2),i=s(79),r=s(3),l=s(80),o=s(35),c=s(143),d=s(39),u=s(25);function h(e){const a=e.split("/"),s=a[a.length-1];return parseInt(null!=s?s:"0",10)}function m(e,a){return e.replace(/\{(\w+)\}/g,((e,s)=>{var t;return String(null!==(t=a[s])&&void 0!==t?t:"")}))}function g(e,a,s){const n=m(e,a),r=n.match(/^(.*?)<([^>]+)>(.*)$/);if(!r)return(0,t.jsx)("span",{children:n});const[,l,o,c]=r;return(0,t.jsxs)("span",{children:[l,(0,t.jsx)("button",{type:"button",className:i.a.modalLink,onClick:s,children:o}),c]})}function p({cart:e,sectionProps:a}){var s,p,_;const[x,j]=(0,n.useState)(!1),v=(0,r.d)((e=>({cart:e.cart,pathname:e.pathname,cartStatus:e.cartStatus,changeCart:e.changeCart,config:e.config,selectedVariant:e.selectedVariant}))),f=null!==(s=v.cart)&&void 0!==s?s:e,y=(0,o.a)(null==f?void 0:f.currency),N=(0,n.useMemo)((()=>a.eligible_products?new Set(a.eligible_products.map((e=>h(e.id)))):new Set),[a.eligible_products]),{eligibleItems:w,eligibleCount:C}=(0,n.useMemo)((()=>{if(!(null==f?void 0:f.items))return{eligibleItems:[],eligibleCount:0};const e=f.items.filter((e=>!!N.has(e.product_id)&&!(0,c.b)(e))),a=e.reduce(((e,a)=>e+a.quantity),0);return{eligibleItems:e,eligibleCount:a}}),[null==f?void 0:f.items,N]);if(0===w.length||!f)return(0,t.jsx)(t.Fragment,{});const k=a.quantity_threshold,I=C>=k,L=Math.max(0,k-C),M=Math.min(100,C/k*100),S=w.reduce(((e,a)=>e+a.discounted_price*a.quantity),0)/100,q=w.reduce(((e,a)=>e+a.original_price*a.quantity),0)/100,V=(C>0?q/C:0)*k,B=V-(null!==(p=a.promotion_price)&&void 0!==p?p:0),O=V>0?Math.round(B/V*100):0,K=I?a.border_color_complete:a.border_color_in_progress,P=m(a.savings_message,{percentage:O,quantity:k});return(0,t.jsxs)("div",{className:i.a.groupContainer,style:{"--border-color":K},children:[(0,t.jsxs)("div",{className:i.a.header,children:[(0,t.jsx)("span",{className:i.a.statusLabel,children:I?a.complete_label:a.in_progress_label}),(0,t.jsx)("span",{className:i.a.promoName,children:a.short_name})]}),(0,t.jsx)("div",{className:i.a.progressMessage,children:I?(0,t.jsxs)("span",{className:i.a.completeMessage,children:[(0,t.jsx)(b,{}),(0,t.jsxs)("span",{children:["You're getting ",O,"% off (-",y(B),")"]})]}):g(a.in_progress_message,{remaining:L},(()=>j(!0)))}),(0,t.jsx)("div",{className:i.a.progressBarContainer,children:(0,t.jsx)("div",{className:i.a.progressBar,style:{width:`${M}%`}})}),(0,t.jsx)("ul",{className:i.a.itemsContainer,"aria-label":"Promotion items",children:w.map(((e,a)=>{var s;return(0,t.jsx)("li",{"aria-label":(0,u.b)(e.product_title,e.options_with_values),children:(0,t.jsx)(l.a,Object.assign({},e,{cartItemkKey:e.key,selectedVariantId:null===(s=v.selectedVariant)||void 0===s?void 0:s.variantId,pathname:v.pathname,line:a+1,flags:{moveToWishList:"disabled"},cartStatus:v.cartStatus,changeCart:v.changeCart,height:v.config.product_image_height,width:v.config.product_image_width,hostname:v.config.hostname,currency:f.currency,formatCurrency:y}))},e.key)}))}),(0,t.jsxs)("div",{className:i.a.footer,children:[(0,t.jsxs)("div",{className:i.a.subtotalRow,children:[(0,t.jsx)("span",{className:i.a.subtotalLabel,children:a.offer_subtotal_label}),(0,t.jsx)("span",{className:i.a.subtotalValue,children:y(S)})]}),(0,t.jsx)("div",{className:i.a.savingsRow,children:P})]}),a.eligible_modal_content&&(0,t.jsx)(d.a,{isOpen:x,onClose:()=>j(!1),title:null!==(_=a.short_name)&&void 0!==_?_:"Eligible styles",children:(0,t.jsxs)("div",{className:i.a.modalContent,children:[(0,t.jsx)("h3",{children:a.short_name}),(0,t.jsx)("div",{dangerouslySetInnerHTML:{__html:a.eligible_modal_content}}),(0,t.jsx)("button",{type:"button",className:i.a.okBtn,onClick:()=>j(!1),children:"OK"})]})})]})}function b(){return(0,t.jsxs)("svg",{className:i.a.checkmarkIcon,width:"17",height:"17",viewBox:"0 0 17 17",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,t.jsx)("circle",{cx:"8.5",cy:"8.5",r:"8",fill:"currentColor"}),(0,t.jsx)("path",{d:"M5 8.5L7.5 11L12 6",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}}}]);