"use client";
import { createContext as e, useCallback as t, useId as n, useReducer as r } from "react";
import { jsx as i } from "react/jsx-runtime";
//#region lib/ui/contexts/TabControl.tsx
function a(e) {
	let t = [...e.refs.keys()], n = (t.findIndex((t) => t === e.value) + 1) % t.length;
	return {
		...e,
		value: t[n]
	};
}
function o(e) {
	let t = [...e.refs.keys()], n = (t.findIndex((t) => t === e.value) - 1 + t.length) % t.length;
	return {
		...e,
		value: t[n]
	};
}
function s(e) {
	let t = [...e.refs.keys()][0];
	return {
		...e,
		value: t
	};
}
function c(e) {
	let t = [...e.refs.keys()], n = t[t.length - 1];
	return {
		...e,
		value: n
	};
}
function l(e, t) {
	let n = new Map(e.refs);
	return n.delete(t.payload.value), {
		...e,
		refs: n
	};
}
function u(e, t) {
	return {
		...e,
		...e.value === -1 && { value: t.payload.value },
		refs: new Map(e.refs).set(t.payload.value, t.payload.ref)
	};
}
function d(e, t) {
	return {
		...e,
		value: t.payload
	};
}
var f = {
	next: a,
	previous: o,
	start: s,
	end: c,
	register: u,
	unregister: l,
	update: d
};
function p(e, t) {
	if (t.type in f) {
		let n = f[t.type];
		return n(e, t);
	}
	return e;
}
var m = e({
	uid: "",
	value: 0,
	refs: /* @__PURE__ */ new Map(),
	dispatch: () => {
		console.warn("Tab Controller Context dispatch used outside of Provider");
	},
	register: () => {
		console.warn("Tab Controller Context register used outside of Provider");
	},
	unregister: () => {
		console.warn("Tab Controller Context unregister used outside of Provider");
	}
});
m.displayName = "TabControlContext";
function h({ selected: e, children: a }) {
	let [o, s] = r(p, {
		uid: n(),
		value: e || -1,
		refs: /* @__PURE__ */ new Map()
	}), c = t((e, t) => {
		s({
			type: "register",
			payload: {
				value: e,
				ref: t
			}
		});
	}, []), l = t((e) => {
		s({
			type: "unregister",
			payload: { value: e }
		});
	}, []);
	return /* @__PURE__ */ i(m.Provider, {
		value: {
			...o,
			dispatch: s,
			register: c,
			unregister: l
		},
		children: a
	});
}
//#endregion
export { m as TabControlContext, h as TabsProvider };

//# sourceMappingURL=TabControl.js.map