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 { u as require_react } from "../_libs/@floating-ui/react-dom+[...].mjs";
import { n as CardContent, t as Card } from "./card-BXjpJ96D.mjs";
import { a as TableHead, n as TableBody, o as TableHeader, r as TableCell, s as TableRow, t as Table } from "./table-BAceZcga.mjs";
import { t as Badge } from "./badge-D1Dupn2y.mjs";
import { t as Button } from "./button-BLZ6ednA.mjs";
import { M as ArrowLeft, S as History, T as Eye, i as Upload } from "../_libs/lucide-react.mjs";
import { n as MONTHS, t as DIVISIONS } from "./calculations-JyW9rCxF.mjs";
import { g as Link } from "../_libs/@tanstack/react-router+[...].mjs";
import { t as Route } from "./upload._division.index-CxdBOqO8.mjs";
import { n as useDivisionAens, t as useAenUploads } from "./aen-hooks-Bhg_u-Ij.mjs";
//#region node_modules/.nitro/vite/services/ssr/assets/upload._division.index-BKyTr3ki.js
var import_react = /* @__PURE__ */ __toESM(require_react());
var import_jsx_runtime = require_jsx_runtime();
function DivisionAenList() {
	const { division } = Route.useParams();
	const div = division;
	const valid = DIVISIONS.includes(div);
	const { data: aens = [] } = useDivisionAens(valid ? div : void 0);
	const { data: uploads = [] } = useAenUploads(valid ? div : void 0);
	const rowsByAen = (0, import_react.useMemo)(() => {
		const map = /* @__PURE__ */ new Map();
		for (const u of uploads) {
			if (!u.aen) continue;
			const arr = map.get(u.aen) ?? [];
			arr.push(u);
			map.set(u.aen, arr);
		}
		return map;
	}, [uploads]);
	if (!valid) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
		className: "p-6",
		children: "Unknown division."
	});
	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: `${div} — AEN Upload Dashboard`,
			subtitle: `${aens.length} AENs · click an AEN to upload, view or edit sheets`,
			right: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
				variant: "outline",
				asChild: true,
				children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
					to: "/upload",
					children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrowLeft, { className: "h-4 w-4 mr-2" }), "Back"]
				})
			})
		}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardContent, {
			className: "p-0",
			children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Table, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow, { children: [
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { children: "AEN" }),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { children: "Upload Status" }),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { children: "Last Uploaded" }),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { children: "Uploaded Month" }),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { children: "Versions" }),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
					className: "text-right",
					children: "Actions"
				})
			] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableBody, { children: [aens.map((a) => {
				const rows = rowsByAen.get(a.aen_code) ?? [];
				const latest = rows[0];
				const monthLabel = latest ? `${MONTHS[latest.month - 1].label} ${latest.year}` : "—";
				const versionCount = rows.length;
				return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow, { children: [
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
						className: "font-medium",
						children: a.aen_code
					}),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: latest ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, {
						className: "bg-success text-success-foreground",
						children: "Uploaded"
					}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Badge, {
						variant: "outline",
						children: "Pending"
					}) }),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
						className: "text-sm text-muted-foreground",
						children: latest ? new Date(latest.uploaded_at).toLocaleString() : "—"
					}),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
						className: "text-sm",
						children: monthLabel
					}),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
						className: "text-sm",
						children: versionCount || "—"
					}),
					/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableCell, {
						className: "text-right space-x-1",
						children: [
							/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
								size: "sm",
								asChild: true,
								children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
									to: "/upload/$division/$aen",
									params: {
										division: div,
										aen: a.aen_code
									},
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Upload, { className: "h-3.5 w-3.5 mr-1" }), "Upload"]
								})
							}),
							latest && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
								size: "sm",
								variant: "outline",
								asChild: true,
								children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
									to: "/upload/$division/$aen/$uploadId",
									params: {
										division: div,
										aen: a.aen_code,
										uploadId: latest.id
									},
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Eye, { className: "h-3.5 w-3.5 mr-1" }), "View"]
								})
							}),
							versionCount > 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
								size: "sm",
								variant: "ghost",
								asChild: true,
								children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
									to: "/upload/$division/$aen",
									params: {
										division: div,
										aen: a.aen_code
									},
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(History, { className: "h-3.5 w-3.5 mr-1" }), "History"]
								})
							})
						]
					})
				] }, a.id);
			}), aens.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableCell, {
				colSpan: 6,
				className: "text-center text-sm text-muted-foreground py-8",
				children: [
					"No AENs seeded for ",
					div,
					"."
				]
			}) })] })] })
		}) })]
	});
}
//#endregion
export { DivisionAenList as component };
