import { jsxs as v, jsx as u, Fragment as A } from "react/jsx-runtime";
import { forwardRef as k, useId as G, useState as J, useMemo as z, useEffect as K } from "react";
import { a as M } from "./paragraph-DNtj7OLr.mjs";
import { V as O } from "./visually-hidden-BYFkJEp1.mjs";
import { c as L } from "./bind-CU-R61T-.mjs";
const U = {
  "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"
}, X = {
  "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"
}, m = L.bind(X), r = "purpur-countdown-counter", $ = ({ tag: t, size: a, numbers: n, counterLabels: _ }) => {
  const w = () => {
    const s = _[t], e = _[`${t}Abbr`];
    return /* @__PURE__ */ v(A, { children: [
      e && /* @__PURE__ */ u(M, { className: m(`${r}__label`, `${r}__label--abbr`), children: /* @__PURE__ */ u("abbr", { title: s, children: e }) }),
      /* @__PURE__ */ u(
        M,
        {
          className: m(`${r}__label`, {
            [`${r}__label--full`]: !!e
          }),
          children: s
        }
      )
    ] });
  };
  return /* @__PURE__ */ v(
    "div",
    {
      className: m(r, `${r}--size-${a}`),
      role: "group",
      "aria-hidden": "true",
      "data-testid": `counter-${t}`,
      children: [
        /* @__PURE__ */ u("div", { className: m(`${r}__number-list-container`), children: n.map((s, e) => /* @__PURE__ */ u(
          "ul",
          {
            className: m(`${r}__number-list`),
            style: {
              "--offset": s
            },
            children: Y.map((l, b) => {
              const i = l === s;
              return /* @__PURE__ */ u(
                "li",
                {
                  className: m(`${r}__number`, {
                    [`${r}__number--selected`]: i
                  }),
                  children: l
                },
                b
              );
            })
          },
          e
        )) }),
        w()
      ]
    }
  );
}, Y = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
function Z(t) {
  const a = (/* @__PURE__ */ new Date()).getTime(), n = Math.max(0, t - a), _ = Math.floor(n / d.day), w = Math.floor(n % d.day / d.hour), s = Math.floor(n % d.hour / d.minute), e = Math.floor(n % d.minute / d.second), l = g(_), b = g(w), i = g(s);
  return {
    seconds: g(e),
    minutes: i,
    hours: b,
    days: l
  };
}
const d = {
  second: 1e3,
  minute: 60 * 1e3,
  hour: 3600 * 1e3,
  day: 1440 * 60 * 1e3
};
function T(t) {
  return t instanceof Date ? t : new Date(t);
}
function g(t) {
  return String(t).padStart(2, "0").split("");
}
const D = L.bind(U), o = "purpur-countdown", B = k(
  ({ renderAfterEnd: t, renderBeforeStart: a, ...n }, _) => {
    const w = /* @__PURE__ */ new Date(), s = G(), {
      size: e = "lg",
      fullWidth: l = !1,
      negative: b = !1,
      showDays: i = !0,
      variant: j = "primary",
      className: P,
      counterLabels: f,
      useMediaQueries: C = !1
    } = n, [p, V] = J(w), N = z(() => T(n.starttime), [n.starttime]), y = z(() => T(n.endtime), [n.endtime]), { days: q, hours: x, minutes: I, seconds: S } = z(() => Z(y.getTime()), [p]);
    K(() => {
      if (p < N || p > y) return;
      const c = setInterval(() => V(/* @__PURE__ */ new Date()), 1e3);
      return () => clearInterval(c);
    }, [N, y, p]);
    const E = N > p, F = y < p;
    if (E) return a ? a(n) : null;
    if (F) return t ? t(n) : null;
    const H = () => {
      const c = { size: e, counterLabels: f };
      return /* @__PURE__ */ v(A, { children: [
        i && /* @__PURE__ */ u($, { numbers: q, tag: "days", ...c }),
        /* @__PURE__ */ u($, { numbers: x, tag: "hours", ...c }),
        /* @__PURE__ */ u($, { numbers: I, tag: "minutes", ...c }),
        /* @__PURE__ */ u($, { numbers: S, tag: "seconds", ...c })
      ] });
    }, Q = () => {
      const c = () => {
        const h = [];
        return i && h.push(`${q.join("")} ${f.days}`), h.push(`${x.join("")} ${f.hours}`), h.push(`${I.join("")} ${f.minutes}`), h.push(`${S.join("")} ${f.seconds}`), h.join(", ");
      };
      return /* @__PURE__ */ u(
        O,
        {
          "data-testid": "live-region",
          "aria-live": "polite",
          "aria-label": n["aria-label"],
          children: c()
        }
      );
    }, R = H(), W = D(
      o,
      `${o}--size-${e}`,
      `${o}--variant-${j}`,
      {
        [`${o}--full-width`]: l,
        [`${o}--negative`]: b,
        [`${o}--show-days`]: i,
        [`${o}--use-media-queries`]: C,
        [`${o}--use-container-queries`]: !C
      },
      P
    );
    return /* @__PURE__ */ v(
      "section",
      {
        id: s,
        className: W,
        ref: _,
        role: "timer",
        "data-testid": n["data-testid"],
        children: [
          Q(),
          n.label && /* @__PURE__ */ u(M, { className: D(`${o}__label`), variant: "paragraph-100-medium", children: n.label }),
          /* @__PURE__ */ u("div", { className: D(`${o}__counter-container`), children: R })
        ]
      }
    );
  }
);
B.displayName = "Countdown";
export {
  B as C
};
//# sourceMappingURL=countdown-DxAGVUFI.mjs.map
