"use client";
import * as v from "react";
import { composeEventHandlers as g } from "../../primitive/dist/index.js";
import { createContextScope as x } from "../../react-context/dist/index.js";
import { createRovingFocusGroupScope as C, Root as E, Item as F } from "../../react-roving-focus/dist/index.js";
import { Presence as w } from "../../react-presence/dist/index.js";
import { Primitive as b } from "../../react-primitive/dist/index.js";
import { useDirection as D } from "../../react-direction/dist/index.js";
import { useControllableState as V } from "../../react-use-controllable-state/dist/index.js";
import { useId as G } from "../../react-id/dist/index.js";
import { jsx as l } from "react/jsx-runtime";
var p = "Tabs", [L] = x(p, [
  C
]), h = C(), [$, T] = L(p), I = v.forwardRef(
  (e, r) => {
    const {
      __scopeTabs: s,
      value: t,
      onValueChange: n,
      defaultValue: c,
      orientation: o = "horizontal",
      dir: d,
      activationMode: f = "automatic",
      ...m
    } = e, i = D(d), [a, u] = V({
      prop: t,
      onChange: n,
      defaultProp: c ?? "",
      caller: p
    });
    return /* @__PURE__ */ l(
      $,
      {
        scope: s,
        baseId: G(),
        value: a,
        onValueChange: u,
        orientation: o,
        dir: i,
        activationMode: f,
        children: /* @__PURE__ */ l(
          b.div,
          {
            dir: i,
            "data-orientation": o,
            ...m,
            ref: r
          }
        )
      }
    );
  }
);
I.displayName = p;
var R = "TabsList", _ = v.forwardRef(
  (e, r) => {
    const { __scopeTabs: s, loop: t = !0, ...n } = e, c = T(R, s), o = h(s);
    return /* @__PURE__ */ l(
      E,
      {
        asChild: !0,
        ...o,
        orientation: c.orientation,
        dir: c.dir,
        loop: t,
        children: /* @__PURE__ */ l(
          b.div,
          {
            role: "tablist",
            "aria-orientation": c.orientation,
            ...n,
            ref: r
          }
        )
      }
    );
  }
);
_.displayName = R;
var y = "TabsTrigger", A = v.forwardRef(
  (e, r) => {
    const { __scopeTabs: s, value: t, disabled: n = !1, ...c } = e, o = T(y, s), d = h(s), f = P(o.baseId, t), m = S(o.baseId, t), i = t === o.value;
    return /* @__PURE__ */ l(
      F,
      {
        asChild: !0,
        ...d,
        focusable: !n,
        active: i,
        children: /* @__PURE__ */ l(
          b.button,
          {
            type: "button",
            role: "tab",
            "aria-selected": i,
            "aria-controls": m,
            "data-state": i ? "active" : "inactive",
            "data-disabled": n ? "" : void 0,
            disabled: n,
            id: f,
            ...c,
            ref: r,
            onMouseDown: g(e.onMouseDown, (a) => {
              !n && a.button === 0 && a.ctrlKey === !1 ? o.onValueChange(t) : a.preventDefault();
            }),
            onKeyDown: g(e.onKeyDown, (a) => {
              [" ", "Enter"].includes(a.key) && o.onValueChange(t);
            }),
            onFocus: g(e.onFocus, () => {
              const a = o.activationMode !== "manual";
              !i && !n && a && o.onValueChange(t);
            })
          }
        )
      }
    );
  }
);
A.displayName = y;
var M = "TabsContent", N = v.forwardRef(
  (e, r) => {
    const { __scopeTabs: s, value: t, forceMount: n, children: c, ...o } = e, d = T(M, s), f = P(d.baseId, t), m = S(d.baseId, t), i = t === d.value, a = v.useRef(i);
    return v.useEffect(() => {
      const u = requestAnimationFrame(() => a.current = !1);
      return () => cancelAnimationFrame(u);
    }, []), /* @__PURE__ */ l(w, { present: n || i, children: ({ present: u }) => /* @__PURE__ */ l(
      b.div,
      {
        "data-state": i ? "active" : "inactive",
        "data-orientation": d.orientation,
        role: "tabpanel",
        "aria-labelledby": f,
        hidden: !u,
        id: m,
        tabIndex: 0,
        ...o,
        ref: r,
        style: {
          ...e.style,
          animationDuration: a.current ? "0s" : void 0
        },
        children: u && c
      }
    ) });
  }
);
N.displayName = M;
function P(e, r) {
  return `${e}-trigger-${r}`;
}
function S(e, r) {
  return `${e}-content-${r}`;
}
var Q = I, U = _, W = A, X = N;
export {
  X as Content,
  U as List,
  Q as Root,
  I as Tabs,
  N as TabsContent,
  _ as TabsList,
  A as TabsTrigger,
  W as Trigger
};
