import { a as e, c as t, i as n, n as r, o as i, r as a, s as o, t as s } from "../../date-BJE0WA9Z.js";
import { t as c } from "../../utils-B7XIe3qq.js";
import * as l from "react";
import { jsx as u, jsxs as d } from "react/jsx-runtime";
//#region src/react/primitives/calendar.tsx
function f({ value: f, rangeStart: p, rangeEnd: m, mode: h = "single", minDate: g, maxDate: _, disabledDates: v, weekStart: y = 0, showOutsideDays: b = !0, className: x, onChange: S, onRangeChange: C }) {
	let w = l.useMemo(() => t(/* @__PURE__ */ new Date()), []), T = f ?? p ?? w, [E, D] = l.useState(T.getFullYear()), [O, k] = l.useState(T.getMonth()), [A, j] = l.useState(f ? t(f) : null), [M, N] = l.useState(p ? t(p) : null), [P, F] = l.useState(m ? t(m) : null), [I, L] = l.useState(null);
	l.useEffect(() => {
		f !== void 0 && (j(f ? t(f) : null), f && (D(f.getFullYear()), k(f.getMonth())));
	}, [f]), l.useEffect(() => {
		p !== void 0 && N(p ? t(p) : null);
	}, [p]), l.useEffect(() => {
		m !== void 0 && F(m ? t(m) : null);
	}, [m]);
	let R = y === 1 ? s : r, z = l.useMemo(() => n(E, O, y), [
		E,
		O,
		y
	]), B = l.useCallback((e) => i(e, g, _, v), [
		g,
		_,
		v
	]);
	function V(e) {
		k((t) => {
			let n = t + e;
			return n > 11 ? (n = 0, D((e) => e + 1)) : n < 0 && (n = 11, D((e) => e - 1)), n;
		});
	}
	function H(e) {
		let n = t(e);
		if (h === "range") if (M === null || P !== null) N(n), F(null);
		else {
			let e = M, t = n;
			n < e && (t = e, e = n), N(e), F(t), C?.(e, t);
		}
		else j(n), S?.(n);
	}
	function U(t) {
		let n = t.getMonth() !== O, r = B(t), i = o(t, w), a = P ?? I, s = !1, l = !1, u = !1, d = !1;
		return h === "range" ? (M && o(t, M) && (l = !0, s = !0), a && o(t, a) && (u = !0, s = !0), M && a && e(t, M, a) && (d = !0)) : A && o(t, A) && (s = !0), c("inline-flex h-9 w-9 items-center justify-center rounded-lg text-[13px] transition-all duration-200", "hover:bg-glass-hover focus:outline-none focus:border-primary focus:shadow-glow", n && "text-foreground-muted", n && !b && "invisible", r && "pointer-events-none opacity-30", i && !s && "border border-primary/50 font-semibold text-primary", s && "bg-primary text-white font-semibold shadow-glow", l && "rounded-r-none", u && "rounded-l-none", d && "bg-primary/15 text-foreground rounded-none");
	}
	let W = l.useMemo(() => {
		let e = [];
		for (let t = 0; t < z.length; t += 7) e.push(z.slice(t, t + 7));
		return e;
	}, [z]);
	return /* @__PURE__ */ d("div", {
		"data-slot": "calendar",
		role: "group",
		className: c("w-fit", x),
		children: [/* @__PURE__ */ d("div", {
			className: "flex items-center justify-between px-1 pb-3",
			children: [
				/* @__PURE__ */ u("button", {
					type: "button",
					"aria-label": "Previous month",
					onClick: () => V(-1),
					className: c("inline-flex h-8 w-8 items-center justify-center rounded-lg transition-all duration-200", "text-foreground-secondary hover:bg-glass-hover hover:text-foreground"),
					children: /* @__PURE__ */ u("svg", {
						width: "16",
						height: "16",
						viewBox: "0 0 16 16",
						fill: "none",
						children: /* @__PURE__ */ u("path", {
							d: "M10 12L6 8L10 4",
							stroke: "currentColor",
							strokeWidth: "1.5",
							strokeLinecap: "round",
							strokeLinejoin: "round"
						})
					})
				}),
				/* @__PURE__ */ d("span", {
					className: "text-[13px] font-semibold text-foreground",
					children: [
						a[O],
						" ",
						E
					]
				}),
				/* @__PURE__ */ u("button", {
					type: "button",
					"aria-label": "Next month",
					onClick: () => V(1),
					className: c("inline-flex h-8 w-8 items-center justify-center rounded-lg transition-all duration-200", "text-foreground-secondary hover:bg-glass-hover hover:text-foreground"),
					children: /* @__PURE__ */ u("svg", {
						width: "16",
						height: "16",
						viewBox: "0 0 16 16",
						fill: "none",
						children: /* @__PURE__ */ u("path", {
							d: "M6 4L10 8L6 12",
							stroke: "currentColor",
							strokeWidth: "1.5",
							strokeLinecap: "round",
							strokeLinejoin: "round"
						})
					})
				})
			]
		}), /* @__PURE__ */ d("div", {
			role: "grid",
			className: "select-none",
			children: [/* @__PURE__ */ u("div", {
				role: "row",
				className: "mb-1 grid grid-cols-7 gap-0",
				children: R.map((e) => /* @__PURE__ */ u("span", {
					role: "columnheader",
					"aria-label": e,
					className: "flex h-9 w-9 items-center justify-center text-[11px] font-medium text-foreground-muted",
					children: e
				}, e))
			}), W.map((e, t) => /* @__PURE__ */ u("div", {
				role: "row",
				className: "grid grid-cols-7 gap-0",
				children: e.map((e, t) => {
					let n = B(e);
					return /* @__PURE__ */ u("button", {
						type: "button",
						role: "gridcell",
						"aria-disabled": n || void 0,
						"aria-selected": h !== "range" && A && o(e, A) || h === "range" && M && o(e, M) || h === "range" && P && o(e, P) || void 0,
						tabIndex: n ? -1 : 0,
						className: U(e),
						onClick: () => !n && H(e),
						onMouseEnter: () => h === "range" && L(e),
						onMouseLeave: () => h === "range" && L(null),
						children: e.getDate()
					}, t);
				})
			}, t))]
		})]
	});
}
//#endregion
export { f as Calendar };

//# sourceMappingURL=calendar.js.map