import { n as __toESM } from "../_runtime.mjs";
import { I as require_jsx_runtime } from "../_libs/@radix-ui/react-alert-dialog+[...].mjs";
import { t as PageHeader } from "./page-header-BE1EG5aP.mjs";
import { t as cn } from "./utils-C_uf36nf.mjs";
import { u as require_react } from "../_libs/@floating-ui/react-dom+[...].mjs";
import { n as CardContent, t as Card } from "./card-BXjpJ96D.mjs";
import { O as ChevronRight, j as Building2 } from "../_libs/lucide-react.mjs";
import { a as SelectValue, i as SelectTrigger, n as SelectContent, r as SelectItem, t as Select } from "./select-CYB-gyWu.mjs";
import { n as MONTHS, t as DIVISIONS } from "./calculations-JyW9rCxF.mjs";
import { g as Link } from "../_libs/@tanstack/react-router+[...].mjs";
import { n as fyForDate } from "./fy-C7Q3MBgO.mjs";
import { n as useDivisionAens, t as useAenUploads } from "./aen-hooks-Bhg_u-Ij.mjs";
import { n as Root, t as Indicator } from "../_libs/radix-ui__react-progress.mjs";
//#region node_modules/.nitro/vite/services/ssr/assets/upload.index-B-YVLwGz.js
var import_react = /* @__PURE__ */ __toESM(require_react());
var import_jsx_runtime = require_jsx_runtime();
var Progress = import_react.forwardRef(({ className, value, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Root, {
	ref,
	className: cn("relative h-2 w-full overflow-hidden rounded-full bg-primary/20", className),
	...props,
	children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Indicator, {
		className: "h-full w-full flex-1 bg-primary transition-all",
		style: { transform: `translateX(-${100 - (value || 0)}%)` }
	})
}));
Progress.displayName = Root.displayName;
function UploadHome() {
	const { data: aens = [] } = useDivisionAens();
	const { data: uploads = [] } = useAenUploads();
	const now = /* @__PURE__ */ new Date();
	const [month, setMonth] = (0, import_react.useState)(now.getMonth() + 1);
	const [year, setYear] = (0, import_react.useState)(now.getFullYear());
	const fy = fyForDate(new Date(year, month - 1, 1));
	const stats = (0, import_react.useMemo)(() => {
		return DIVISIONS.map((d) => {
			const total = aens.filter((a) => a.division === d).length;
			const uploaded = new Set(uploads.filter((u) => u.division === d && u.month === month && u.year === year).map((u) => u.aen)).size;
			return {
				division: d,
				total,
				uploaded,
				pending: Math.max(0, total - uploaded),
				pct: total > 0 ? Math.round(uploaded / total * 100) : 0
			};
		});
	}, [
		aens,
		uploads,
		month,
		year
	]);
	return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
		className: "p-6 max-w-[1400px] mx-auto",
		children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageHeader, {
			title: "Data Upload",
			subtitle: `AEN-wise monthly upload dashboard · FY ${fy}`,
			right: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
				className: "flex gap-2",
				children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Select, {
					value: String(month),
					onValueChange: (v) => setMonth(Number(v)),
					children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectTrigger, {
						className: "w-40",
						children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectValue, {})
					}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectContent, { children: MONTHS.map((m) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItem, {
						value: String(m.v),
						children: m.label
					}, m.v)) })]
				}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Select, {
					value: String(year),
					onValueChange: (v) => setYear(Number(v)),
					children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectTrigger, {
						className: "w-28",
						children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectValue, {})
					}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectContent, { children: [
						year + 1,
						year,
						year - 1,
						year - 2
					].map((y) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItem, {
						value: String(y),
						children: y
					}, y)) })]
				})]
			})
		}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
			className: "grid gap-4 md:grid-cols-2 xl:grid-cols-4",
			children: stats.map((s) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
				to: "/upload/$division",
				params: { division: s.division },
				className: "block group",
				children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card, {
					className: "h-full transition hover:border-primary hover:shadow-md",
					children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CardContent, {
						className: "p-5 space-y-4",
						children: [
							/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
								className: "flex items-center justify-between",
								children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
									className: "flex items-center gap-3",
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
										className: "grid h-11 w-11 place-items-center rounded-lg bg-primary/10 text-primary",
										children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Building2, { className: "h-5 w-5" })
									}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
										className: "text-xs uppercase text-muted-foreground",
										children: "Division"
									}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
										className: "text-xl font-semibold",
										children: s.division
									})] })]
								}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronRight, { className: "h-5 w-5 text-muted-foreground group-hover:text-primary" })]
							}),
							/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
								className: "grid grid-cols-3 gap-2 text-center",
								children: [
									/* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatMini, {
										label: "Total AENs",
										value: s.total
									}),
									/* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatMini, {
										label: "Uploaded",
										value: s.uploaded,
										tone: "success"
									}),
									/* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatMini, {
										label: "Pending",
										value: s.pending,
										tone: s.pending ? "warning" : "muted"
									})
								]
							}),
							/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
								className: "space-y-1",
								children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
									className: "flex items-center justify-between text-xs",
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
										className: "text-muted-foreground",
										children: "Completion"
									}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
										className: "font-medium",
										children: [s.pct, "%"]
									})]
								}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Progress, { value: s.pct })]
							})
						]
					})
				})
			}, s.division))
		})]
	});
}
function StatMini({ label, value, tone }) {
	return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
		className: "rounded-md border p-2",
		children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
			className: `text-xl font-semibold ${tone === "success" ? "text-success" : tone === "warning" ? "text-warning" : "text-foreground"}`,
			children: value
		}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
			className: "text-[11px] text-muted-foreground",
			children: label
		})]
	});
}
//#endregion
export { UploadHome as component };
