import { b as Q, g as x, m as g, p as d, v as u } from "./vendor-preact-DThS2ZQ_.js";
import { n as cn } from "./loadingIcon-B0ysgiNq.js";
//#region src/shared/tabs/tabs.tsx
var TabsContext = Q(null);
var useTabsContext = () => {
	const ctx = x(TabsContext);
	if (!ctx) throw new Error("Tabs compound components must be used within <Tabs>");
	return ctx;
};
var tabId = (baseId, value) => `${baseId}-tab-${value}`;
var panelId = (baseId, value) => `${baseId}-panel-${value}`;
var TabsRoot = ({ defaultValue, value, onValueChange, orientation = "horizontal", activation = "manual", listClassName, triggerClassName, activeTriggerClassName, children }) => {
	const baseId = g();
	const [internalValue, setInternalValue] = d(defaultValue ?? value ?? "");
	const activeValue = value ?? internalValue;
	const setActiveValue = (next) => {
		if (value === void 0) setInternalValue(next);
		onValueChange?.(next);
	};
	return /* @__PURE__ */ u(TabsContext.Provider, {
		value: {
			baseId,
			activeValue,
			setActiveValue,
			orientation,
			activation,
			listClassName,
			triggerClassName,
			activeTriggerClassName
		},
		children
	});
};
var TabsList = ({ label, labelledBy, children }) => {
	const { listClassName, orientation } = useTabsContext();
	return /* @__PURE__ */ u("div", {
		role: "tablist",
		"aria-orientation": orientation,
		"aria-label": label,
		"aria-labelledby": labelledBy,
		class: listClassName,
		children
	});
};
var TabsTrigger = ({ value, disabled, children }) => {
	const { baseId, activeValue, setActiveValue, orientation, activation, triggerClassName, activeTriggerClassName } = useTabsContext();
	const selected = activeValue === value;
	const handleKeyDown = (event) => {
		const horizontal = orientation === "horizontal";
		const nextKey = horizontal ? "ArrowRight" : "ArrowDown";
		const prevKey = horizontal ? "ArrowLeft" : "ArrowUp";
		if (event.key !== nextKey && event.key !== prevKey && event.key !== "Home" && event.key !== "End") return;
		const list = event.currentTarget.closest("[role=\"tablist\"]");
		if (!list) return;
		const tabs = Array.from(list.querySelectorAll("[role=\"tab\"]:not([disabled])"));
		const currentIndex = tabs.indexOf(event.currentTarget);
		if (currentIndex === -1) return;
		let target;
		if (event.key === nextKey) target = tabs[(currentIndex + 1) % tabs.length];
		else if (event.key === prevKey) target = tabs[(currentIndex - 1 + tabs.length) % tabs.length];
		else if (event.key === "Home") target = tabs[0];
		else if (event.key === "End") target = tabs[tabs.length - 1];
		if (!target) return;
		event.preventDefault();
		target.focus();
		if (activation === "automatic") {
			const nextValue = target.dataset.value;
			if (nextValue !== void 0) setActiveValue(nextValue);
		}
	};
	return /* @__PURE__ */ u("button", {
		type: "button",
		role: "tab",
		id: tabId(baseId, value),
		"aria-selected": selected,
		"aria-controls": panelId(baseId, value),
		tabIndex: selected ? 0 : -1,
		disabled,
		"data-value": value,
		class: cn(triggerClassName, selected && activeTriggerClassName),
		onClick: () => setActiveValue(value),
		onKeyDown: handleKeyDown,
		children
	});
};
var TabsContent = ({ value, className, children }) => {
	const { baseId, activeValue } = useTabsContext();
	if (activeValue !== value) return null;
	return /* @__PURE__ */ u("div", {
		role: "tabpanel",
		id: panelId(baseId, value),
		"aria-labelledby": tabId(baseId, value),
		class: className,
		children
	});
};
var Tabs = Object.assign(TabsRoot, {
	List: TabsList,
	Trigger: TabsTrigger,
	Content: TabsContent
});
//#endregion
export { Tabs as t };
