import { jsx as u, jsxs as G, Fragment as J } from "react/jsx-runtime";
import b, { useMemo as S, useRef as Q, useEffect as X, forwardRef as E, useContext as x, createContext as V } from "react";
import { g as Y, e as Z, h as O, j as ee, k as te } from "./SelectionManager-CX9btso_.es.js";
import { a as D, e as H, $ as ae, c as ie } from "./utils-B6pV5ewr.es.js";
import { a as le, $ as se } from "./SelectionIndicator-B27AsfqE.es.js";
import { $ as oe, g as z, f as re, a as ne } from "./CollectionBuilder-BOe312C_.es.js";
import { $ as de } from "./Hidden-X9vuhkMZ.es.js";
import { $ as v, a as ce } from "./mergeProps-Dsl8k3Ig.es.js";
import { $ as g } from "./filterDOMProps-BSVCO5jK.es.js";
import { $ as F } from "./useObjectRef-CaJ5pgjX.es.js";
import { a as fe, b as N } from "./useListState-Dd0Mtev3.es.js";
import { $ as A } from "./useLabels-BDqWMehi.es.js";
import { $ as ue } from "./useHasTabbableChild-DXq72IE3.es.js";
import { b as be } from "./openLink-BNz58j4a.es.js";
import { $ as $e } from "./useFocusable-Cs6i58WP.es.js";
import { $ as pe } from "./context-DW7UvQ8z.es.js";
import { $ as w } from "./useFocusRing-FPt2Rwil.es.js";
import { $ as he } from "./useHover-BQRSM3qT.es.js";
import { $ as ve } from "./useControlledState-u436Wbp1.es.js";
import { createSlotRecipeContext as ye } from "@chakra-ui/react";
import { e as j } from "./extract-style-props-BdibuNZ7.es.js";
import { useChakraContext as me, useSlotRecipe as Pe } from "@chakra-ui/react/styled-system";
const B = /* @__PURE__ */ new WeakMap();
function K(a, e, t) {
  if (!a)
    return "";
  typeof e == "string" && (e = e.replace(/\s+/g, ""));
  let i = B.get(a);
  return process.env.NODE_ENV !== "production" && !i && console.error("There is no tab id, please check if you have rendered the tab panel before the tab list."), `${i}-${t}-${e}`;
}
function xe(a, e, t) {
  let { key: i, isDisabled: l, shouldSelectOnPressUp: s } = a, { selectionManager: r, selectedKey: d } = e, o = i === d, n = l || e.isDisabled || e.selectionManager.isDisabled(i), { itemProps: f, isPressed: c } = Y({
    selectionManager: r,
    key: i,
    ref: t,
    isDisabled: n,
    shouldSelectOnPressUp: s,
    linkBehavior: "selection"
  }), $ = K(e, i, "tab"), h = K(e, i, "tabpanel"), { tabIndex: y } = f, p = e.collection.getItem(i), m = g(p?.props, {
    labelable: !0
  });
  delete m.id;
  let _ = be(p?.props), { focusableProps: q } = $e({
    isDisabled: n
  }, t);
  return {
    tabProps: v(m, q, _, f, {
      id: $,
      "aria-selected": o,
      "aria-disabled": n || void 0,
      "aria-controls": o ? h : void 0,
      tabIndex: n ? void 0 : y,
      role: "tab"
    }),
    isSelected: o,
    isDisabled: n,
    isPressed: c
  };
}
function ge(a, e, t) {
  let i = ue(t) ? void 0 : 0;
  var l;
  const s = K(e, (l = a.id) !== null && l !== void 0 ? l : e?.selectedKey, "tabpanel"), r = A({
    ...a,
    id: s,
    "aria-labelledby": K(e, e?.selectedKey, "tab")
  });
  return {
    tabPanelProps: v(r, {
      tabIndex: i,
      role: "tabpanel",
      "aria-describedby": a["aria-describedby"],
      "aria-details": a["aria-details"]
    })
  };
}
class Ke {
  getKeyLeftOf(e) {
    return this.flipDirection ? this.getNextKey(e) : this.getPreviousKey(e);
  }
  getKeyRightOf(e) {
    return this.flipDirection ? this.getPreviousKey(e) : this.getNextKey(e);
  }
  isDisabled(e) {
    var t, i;
    return this.disabledKeys.has(e) || !!(!((i = this.collection.getItem(e)) === null || i === void 0 || (t = i.props) === null || t === void 0) && t.isDisabled);
  }
  getFirstKey() {
    let e = this.collection.getFirstKey();
    return e != null && this.isDisabled(e) && (e = this.getNextKey(e)), e;
  }
  getLastKey() {
    let e = this.collection.getLastKey();
    return e != null && this.isDisabled(e) && (e = this.getPreviousKey(e)), e;
  }
  getKeyAbove(e) {
    return this.tabDirection ? null : this.getPreviousKey(e);
  }
  getKeyBelow(e) {
    return this.tabDirection ? null : this.getNextKey(e);
  }
  getNextKey(e) {
    let t = e;
    do
      t = this.collection.getKeyAfter(t), t == null && (t = this.collection.getFirstKey());
    while (t != null && this.isDisabled(t));
    return t;
  }
  getPreviousKey(e) {
    let t = e;
    do
      t = this.collection.getKeyBefore(t), t == null && (t = this.collection.getLastKey());
    while (t != null && this.isDisabled(t));
    return t;
  }
  constructor(e, t, i, l = /* @__PURE__ */ new Set()) {
    this.collection = e, this.flipDirection = t === "rtl" && i === "horizontal", this.disabledKeys = l, this.tabDirection = i === "horizontal";
  }
}
function Se(a, e, t) {
  let { orientation: i = "horizontal", keyboardActivation: l = "automatic" } = a, { collection: s, selectionManager: r, disabledKeys: d } = e, { direction: o } = pe(), n = S(() => new Ke(s, o, i, d), [
    s,
    d,
    i,
    o
  ]), { collectionProps: f } = Z({
    ref: t,
    selectionManager: r,
    keyboardDelegate: n,
    selectOnFocus: l === "automatic",
    disallowEmptySelection: !0,
    scrollRef: t,
    linkBehavior: "selection"
  }), c = ce();
  B.set(e, c);
  let $ = A({
    ...a,
    id: c
  });
  return {
    tabListProps: {
      ...v(f, $),
      role: "tablist",
      "aria-orientation": i,
      tabIndex: void 0
    }
  };
}
function De(a) {
  var e;
  let [t, i] = ve(a.selectedKey, (e = a.defaultSelectedKey) !== null && e !== void 0 ? e : null, a.onSelectionChange), l = S(() => t != null ? [
    t
  ] : [], [
    t
  ]), { collection: s, disabledKeys: r, selectionManager: d } = fe({
    ...a,
    selectionMode: "single",
    disallowEmptySelection: !0,
    allowDuplicateSelectionEvents: !0,
    selectedKeys: l,
    onSelectionChange: (n) => {
      if (n === "all") return;
      var f;
      let c = (f = n.values().next().value) !== null && f !== void 0 ? f : null;
      c === t && a.onSelectionChange && a.onSelectionChange(c), i(c);
    }
  }), o = t != null ? s.getItem(t) : null;
  return {
    collection: s,
    disabledKeys: r,
    selectionManager: d,
    selectedKey: t,
    setSelectedKey: i,
    selectedItem: o
  };
}
function Te(a) {
  var e, t;
  let i = De({
    ...a,
    onSelectionChange: a.onSelectionChange ? (o) => {
      var n;
      o != null && ((n = a.onSelectionChange) === null || n === void 0 || n.call(a, o));
    } : void 0,
    suppressTextValueWarning: !0,
    defaultSelectedKey: (t = (e = a.defaultSelectedKey) !== null && e !== void 0 ? e : I(a.collection, a.disabledKeys ? new Set(a.disabledKeys) : /* @__PURE__ */ new Set())) !== null && t !== void 0 ? t : void 0
  }), { selectionManager: l, collection: s, selectedKey: r } = i, d = Q(r);
  return X(() => {
    let o = r;
    a.selectedKey == null && (l.isEmpty || o == null || !s.getItem(o)) && (o = I(s, i.disabledKeys), o != null && l.setSelectedKeys([
      o
    ])), (o != null && l.focusedKey == null || !l.isFocused && o !== d.current) && l.setFocusedKey(o), d.current = o;
  }), {
    ...i,
    isDisabled: a.isDisabled || !1
  };
}
function I(a, e) {
  let t = null;
  if (a) {
    var i, l, s, r;
    for (t = a.getFirstKey(); t != null && (e.has(t) || !((l = a.getItem(t)) === null || l === void 0 || (i = l.props) === null || i === void 0) && i.isDisabled) && t !== a.getLastKey(); ) t = a.getKeyAfter(t);
    t != null && (e.has(t) || !((r = a.getItem(t)) === null || r === void 0 || (s = r.props) === null || s === void 0) && s.isDisabled) && t === a.getLastKey() && (t = a.getFirstKey());
  }
  return t;
}
const T = /* @__PURE__ */ V(null), P = /* @__PURE__ */ V(null), Ce = /* @__PURE__ */ E(function(e, t) {
  [e, t] = ae(e, t, T);
  let { children: i, orientation: l = "horizontal" } = e;
  return i = S(() => typeof i == "function" ? i({
    orientation: l,
    defaultChildren: null
  }) : i, [
    i,
    l
  ]), /* @__PURE__ */ b.createElement(re, {
    content: i
  }, (s) => /* @__PURE__ */ b.createElement(Ee, {
    props: e,
    collection: s,
    tabsRef: t
  }));
});
function Ee({ props: a, tabsRef: e, collection: t }) {
  let { orientation: i = "horizontal" } = a, l = Te({
    ...a,
    collection: t,
    children: void 0
  }), { focusProps: s, isFocused: r, isFocusVisible: d } = w({
    within: !0
  }), o = S(() => ({
    orientation: i,
    isFocusWithin: r,
    isFocusVisible: d
  }), [
    i,
    r,
    d
  ]), n = D({
    ...a,
    defaultClassName: "react-aria-Tabs",
    values: o
  }), f = g(a, {
    global: !0
  });
  return /* @__PURE__ */ b.createElement("div", {
    ...v(f, n, s),
    ref: e,
    slot: a.slot || void 0,
    "data-focused": r || void 0,
    "data-orientation": i,
    "data-focus-visible": d || void 0,
    "data-disabled": l.isDisabled || void 0
  }, /* @__PURE__ */ b.createElement(H, {
    values: [
      [
        T,
        a
      ],
      [
        P,
        l
      ]
    ]
  }, n.children));
}
const Fe = /* @__PURE__ */ E(function(e, t) {
  return x(P) ? /* @__PURE__ */ b.createElement(we, {
    props: e,
    forwardedRef: t
  }) : /* @__PURE__ */ b.createElement(z, e);
});
function we({ props: a, forwardedRef: e }) {
  let t = x(P), { CollectionRoot: i } = x(O), { orientation: l = "horizontal", keyboardActivation: s = "automatic" } = ie(T), r = F(e), { tabListProps: d } = Se({
    ...a,
    orientation: l,
    keyboardActivation: s
  }, t, r), o = D({
    ...a,
    children: null,
    defaultClassName: "react-aria-TabList",
    values: {
      orientation: l,
      state: t
    }
  }), n = g(a, {
    global: !0
  });
  return delete n.id, /* @__PURE__ */ b.createElement("div", {
    ...v(n, o, d),
    ref: r,
    "data-orientation": l || void 0
  }, /* @__PURE__ */ b.createElement(se, null, /* @__PURE__ */ b.createElement(i, {
    collection: t.collection,
    persistedKeys: te(t.selectionManager.focusedKey)
  })));
}
class U extends ne {
}
U.type = "item";
const Le = /* @__PURE__ */ oe(U, (a, e, t) => {
  let i = x(P), l = F(e), { tabProps: s, isSelected: r, isDisabled: d, isPressed: o } = xe({
    key: t.key,
    ...a
  }, i, l), { focusProps: n, isFocused: f, isFocusVisible: c } = w(), { hoverProps: $, isHovered: h } = he({
    isDisabled: d,
    onHoverStart: a.onHoverStart,
    onHoverEnd: a.onHoverEnd,
    onHoverChange: a.onHoverChange
  }), y = D({
    ...a,
    id: void 0,
    children: t.rendered,
    defaultClassName: "react-aria-Tab",
    values: {
      isSelected: r,
      isDisabled: d,
      isFocused: f,
      isFocusVisible: c,
      isPressed: o,
      isHovered: h
    }
  }), p = t.props.href ? "a" : "div", m = g(a, {
    global: !0
  });
  return delete m.id, delete m.onClick, /* @__PURE__ */ b.createElement(p, {
    ...v(m, y, s, n, $),
    ref: l,
    "data-selected": r || void 0,
    "data-disabled": d || void 0,
    "data-focused": f || void 0,
    "data-focus-visible": c || void 0,
    "data-pressed": o || void 0,
    "data-hovered": h || void 0
  }, /* @__PURE__ */ b.createElement(le.Provider, {
    value: {
      isSelected: r
    }
  }, y.children));
}), ke = /* @__PURE__ */ de(function(e, t) {
  const i = x(P);
  let l = F(t), { id: s, ...r } = e, { tabPanelProps: d } = ge(e, i, l), { focusProps: o, isFocused: n, isFocusVisible: f } = w(), c = i.selectedKey === e.id, $ = D({
    ...e,
    defaultClassName: "react-aria-TabPanel",
    values: {
      isFocused: n,
      isFocusVisible: f,
      // @ts-ignore - compatibility with React < 19
      isInert: N(!c),
      state: i
    }
  });
  if (!c && !e.shouldForceMount) return null;
  let h = g(r, {
    global: !0
  });
  delete h.id;
  let y = c ? v(h, d, o, $) : $;
  return /* @__PURE__ */ b.createElement("div", {
    ...y,
    ref: l,
    "data-focused": n || void 0,
    "data-focus-visible": f || void 0,
    // @ts-ignore
    inert: N(!c || e.inert),
    "data-inert": c ? void 0 : "true"
  }, /* @__PURE__ */ b.createElement(H, {
    values: [
      [
        T,
        null
      ],
      [
        P,
        null
      ]
    ]
  }, /* @__PURE__ */ b.createElement(O.Provider, {
    value: ee
  }, $.children)));
}), { withProvider: Me, withContext: C } = /* @__PURE__ */ ye({
  key: "tabs"
}), Re = /* @__PURE__ */ Me(
  "div",
  "root"
), Ne = /* @__PURE__ */ C(
  "div",
  "list"
), Ie = /* @__PURE__ */ C(
  "button",
  "tab"
), Ve = /* @__PURE__ */ C("div", "panels"), Oe = /* @__PURE__ */ C("div", "panel"), L = ({ children: a, isDisabled: e, ...t }) => /* @__PURE__ */ u(Ie, { asChild: !0, ...t, children: /* @__PURE__ */ u(Le, { isDisabled: e, children: a }) });
L.displayName = "Tabs.Tab";
const k = ({ tabs: a, children: e, ...t }) => {
  const [i, l] = j(t);
  if (!a && !e)
    throw new Error(
      'Tabs.List: Either provide "tabs" prop or "children" must be provided'
    );
  return /* @__PURE__ */ u(Ne, { ...i, asChild: !0, children: /* @__PURE__ */ u(Fe, { items: a, ...l, children: a ? (s) => /* @__PURE__ */ u(L, { id: s.id, isDisabled: s.isDisabled, children: s.tabLabel }, s.id) : e }) });
};
k.displayName = "Tabs.List";
const M = /* @__PURE__ */ E(
  ({ children: a, ...e }, t) => {
    if (!a)
      throw new Error("Tabs.Panel: children prop is required");
    return /* @__PURE__ */ u(Oe, { asChild: !0, ref: t, ...e, children: /* @__PURE__ */ u(ke, { children: a }) });
  }
);
M.displayName = "Tabs.Panel";
const R = ({ tabs: a, children: e, ...t }) => {
  if (!a && !e)
    throw new Error(
      'Tabs.Panels: Either provide "items" prop or "children" must be provided'
    );
  return /* @__PURE__ */ u(Ve, { ...t, children: a ? /* @__PURE__ */ u(z, { items: a, children: (i) => /* @__PURE__ */ u(M, { id: i.id, children: i.panelContent }, i.id) }) : e });
};
R.displayName = "Tabs.Panels";
const W = ({ children: a, tabs: e, ...t }) => {
  const i = me(), l = Pe({ key: "tabs" }), [s, r] = l.splitVariantProps(t), [d, o] = j(r), n = i.normalizeValue(s.orientation);
  return /* @__PURE__ */ u(Re, { asChild: !0, ...s, ...d, children: /* @__PURE__ */ u(Ce, { ...o, orientation: n, children: a || /* @__PURE__ */ G(J, { children: [
    /* @__PURE__ */ u(k, { tabs: e }),
    /* @__PURE__ */ u(R, { tabs: e })
  ] }) }) });
};
W.displayName = "Tabs.Root";
const rt = {
  /**
   * # Tabs.Root
   *
   * The root component that provides context and state management for the tabs.
   * Must wrap all tabs parts (List, Tab, Panels, Panel) to coordinate their behavior.
   *
   * @example
   * ```tsx
   * <Tabs.Root orientation="horizontal" size="md">
   *   <Tabs.List>
   *     <Tabs.Tab id="tab1">Tab 1</Tabs.Tab>
   *   </Tabs.List>
   *   <Tabs.Panels>
   *     <Tabs.Panel id="tab1">Content</Tabs.Panel>
   *   </Tabs.Panels>
   * </Tabs.Root>
   * ```
   */
  Root: W,
  /**
   * # Tabs.List
   *
   * The container for tab buttons that allows users to navigate between panels.
   * Handles keyboard navigation and manages the active tab state.
   *
   * @example
   * ```tsx
   * <Tabs.List>
   *   <Tabs.Tab id="tab1">First Tab</Tabs.Tab>
   *   <Tabs.Tab id="tab2">Second Tab</Tabs.Tab>
   * </Tabs.List>
   * ```
   */
  List: k,
  /**
   * # Tabs.Tab
   *
   * An individual tab button that activates its corresponding panel when selected.
   * Supports keyboard navigation, disabled states, and custom content.
   *
   * @example
   * ```tsx
   * <Tabs.Tab id="settings" isDisabled={false}>
   *   <Icon name="settings" />
   *   Settings
   * </Tabs.Tab>
   * ```
   */
  Tab: L,
  /**
   * # Tabs.Panels
   *
   * The container for all tab panels that displays the content for the active tab.
   * Manages visibility and accessibility of panel content.
   *
   * @example
   * ```tsx
   * <Tabs.Panels>
   *   <Tabs.Panel id="tab1">First panel content</Tabs.Panel>
   *   <Tabs.Panel id="tab2">Second panel content</Tabs.Panel>
   * </Tabs.Panels>
   * ```
   */
  Panels: R,
  /**
   * # Tabs.Panel
   *
   * An individual panel that displays content when its corresponding tab is active.
   * Automatically manages focus and accessibility attributes.
   *
   * @example
   * ```tsx
   * <Tabs.Panel id="profile">
   *   <h3>Profile Settings</h3>
   *   <p>Manage your profile information here.</p>
   * </Tabs.Panel>
   * ```
   */
  Panel: M
};
export {
  rt as T,
  W as a,
  k as b,
  L as c,
  R as d,
  M as e
};
//# sourceMappingURL=tabs-D0OPeQ_J.es.js.map
