import { j as o } from "./jsx-runtime-NmMXPjeo.js";
import { createContext as S, useState as W, useCallback as C, useContext as k } from "react";
import { I as N, n as T, W as w, e as I, E as M } from "./Toggle-5mHDjpoq.js";
import { S as v, P as L } from "./Center-ZEYtK6iF.js";
import { C as a, d as O } from "./css-M9deYuc0.js";
import "react-hook-form";
import { C as A } from "./aggregator-e8E2YGic.js";
const q = (r = "", e = []) => {
  var t;
  if (e.length !== 0)
    return e.find((n) => n.tabKey === r) != null ? r : (t = e[e.length - 1]) == null ? void 0 : t.tabKey;
}, z = (r, e, t) => {
  if (e = e.trim(), e.length === 0)
    return t;
  const n = t.find((s) => s.tabKey === r);
  return n == null || n.name === e ? t : t.map((s) => s.tabKey === r ? { ...s, name: e } : s);
}, F = ({
  tabs: r,
  content: e,
  onSelect: t
}) => {
  var c;
  const [n, s] = W(((c = r[0]) == null ? void 0 : c.tabKey) ?? ""), l = C(
    (i) => {
      s(i), t == null || t(i);
    },
    [s, t]
  );
  return {
    tabs: r,
    selected: n,
    content: e,
    onSelect: l
  };
}, B = S({ tabs: [] }), P = () => k(B), G = ({
  content: r,
  children: e,
  onSelect: t,
  selected: n,
  closable: s,
  tabs: l,
  onClose: c,
  onDragStart: i,
  onDragEnd: m,
  onCreate: f,
  onRename: x,
  emptyContent: j,
  className: b,
  onDragOver: p,
  onDrop: u,
  size: g = "medium",
  direction: d = "y",
  ...E
}) => /* @__PURE__ */ o.jsx(
  v,
  {
    empty: !0,
    className: a(a.B("tabs"), b),
    onDragOver: p,
    onDrop: u,
    direction: d,
    ...E,
    children: /* @__PURE__ */ o.jsxs(
      B.Provider,
      {
        value: {
          tabs: l,
          emptyContent: j,
          selected: n,
          closable: s,
          content: e ?? r,
          onSelect: t,
          onClose: c,
          onDragStart: i,
          onDragEnd: m,
          onRename: x,
          onCreate: f,
          onDrop: u
        },
        children: [
          /* @__PURE__ */ o.jsx(y, { size: g, direction: O.swap(d) }),
          /* @__PURE__ */ o.jsx(_, {})
        ]
      }
    )
  }
), H = B.Provider, _ = () => {
  const {
    tabs: r,
    selected: e,
    content: t,
    emptyContent: n,
    onSelect: s
  } = P();
  let l = null;
  const c = r.find((i) => i.tabKey === e);
  return e == null || c == null ? n ?? null : (t != null ? l = t(c) : c.content != null && (l = c.content), /* @__PURE__ */ o.jsx(
    "div",
    {
      className: a.B("tabs-content"),
      onClick: () => s == null ? void 0 : s(e),
      style: {
        width: "100%",
        height: "100%",
        position: "relative",
        overflow: "hidden"
      },
      children: l
    }
  ));
}, h = "tabs-selector", y = ({
  className: r,
  size: e = "medium",
  direction: t = "x",
  ...n
}) => {
  const {
    tabs: s,
    selected: l,
    onSelect: c,
    onClose: i,
    closable: m,
    onDragEnd: f,
    onDragStart: x,
    onDrop: j,
    onRename: b,
    onCreate: p
  } = P();
  return /* @__PURE__ */ o.jsxs(
    v,
    {
      className: a(a.B(h), a.size(e), r),
      align: "center",
      justify: "spaceBetween",
      onDrop: j,
      empty: !0,
      direction: t,
      ...n,
      children: [
        /* @__PURE__ */ o.jsx(v, { direction: t, className: a.BE(h, "tabs"), empty: !0, children: s.map((u) => /* @__PURE__ */ o.jsx(
          J,
          {
            selected: l,
            onSelect: c,
            onClose: i,
            onDragStart: x,
            onDragEnd: f,
            onRename: b,
            closable: u.closable ?? m,
            size: e,
            ...u
          },
          u.tabKey
        )) }),
        /* @__PURE__ */ o.jsx(v, { className: a.BE(h, "actions"), children: p != null && /* @__PURE__ */ o.jsx(N, { size: e, sharp: !0, onClick: p, children: /* @__PURE__ */ o.jsx(T.Add, {}) }) })
      ]
    }
  );
}, J = ({
  selected: r,
  onSelect: e,
  onClose: t,
  tabKey: n,
  name: s,
  onDragStart: l,
  onDragEnd: c,
  onRename: i,
  closable: m = !0,
  icon: f,
  size: x,
  editable: j = !0
}) => {
  const b = C(
    (d) => l == null ? void 0 : l(d, { tabKey: n, name: s }),
    [l, n, s]
  ), p = C(
    (d) => c == null ? void 0 : c(d, { tabKey: n, name: s }),
    [c, n, s]
  ), u = C(
    (d) => {
      d.stopPropagation(), t == null || t(n);
    },
    [t, n]
  ), g = C(() => e == null ? void 0 : e(n), [e, n]);
  return /* @__PURE__ */ o.jsxs(
    L,
    {
      size: x,
      className: a(
        a.BE(h, "btn"),
        i == null && a.BEM(h, "btn", "uneditable"),
        a.selected(r === n),
        m && t != null && a.BEM(h, "btn", "closable")
      ),
      draggable: !0,
      direction: "x",
      justify: "center",
      align: "center",
      onClick: g,
      onDragStart: b,
      onDragEnd: p,
      bordered: !1,
      rounded: !1,
      children: [
        /* @__PURE__ */ o.jsx(
          Q,
          {
            name: s,
            tabKey: n,
            onRename: i,
            icon: f,
            editable: j,
            level: A[x]
          }
        ),
        m && t != null && /* @__PURE__ */ o.jsx(N, { onClick: u, children: /* @__PURE__ */ o.jsx(T.Close, { "aria-label": "pluto-tabs__close" }) })
      ]
    }
  );
}, Q = ({
  onRename: r,
  name: e,
  tabKey: t,
  icon: n,
  editable: s = !0,
  ...l
}) => r == null || !s ? n != null ? /* @__PURE__ */ o.jsx(w, { startIcon: n, noWrap: !0, ...l, children: e }) : /* @__PURE__ */ o.jsx(I, { noWrap: !0, ...l, children: e }) : /* @__PURE__ */ o.jsx(
  M,
  {
    onChange: (c) => r(t, c),
    value: e,
    noWrap: !0,
    ...l
  }
), K = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  Content: _,
  Provider: H,
  Selector: y,
  Tabs: G,
  TabsContext: B,
  rename: z,
  resetSelection: q,
  useStatic: F,
  useTabsContext: P
}, Symbol.toStringTag, { value: "Module" }));
export {
  G as T,
  z as a,
  K as e,
  q as r,
  F as u
};
//# sourceMappingURL=external-qZLl-K7A.js.map
