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

//# sourceMappingURL=index.js.map