"use strict";const n=require("react/jsx-runtime"),d=require("react"),N=require("./paragraph-BsI53OR0.js"),W=require("./visually-hidden-C2CKovZx.js"),S=require("./bind-DeUYJ6m9.js"),k={"purpur-countdown--size-md":"_purpur-countdown--size-md_ytnsp_1","purpur-countdown--size-lg":"_purpur-countdown--size-lg_ytnsp_5","purpur-countdown--use-container-queries":"_purpur-countdown--use-container-queries_ytnsp_10","purpur-countdown__counter-container":"_purpur-countdown__counter-container_ytnsp_10","purpur-countdown--full-width":"_purpur-countdown--full-width_ytnsp_15","purpur-countdown--use-media-queries":"_purpur-countdown--use-media-queries_ytnsp_25","purpur-countdown":"_purpur-countdown_ytnsp_1","purpur-countdown--variant-primary":"_purpur-countdown--variant-primary_ytnsp_40","purpur-countdown--variant-secondary":"_purpur-countdown--variant-secondary_ytnsp_43","purpur-countdown--negative":"_purpur-countdown--negative_ytnsp_46","purpur-countdown--show-days":"_purpur-countdown--show-days_ytnsp_56","purpur-countdown__label":"_purpur-countdown__label_ytnsp_72"},G={"purpur-countdown-counter":"_purpur-countdown-counter_23fbu_1","purpur-countdown-counter--size-lg":"_purpur-countdown-counter--size-lg_23fbu_10","purpur-countdown-counter__number":"_purpur-countdown-counter__number_23fbu_15","purpur-countdown-counter--size-md":"_purpur-countdown-counter--size-md_23fbu_21","purpur-countdown-counter__number-list-container":"_purpur-countdown-counter__number-list-container_23fbu_35","purpur-countdown-counter__number-list":"_purpur-countdown-counter__number-list_23fbu_35","purpur-countdown-counter__number--selected":"_purpur-countdown-counter__number--selected_23fbu_61","purpur-countdown-counter__label":"_purpur-countdown-counter__label_23fbu_64","purpur-countdown-counter__label--abbr":"_purpur-countdown-counter__label--abbr_23fbu_71","purpur-countdown-counter__label--full":"_purpur-countdown-counter__label--full_23fbu_74"},w=S.c.bind(G),r="purpur-countdown-counter",g=({tag:u,size:a,numbers:e,counterLabels:_})=>{const b=()=>{const s=_[u],t=_[`${u}Abbr`];return n.jsxs(n.Fragment,{children:[t&&n.jsx(N.Paragraph,{className:w(`${r}__label`,`${r}__label--abbr`),children:n.jsx("abbr",{title:s,children:t})}),n.jsx(N.Paragraph,{className:w(`${r}__label`,{[`${r}__label--full`]:!!t}),children:s})]})};return n.jsxs("div",{className:w(r,`${r}--size-${a}`),role:"group","aria-hidden":"true","data-testid":`counter-${u}`,children:[n.jsx("div",{className:w(`${r}__number-list-container`),children:e.map((s,t)=>n.jsx("ul",{className:w(`${r}__number-list`),style:{"--offset":s},children:J.map((p,h)=>{const i=p===s;return n.jsx("li",{className:w(`${r}__number`,{[`${r}__number--selected`]:i}),children:p},h)})},t))}),b()]})},J=["0","1","2","3","4","5","6","7","8","9"];function K(u){const a=new Date().getTime(),e=Math.max(0,u-a),_=Math.floor(e/l.day),b=Math.floor(e%l.day/l.hour),s=Math.floor(e%l.hour/l.minute),t=Math.floor(e%l.minute/l.second),p=j(_),h=j(b),i=j(s);return{seconds:j(t),minutes:i,hours:h,days:p}}const l={second:1e3,minute:60*1e3,hour:3600*1e3,day:1440*60*1e3};function P(u){return u instanceof Date?u:new Date(u)}function j(u){return String(u).padStart(2,"0").split("")}const v=S.c.bind(k),o="purpur-countdown",R=d.forwardRef(({renderAfterEnd:u,renderBeforeStart:a,...e},_)=>{const b=new Date,s=d.useId(),{size:t="lg",fullWidth:p=!1,negative:h=!1,showDays:i=!0,variant:q="primary",className:T,counterLabels:f,useMediaQueries:z=!1}=e,[m,A]=d.useState(b),x=d.useMemo(()=>P(e.starttime),[e.starttime]),$=d.useMemo(()=>P(e.endtime),[e.endtime]),{days:M,hours:D,minutes:C,seconds:I}=d.useMemo(()=>K($.getTime()),[m]);d.useEffect(()=>{if(m<x||m>$)return;const c=setInterval(()=>A(new Date),1e3);return()=>clearInterval(c)},[x,$,m]);const F=x>m,H=$<m;if(F)return a?a(e):null;if(H)return u?u(e):null;const L=()=>{const c={size:t,counterLabels:f};return n.jsxs(n.Fragment,{children:[i&&n.jsx(g,{numbers:M,tag:"days",...c}),n.jsx(g,{numbers:D,tag:"hours",...c}),n.jsx(g,{numbers:C,tag:"minutes",...c}),n.jsx(g,{numbers:I,tag:"seconds",...c})]})},E=()=>{const c=()=>{const y=[];return i&&y.push(`${M.join("")} ${f.days}`),y.push(`${D.join("")} ${f.hours}`),y.push(`${C.join("")} ${f.minutes}`),y.push(`${I.join("")} ${f.seconds}`),y.join(", ")};return n.jsx(W.VisuallyHidden,{"data-testid":"live-region","aria-live":"polite","aria-label":e["aria-label"],children:c()})},Q=L(),V=v(o,`${o}--size-${t}`,`${o}--variant-${q}`,{[`${o}--full-width`]:p,[`${o}--negative`]:h,[`${o}--show-days`]:i,[`${o}--use-media-queries`]:z,[`${o}--use-container-queries`]:!z},T);return n.jsxs("section",{id:s,className:V,ref:_,role:"timer","data-testid":e["data-testid"],children:[E(),e.label&&n.jsx(N.Paragraph,{className:v(`${o}__label`),variant:"paragraph-100-medium",children:e.label}),n.jsx("div",{className:v(`${o}__counter-container`),children:Q})]})});R.displayName="Countdown";exports.Countdown=R;
//# sourceMappingURL=countdown-CqYsZigV.js.map
