import { jsx as l, jsxs as P } from "react/jsx-runtime";
import * as T from "react";
import { forwardRef as q, isValidElement as gt, useRef as M, useState as $, Children as x, useEffect as N } from "react";
import { b as ht } from "./icon.es-CZcKxTaM.mjs";
import { P as R, c as D, u as mt } from "./index-DCcK_d4W.mjs";
import { c as wt } from "./index-DOfn3ixy.mjs";
import { c as Z, I as Ct, R as Tt } from "./index-IpWiejWQ.mjs";
import { P as $t } from "./index-DDrLXRUs.mjs";
import { u as It } from "./index-ByaXH_ih.mjs";
import { u as yt } from "./index-CEQ35j8b.mjs";
import { c as B } from "./bind-CU-R61T-.mjs";
const xt = {
  name: "chevron-left",
  svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M16.175 3.905a.9.9 0 0 1-.08 1.27L8.36 12l7.736 6.825a.9.9 0 0 1-1.191 1.35l-8.5-7.5a.9.9 0 0 1 0-1.35l8.5-7.5a.9.9 0 0 1 1.27.08Z" clip-rule="evenodd"/></svg>',
  keywords: ["chevron-left"],
  category: "utility"
}, Nt = {
  name: "chevron-right",
  svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M7.809 3.924a.9.9 0 0 0 .115 1.267L16.094 12l-8.17 6.809a.9.9 0 0 0 1.152 1.382l9-7.5a.9.9 0 0 0 0-1.382l-9-7.5a.9.9 0 0 0-1.267.115Z" clip-rule="evenodd"/></svg>',
  keywords: ["chevron-right"],
  category: "utility"
};
var S = "Tabs", [Rt] = wt(S, [
  Z
]), X = Z(), [St, z] = Rt(S), J = T.forwardRef(
  (e, r) => {
    const {
      __scopeTabs: s,
      value: o,
      onValueChange: i,
      defaultValue: u,
      orientation: a = "horizontal",
      dir: n,
      activationMode: b = "automatic",
      ...f
    } = e, p = It(n), [d, v] = mt({
      prop: o,
      onChange: i,
      defaultProp: u ?? "",
      caller: S
    });
    return /* @__PURE__ */ l(
      St,
      {
        scope: s,
        baseId: yt(),
        value: d,
        onValueChange: v,
        orientation: a,
        dir: p,
        activationMode: b,
        children: /* @__PURE__ */ l(
          R.div,
          {
            dir: p,
            "data-orientation": a,
            ...f,
            ref: r
          }
        )
      }
    );
  }
);
J.displayName = S;
var Q = "TabsList", U = T.forwardRef(
  (e, r) => {
    const { __scopeTabs: s, loop: o = !0, ...i } = e, u = z(Q, s), a = X(s);
    return /* @__PURE__ */ l(
      Tt,
      {
        asChild: !0,
        ...a,
        orientation: u.orientation,
        dir: u.dir,
        loop: o,
        children: /* @__PURE__ */ l(
          R.div,
          {
            role: "tablist",
            "aria-orientation": u.orientation,
            ...i,
            ref: r
          }
        )
      }
    );
  }
);
U.displayName = Q;
var Y = "TabsTrigger", tt = T.forwardRef(
  (e, r) => {
    const { __scopeTabs: s, value: o, disabled: i = !1, ...u } = e, a = z(Y, s), n = X(s), b = nt(a.baseId, o), f = ot(a.baseId, o), p = o === a.value;
    return /* @__PURE__ */ l(
      Ct,
      {
        asChild: !0,
        ...n,
        focusable: !i,
        active: p,
        children: /* @__PURE__ */ l(
          R.button,
          {
            type: "button",
            role: "tab",
            "aria-selected": p,
            "aria-controls": f,
            "data-state": p ? "active" : "inactive",
            "data-disabled": i ? "" : void 0,
            disabled: i,
            id: b,
            ...u,
            ref: r,
            onMouseDown: D(e.onMouseDown, (d) => {
              !i && d.button === 0 && d.ctrlKey === !1 ? a.onValueChange(o) : d.preventDefault();
            }),
            onKeyDown: D(e.onKeyDown, (d) => {
              [" ", "Enter"].includes(d.key) && a.onValueChange(o);
            }),
            onFocus: D(e.onFocus, () => {
              const d = a.activationMode !== "manual";
              !p && !i && d && a.onValueChange(o);
            })
          }
        )
      }
    );
  }
);
tt.displayName = Y;
var et = "TabsContent", rt = T.forwardRef(
  (e, r) => {
    const { __scopeTabs: s, value: o, forceMount: i, children: u, ...a } = e, n = z(et, s), b = nt(n.baseId, o), f = ot(n.baseId, o), p = o === n.value, d = T.useRef(p);
    return T.useEffect(() => {
      const v = requestAnimationFrame(() => d.current = !1);
      return () => cancelAnimationFrame(v);
    }, []), /* @__PURE__ */ l($t, { present: i || p, children: ({ present: v }) => /* @__PURE__ */ l(
      R.div,
      {
        "data-state": p ? "active" : "inactive",
        "data-orientation": n.orientation,
        role: "tabpanel",
        "aria-labelledby": b,
        hidden: !v,
        id: f,
        tabIndex: 0,
        ...a,
        ref: r,
        style: {
          ...e.style,
          animationDuration: d.current ? "0s" : void 0
        },
        children: v && u
      }
    ) });
  }
);
rt.displayName = et;
function nt(e, r) {
  return `${e}-trigger-${r}`;
}
function ot(e, r) {
  return `${e}-content-${r}`;
}
var Et = J, jt = U, At = tt, Lt = rt;
const Pt = {
  "purpur-tab-content": "_purpur-tab-content_1ugbi_1",
  "purpur-tab-content--force-mount": "_purpur-tab-content--force-mount_1ugbi_15"
}, Mt = B.bind(Pt), K = "purpur-tab-content", Dt = q(
  ({ children: e, tabId: r, "data-testid": s, className: o, disableForceMount: i, ...u }, a) => /* @__PURE__ */ l(
    Lt,
    {
      ref: a,
      className: Mt(K, o, {
        [`${K}--force-mount`]: !i
      }),
      "data-testid": s,
      value: r,
      forceMount: !i || void 0,
      ...u,
      children: e
    }
  )
), Vt = (e) => !!e && gt(e) && !!e.props.name && !!e.props.tabId, Bt = {
  "purpur-tab-header": "_purpur-tab-header_1tc2s_1",
  "purpur-tab-header--contained": "_purpur-tab-header--contained_1tc2s_36",
  "purpur-tab-header--contained-negative": "_purpur-tab-header--contained-negative_1tc2s_36",
  "purpur-tab-header--line": "_purpur-tab-header--line_1tc2s_39",
  "purpur-tab-header--line-negative": "_purpur-tab-header--line-negative_1tc2s_51",
  "purpur-tab-header--full-width": "_purpur-tab-header--full-width_1tc2s_100"
}, zt = B.bind(Bt), V = "purpur-tab-header", Ft = q(
  ({
    index: e,
    tabId: r,
    variant: s,
    negative: o,
    onFocus: i,
    fullWidth: u,
    "data-testid": a,
    children: n
  }, b) => /* @__PURE__ */ l(
    At,
    {
      id: `${r}-trigger`,
      className: zt(V, `${V}--${s}${o ? "-negative" : ""}`, {
        [`${V}--full-width`]: u
      }),
      value: r,
      "data-testid": a,
      "data-index": e,
      ref: b,
      onFocus: i,
      children: n
    }
  )
), kt = {
  "purpur-tabs__wrapper": "_purpur-tabs__wrapper_jv2vl_1",
  "purpur-tabs__scroll-button": "_purpur-tabs__scroll-button_jv2vl_9",
  "purpur-tabs__scroll-button--left": "_purpur-tabs__scroll-button--left_jv2vl_71",
  "purpur-tabs__scroll-button--right": "_purpur-tabs__scroll-button--right_jv2vl_74",
  "purpur-tabs__wrapper--scroll-start": "_purpur-tabs__wrapper--scroll-start_jv2vl_77",
  "purpur-tabs__wrapper--scroll-end": "_purpur-tabs__wrapper--scroll-end_jv2vl_80",
  "purpur-tabs--line": "_purpur-tabs--line_jv2vl_83",
  "purpur-tabs--line-negative": "_purpur-tabs--line-negative_jv2vl_83",
  "purpur-tabs__selected-border": "_purpur-tabs__selected-border_jv2vl_91",
  "purpur-tabs__content-wrapper": "_purpur-tabs__content-wrapper_jv2vl_115",
  "purpur-tabs--contained": "_purpur-tabs--contained_jv2vl_123",
  "purpur-tabs__list": "_purpur-tabs__list_jv2vl_123",
  "purpur-tabs--contained-negative": "_purpur-tabs--contained-negative_jv2vl_123",
  "purpur-tabs__content-container": "_purpur-tabs__content-container_jv2vl_126",
  "purpur-tabs--full-width": "_purpur-tabs--full-width_jv2vl_136"
}, ee = ["line", "contained"], Gt = (e) => new CustomEvent("tabChangeDetail", { detail: { value: e } }), m = B.bind(kt), _ = "purpur-tabs", Wt = (e, r) => {
  if (typeof e?.getBoundingClientRect != "function" || typeof r?.scroll != "function")
    return;
  const s = e.getBoundingClientRect(), o = r.getBoundingClientRect(), i = r.clientWidth, u = parseInt(getComputedStyle(r).borderLeftWidth?.split("px")[0], 10), a = o.left + (isNaN(u) ? 0 : u);
  let n;
  s.right > o.right && (n = s.left + r.scrollLeft, n = n + s.width - i + i * 0.1, n = n - a), s.left < o.left && (n = s.left + r.scrollLeft, n = n - i * 0.1, n = n - a), n !== void 0 && r.scroll({ left: n, behavior: "smooth" });
}, Ot = ({
  children: e,
  variant: r = "line",
  negative: s = !1,
  fullWidth: o = !1,
  onChange: i,
  className: u,
  defaultValue: a,
  animateHeight: n = !1,
  "data-testid": b,
  value: f,
  ...p
}) => {
  const d = M(null), [v, at] = $(-1), [st, F] = $({}), [it, ct] = $(0), [lt, ut] = $(0), g = x.toArray(e).filter(Vt), w = M(null), k = M(new Array(g.length)), G = 200, E = r === "line", dt = m(
    _,
    `${_}--${r}${s ? "-negative" : ""}`,
    { [`${_}--full-width`]: o },
    u
  ), j = x.map(g, ({ props: { tabId: t } }) => t), pt = () => {
    const t = j.findIndex((c) => c === a);
    return t >= 0 ? t : 0;
  };
  N(() => {
    f && W(g.findIndex((t) => t.props.tabId === f));
  }, [g, f]);
  const [A, W] = $(pt);
  if (new Set(j).size !== j.length)
    throw new Error("tabId must be unique");
  const L = (t, c) => c || b ? `${c || b}-${t}` : void 0, O = () => {
    if (!E)
      return;
    const t = k.current[A];
    ct(t?.offsetLeft || 0), ut(t?.getBoundingClientRect().width || 0);
  }, _t = (t) => {
    E && !f && W(g.findIndex((c) => c.props.tabId === t)), i?.(Gt(t));
  }, bt = (t) => {
    if (w?.current) {
      const { scrollLeft: c } = w.current, h = t === "left" ? -G : G;
      w.current.scroll({ left: c + h, behavior: "smooth" });
    }
  }, H = ({ side: t }) => /* @__PURE__ */ l(
    "button",
    {
      className: m(`${_}__scroll-button`, `${_}__scroll-button--${t}`),
      onClick: () => bt(t),
      type: "button",
      "aria-hidden": "true",
      tabIndex: -1,
      "data-testid": L("scroll-button"),
      children: /* @__PURE__ */ l(ht, { svg: t === "left" ? xt : Nt, size: "md" })
    }
  );
  return N(() => {
    const t = () => {
      if (d.current && n) {
        const h = d.current.offsetHeight;
        at(h);
      }
    }, c = () => {
      t(), O();
    };
    return t(), window.addEventListener("resize", c), () => {
      window.removeEventListener("resize", c);
    };
  }, [A, n]), N(() => {
    O();
  }, [A, o, g.length, r]), N(() => {
    const t = w.current;
    if (!t) return;
    const c = () => {
      const { scrollLeft: h, scrollWidth: I, clientWidth: y } = t, C = I > y, ft = h <= 1, vt = h + y >= I - 1;
      if (!C) {
        F({});
        return;
      }
      F({
        [`${_}__wrapper--scroll-start`]: !ft,
        [`${_}__wrapper--scroll-end`]: !vt
      });
    };
    return c(), t.addEventListener("scroll", c, { passive: !0 }), window.addEventListener("resize", c), () => {
      t.removeEventListener("scroll", c), window.removeEventListener("resize", c);
    };
  }, []), /* @__PURE__ */ l(
    Et,
    {
      defaultValue: a ?? g[0].props.tabId,
      onValueChange: _t,
      "data-testid": b,
      className: dt,
      value: f,
      ...p,
      children: /* @__PURE__ */ P("div", { className: m(`${_}__container`), children: [
        /* @__PURE__ */ P("div", { className: m(`${_}__wrapper`, st), children: [
          /* @__PURE__ */ P(
            jt,
            {
              ref: (t) => {
                w.current = t;
              },
              className: m(`${_}__list`),
              children: [
                x.map(g, (t, c) => {
                  const { name: h, tabId: I, "data-testid": y } = t.props;
                  return /* @__PURE__ */ l(
                    Ft,
                    {
                      "data-testid": L("header", y),
                      index: c,
                      tabId: I,
                      ref: (C) => {
                        C && (k.current[c] = C);
                      },
                      onFocus: (C) => {
                        Wt(C.target, w.current);
                      },
                      variant: r,
                      negative: s,
                      fullWidth: o,
                      children: h
                    }
                  );
                }),
                E && /* @__PURE__ */ l(
                  "div",
                  {
                    className: m(`${_}__selected-border`),
                    style: {
                      width: lt,
                      transform: `translateX(${it}px)`
                    },
                    "data-testid": L("selected-border")
                  }
                )
              ]
            }
          ),
          /* @__PURE__ */ l(H, { side: "left" }),
          /* @__PURE__ */ l(H, { side: "right" })
        ] }),
        /* @__PURE__ */ l(
          "div",
          {
            className: n ? m(`${_}__content-wrapper`) : "",
            style: { height: n && v > -1 ? `${v}px` : "auto" },
            children: /* @__PURE__ */ l("div", { ref: d, className: m(`${_}__content-container`), children: x.map(g, (t) => t) })
          }
        )
      ] })
    }
  );
};
Ot.Content = Dt;
export {
  Ot as T,
  Gt as c,
  ee as t
};
//# sourceMappingURL=tabs-CoXMAwMx.mjs.map
