"use client";
import { cn } from "./index3.js";
import { FOCUS_RING } from "./index58.js";
import { useCalendarContext } from "./index76.js";
import { jsx } from "react/jsx-runtime";
//#region src/components/molecules/data/Calendar/CalendarViewSwitcher.tsx
var VIEW_OPTIONS = [
	{
		value: "month",
		label: "Month"
	},
	{
		value: "week",
		label: "Week"
	},
	{
		value: "day",
		label: "Day"
	}
];
function CalendarViewSwitcher({ view: viewProp, onViewChange: onViewChangeProp, className }) {
	const ctx = useCalendarContext();
	const view = viewProp ?? ctx.view;
	const handleChange = onViewChangeProp ?? ctx.onViewChange;
	const { idPrefix } = ctx;
	const handleKeyDown = (e, currentIndex) => {
		let nextIndex = null;
		if (e.key === "ArrowRight" || e.key === "ArrowDown") nextIndex = (currentIndex + 1) % VIEW_OPTIONS.length;
		else if (e.key === "ArrowLeft" || e.key === "ArrowUp") nextIndex = (currentIndex - 1 + VIEW_OPTIONS.length) % VIEW_OPTIONS.length;
		else if (e.key === "Home") nextIndex = 0;
		else if (e.key === "End") nextIndex = VIEW_OPTIONS.length - 1;
		if (nextIndex !== null) {
			e.preventDefault();
			const next = VIEW_OPTIONS[nextIndex];
			handleChange(next.value);
			(e.target.closest("[role=\"tablist\"]")?.querySelectorAll("[role=\"tab\"]"))?.[nextIndex]?.focus();
		}
	};
	return /* @__PURE__ */ jsx("div", {
		"data-slot": "calendar-view-switcher",
		role: "tablist",
		"aria-label": "Calendar view",
		className: cn("flex overflow-hidden rounded-lg border border-border", className),
		children: VIEW_OPTIONS.map((option, index) => {
			const isSelected = view === option.value;
			return /* @__PURE__ */ jsx("button", {
				type: "button",
				role: "tab",
				id: `${idPrefix}-tab-${option.value}`,
				"aria-selected": isSelected,
				"aria-controls": `${idPrefix}-tabpanel-${option.value}`,
				tabIndex: isSelected ? 0 : -1,
				onClick: () => handleChange(option.value),
				onKeyDown: (e) => handleKeyDown(e, index),
				className: cn("min-h-[44px] px-3 py-1.5 text-xs font-medium transition-colors duration-200 motion-reduce:transition-none", "border-e border-border last:border-e-0", FOCUS_RING, isSelected ? "bg-muted font-semibold text-foreground" : "text-muted-foreground hover:bg-muted/50"),
				children: option.label
			}, option.value);
		})
	});
}
CalendarViewSwitcher.displayName = "CalendarViewSwitcher";
//#endregion
export { CalendarViewSwitcher };

//# sourceMappingURL=index75.js.map