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