import { t as e } from "../chunks/ui.module-DHVTOqZ0.js";
import { n as t } from "../chunks/uiClasses-UkaejTdf.js";
import { d as n, h as r, l as i } from "../chunks/misc-aGQBhywJ.js";
import { Children as a, isValidElement as o, useId as s, useMemo as c, useRef as l, useState as u } from "react";
import { cn as d, getRovingFocusTargetIndex as f } from "@ryuzaki13/react-foundation-lib/utils";
import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
//#region src/tabs/lib/tabs.ts
function g(e) {
	return e.find((e) => !e.disabled)?.id ?? null;
}
function _(e, t) {
	return t ? e.find((e) => e.id === t && !e.disabled)?.id ?? g(e) : g(e);
}
function v(e) {
	return e.filter((e) => !e.disabled);
}
function y({ mountStrategy: e, isSelected: t, isVisited: n }) {
	return e === "keep-mounted" || t || e === "lazy" && n;
}
//#endregion
//#region src/tabs/model/useTabsState.ts
function b({ items: e, value: t, defaultValue: n, onValueChange: r, orientation: i = "horizontal", activationMode: a = "automatic", loop: o = !0 }) {
	let d = t !== void 0, p = c(() => v(e), [e]), m = p[0]?.id ?? null, [h, g] = u(() => _(e, n)), [y, b] = u(() => _(e, t ?? n)), x = _(e, t ?? n), [S, C] = u(() => x ? /* @__PURE__ */ new Set([x]) : /* @__PURE__ */ new Set()), w = s(), T = l({}), E = _(e, d ? t : h), D = _(e, y) ?? E ?? m, O = c(() => {
		if (!E || S.has(E)) return S;
		let e = new Set(S);
		return e.add(E), e;
	}, [E, S]), k = (t) => {
		let n = _(e, t);
		n && (C((e) => {
			if (e.has(n)) return e;
			let t = new Set(e);
			return t.add(n), t;
		}), d || g(n), r?.(n));
	}, A = (e) => {
		T.current[e]?.focus();
	}, j = (e) => {
		if (p.length < 2) return;
		let t = Math.max(0, p.findIndex((e) => e.id === (D ?? E ?? m))), n = f({
			currentIndex: t,
			itemCount: p.length,
			key: e.key,
			orientation: i,
			wrap: o
		});
		if (n === null) return;
		e.preventDefault();
		let r = p[n]?.id;
		r && (b(r), A(r), a === "automatic" && k(r));
	}, M = (e) => {
		let t = e.relatedTarget;
		t instanceof Node && e.currentTarget.contains(t) || b(E ?? m);
	}, N = (e) => `${w}-tab-${e}`, P = (e) => `${w}-panel-${e}`;
	return {
		activationMode: a,
		orientation: i,
		selectedTabId: E,
		tabbableTabId: D,
		onTabListKeyDown: j,
		onTabListBlur: M,
		getTabElementId: N,
		getPanelElementId: P,
		getTabButtonProps: (e) => {
			let t = e.id === E, n = e.id === D;
			return {
				ref: (t) => {
					T.current[e.id] = t;
				},
				type: "button",
				role: "tab",
				id: N(e.id),
				disabled: e.disabled,
				"aria-selected": t,
				"aria-controls": P(e.id),
				"aria-disabled": e.disabled || void 0,
				tabIndex: e.disabled ? -1 : n ? 0 : -1,
				onFocus: () => b(e.id),
				onClick: () => k(e.id)
			};
		},
		isVisited: (e) => O.has(e)
	};
}
var x = {
	tabsContainer: "pcMjuj",
	clean: "NLOw2z",
	tabs: "ZSAoAa",
	panels: "psYhsZ",
	horizontal: "mNDq9-",
	tab: "_28F3fs",
	vertical: "g156KO",
	panelScrollable: "C2mO1e",
	selected: "UKZXTZ",
	panel: "jiTafe",
	panelBody: "nhD0k7",
	layoutPanels: "G8FICe",
	layoutPanel: "W50XHh",
	layoutSection: "vnjXkU",
	layoutContent: "Nzvfhw"
};
//#endregion
//#region src/tabs/ui/TabsLoadingState.tsx
function S({ containerClassName: e, tabListClassName: t, panelsClassName: n, panelClassName: i, panelBodyClassName: a, loadingText: o }) {
	return /* @__PURE__ */ h("div", {
		className: e,
		children: [/* @__PURE__ */ m("div", {
			className: t,
			"aria-hidden": "true",
			children: /* @__PURE__ */ m("button", {
				type: "button",
				disabled: !0,
				"data-disabled": "",
				className: d(x.tab, "skeletonLine"),
				children: "Загрузка..."
			})
		}), /* @__PURE__ */ m("div", {
			className: n,
			"aria-busy": "true",
			children: /* @__PURE__ */ m("div", {
				className: i,
				children: /* @__PURE__ */ m("div", {
					className: a,
					children: /* @__PURE__ */ m(r, {
						text: o,
						className: "radiusSm"
					})
				})
			})
		})]
	});
}
//#endregion
//#region src/tabs/ui/TabsNoDataState.tsx
function C({ containerClassName: e, panelsClassName: t, panelClassName: r, panelBodyClassName: i }) {
	return /* @__PURE__ */ m("div", {
		className: e,
		children: /* @__PURE__ */ m("div", {
			className: t,
			children: /* @__PURE__ */ m("div", {
				className: r,
				children: /* @__PURE__ */ m("div", {
					className: i,
					children: /* @__PURE__ */ m(n, { className: "radiusSm" })
				})
			})
		})
	});
}
//#endregion
//#region src/tabs/ui/TabsPanel.tsx
function w({ tabId: e, isSelected: t, className: n, getTabElementId: r, getPanelElementId: i, children: a }) {
	return /* @__PURE__ */ m("div", {
		role: "tabpanel",
		id: i(e),
		"aria-labelledby": r(e),
		hidden: !t,
		className: n,
		children: a
	});
}
//#endregion
//#region src/tabs/ui/TabsTabList.tsx
function T({ items: e, state: t, className: n, ariaLabel: r, ariaLabelledBy: a }) {
	return /* @__PURE__ */ m("div", {
		className: n,
		role: "tablist",
		"aria-orientation": t.orientation,
		"aria-label": r,
		"aria-labelledby": a,
		onKeyDown: t.onTabListKeyDown,
		onBlur: t.onTabListBlur,
		children: ((e) => t.orientation === "horizontal" ? /* @__PURE__ */ m(i, { children: e }) : /* @__PURE__ */ m(p, { children: e }))(e.map((e) => /* @__PURE__ */ m("button", {
			...t.getTabButtonProps(e),
			"data-ui": "tabs-tab",
			"data-action": "select-tab",
			className: d(x.tab, "textWrap", e.id === t.selectedTabId && x.selected),
			children: e.title
		}, e.id)))
	});
}
//#endregion
//#region src/tabs/ui/TabsBox.tsx
function E({ items: n, value: r, defaultValue: i, onValueChange: a, className: o, isLoading: s, loadingText: c, orientation: l = "horizontal", activationMode: u = "automatic", mountStrategy: f = "unmount", loop: p = !0, tone: g = "primary", clean: _ = !1, "aria-label": v, "aria-labelledby": E }) {
	let D = b({
		items: n,
		value: r,
		defaultValue: i,
		onValueChange: a,
		orientation: l,
		activationMode: u,
		loop: p
	}), O = d(x.tabsContainer, _ ? x.clean : e.uiFilledPanel, x[l], t(g), o), k = x.tabs, A = d(x.panels, x.panelScrollable, "scrollable overscroll"), j = x.panel, M = x.panelBody;
	return s ? /* @__PURE__ */ m(S, {
		containerClassName: O,
		tabListClassName: k,
		panelsClassName: A,
		panelClassName: j,
		panelBodyClassName: M,
		loadingText: c
	}) : n.length ? /* @__PURE__ */ h("div", {
		className: O,
		children: [/* @__PURE__ */ m(T, {
			items: n,
			state: D,
			className: k,
			ariaLabel: v,
			ariaLabelledBy: E
		}), /* @__PURE__ */ m("div", {
			className: A,
			children: n.map((e) => {
				let t = e.id === D.selectedTabId;
				return y({
					mountStrategy: f,
					isSelected: t,
					isVisited: D.isVisited(e.id)
				}) ? /* @__PURE__ */ m(w, {
					tabId: e.id,
					isSelected: t,
					className: j,
					getTabElementId: D.getTabElementId,
					getPanelElementId: D.getPanelElementId,
					children: /* @__PURE__ */ m("div", {
						className: M,
						children: e.content
					})
				}, e.id) : null;
			})
		})]
	}) : /* @__PURE__ */ m(C, {
		containerClassName: O,
		panelsClassName: A,
		panelClassName: j,
		panelBodyClassName: M
	});
}
//#endregion
//#region src/tabs/ui/TabsLayout.tsx
var D = "TabsLayout.Tab", O = "TabsLayout.Toolbar", k = "TabsLayout.Content", A = "TabsLayout.Footer";
function j(e) {
	let { type: t } = e;
	if (typeof t == "function") {
		let e = t;
		return e.displayName ?? e.name ?? null;
	}
	if (typeof t == "object" && t && "displayName" in t) {
		let e = t;
		return typeof e.displayName == "string" ? e.displayName : null;
	}
	return null;
}
function M(e, t) {
	return o(e) && j(e) === t;
}
function N({ children: e }) {
	return /* @__PURE__ */ m(p, { children: e });
}
N.displayName = D;
function P({ children: e }) {
	return /* @__PURE__ */ m(p, { children: e });
}
P.displayName = O;
function F({ children: e }) {
	return /* @__PURE__ */ m(p, { children: e });
}
F.displayName = k;
function I({ children: e }) {
	return /* @__PURE__ */ m(p, { children: e });
}
I.displayName = A;
function L(e, t) {
	let n = null, r = null, i = null;
	for (let s of a.toArray(e)) {
		if (!o(s)) throw Error(`TabsLayout.Tab "${t}" поддерживает только дочерние элементы TabsLayout.Toolbar, TabsLayout.Content и TabsLayout.Footer.`);
		if (M(s, O)) {
			if (n) throw Error(`TabsLayout.Tab "${t}" содержит более одного блока TabsLayout.Toolbar.`);
			n = s.props;
			continue;
		}
		if (M(s, k)) {
			if (r) throw Error(`TabsLayout.Tab "${t}" содержит более одного блока TabsLayout.Content.`);
			r = s.props;
			continue;
		}
		if (M(s, A)) {
			if (i) throw Error(`TabsLayout.Tab "${t}" содержит более одного блока TabsLayout.Footer.`);
			i = s.props;
			continue;
		}
		throw Error(`TabsLayout.Tab "${t}" поддерживает только дочерние элементы TabsLayout.Toolbar, TabsLayout.Content и TabsLayout.Footer.`);
	}
	if (!r) throw Error(`TabsLayout.Tab "${t}" должен содержать блок TabsLayout.Content.`);
	return {
		toolbar: n,
		content: r,
		footer: i
	};
}
function R(e) {
	return a.toArray(e).map((e) => {
		if (!M(e, D)) throw Error("TabsLayout принимает только дочерние элементы TabsLayout.Tab.");
		return {
			id: e.props.id,
			title: e.props.title,
			disabled: e.props.disabled,
			...L(e.props.children, e.props.id)
		};
	});
}
var z = ({ children: n, value: r, defaultValue: i, onValueChange: a, className: o, orientation: s = "horizontal", activationMode: l = "manual", mountStrategy: u = "lazy", loop: f = !0, tone: p = "primary", clean: g = !1, "aria-label": _, "aria-labelledby": v }) => {
	let S = c(() => R(n), [n]), C = b({
		items: S,
		value: r,
		defaultValue: i,
		onValueChange: a,
		orientation: s,
		activationMode: l,
		loop: f
	}), E = d(x.tabsContainer, g ? x.clean : e.uiFilledPanel, x[s], t(p), o), D = d(x.panels, x.layoutPanels);
	return /* @__PURE__ */ h("div", {
		className: E,
		children: [/* @__PURE__ */ m(T, {
			items: S,
			state: C,
			className: x.tabs,
			ariaLabel: _,
			ariaLabelledBy: v
		}), /* @__PURE__ */ m("div", {
			className: D,
			children: S.map((e) => {
				let t = e.id === C.selectedTabId;
				if (!y({
					mountStrategy: u,
					isSelected: t,
					isVisited: C.isVisited(e.id)
				})) return null;
				let n = `${e.toolbar ? "auto " : ""}minmax(0, 1fr)${e.footer ? " auto" : ""}`;
				return /* @__PURE__ */ m(w, {
					tabId: e.id,
					isSelected: t,
					className: x.panel,
					getTabElementId: C.getTabElementId,
					getPanelElementId: C.getPanelElementId,
					children: /* @__PURE__ */ h("div", {
						className: x.layoutPanel,
						style: { gridTemplateRows: n },
						children: [
							e.toolbar ? /* @__PURE__ */ m("div", {
								className: d(x.layoutSection, e.toolbar.className),
								children: e.toolbar.children
							}) : null,
							/* @__PURE__ */ m("div", {
								className: d(x.layoutSection, x.layoutContent, e.content.className),
								children: e.content.children
							}),
							e.footer ? /* @__PURE__ */ m("div", {
								className: d(x.layoutSection, e.footer.className),
								children: e.footer.children
							}) : null
						]
					})
				}, e.id);
			})
		})]
	});
};
z.displayName = "TabsLayout";
var B = Object.assign(z, {
	Tab: N,
	Toolbar: P,
	Content: F,
	Footer: I
});
//#endregion
export { E as TabsBox, B as TabsLayout };

//# sourceMappingURL=index.js.map