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 { i as CardTitle, n as CardContent, r as CardHeader, 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 supabase } from "./client-_1GYITl-.mjs";
import { r as useQueryClient } from "../_libs/tanstack__react-query.mjs";
import { n as useItems } from "./data-hooks--e_NaUze.mjs";
import { t as useAuth } from "./use-auth-bumQAdtQ.mjs";
import { t as Button } from "./button-BLZ6ednA.mjs";
import { t as Input } from "./input-B8Q2ztVi.mjs";
import { a as AlertDialogDescription, c as AlertDialogTitle, i as AlertDialogContent, n as AlertDialogAction, o as AlertDialogFooter, r as AlertDialogCancel, s as AlertDialogHeader, t as AlertDialog } from "./alert-dialog-DOhnwhih.mjs";
import { n as toast } from "../_libs/sonner.mjs";
import { E as Download, M as ArrowLeft, T as Eye, c as Trash2, i as Upload, y as LoaderCircle } 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 } from "./calculations-JyW9rCxF.mjs";
import { t as Label } from "./label-DBD1bRRP.mjs";
import { _ as useNavigate, g as Link } from "../_libs/@tanstack/react-router+[...].mjs";
import { i as yearForFyMonth, n as fyForDate, r as fyList, t as FY_MONTHS } from "./fy-C7Q3MBgO.mjs";
import { n as utils, t as readSync } from "../_libs/xlsx.mjs";
import { t as Route } from "./upload._division._aen.index-DOvmEXbR.mjs";
import { t as useAenUploads } from "./aen-hooks-Bhg_u-Ij.mjs";
//#region node_modules/.nitro/vite/services/ssr/assets/upload._division._aen.index-DTf-fRke.js
var import_react = /* @__PURE__ */ __toESM(require_react());
var import_jsx_runtime = require_jsx_runtime();
var num = (v) => {
	if (v === null || v === void 0 || v === "") return 0;
	const n = typeof v === "number" ? v : Number(String(v).replace(/[, ]/g, ""));
	return Number.isFinite(n) ? n : 0;
};
var clean = (v) => v === null || v === void 0 ? "" : String(v).replace(/\s+/g, " ").trim();
/** Parses one workbook. Each sheet has a header row (2) with blocks like "ADEN/XXX" or "SSE/PW/XXX",
*  each spanning 6 columns (Scope, New accrual, Cum scope, Progress, Cum progress, Net balance).
*  Data starts at row 4 (0-indexed). */
function parseWorkbook(buf) {
	const wb = readSync(buf, { type: "array" });
	const out = [];
	const seenAen = /* @__PURE__ */ new Set();
	for (const sheetName of wb.SheetNames) {
		const ws = wb.Sheets[sheetName];
		if (!ws) continue;
		const grid = utils.sheet_to_json(ws, {
			header: 1,
			defval: null,
			raw: true
		});
		if (grid.length < 5) continue;
		let hdr = -1;
		for (let i = 0; i < Math.min(10, grid.length); i++) if ((grid[i] || []).some((c) => /^\s*sr\.?\s*no/i.test(clean(c)))) {
			hdr = i;
			break;
		}
		if (hdr < 0) continue;
		const headerRow = grid[hdr];
		const blocks = [];
		for (let c = 3; c < headerRow.length; c += 6) {
			const raw = clean(headerRow[c]);
			if (!raw) continue;
			const kind = /sse/i.test(raw) ? "SSE" : "AEN";
			let name = raw.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
			name = name.replace(/^(SSE\/PW\/(?:TD\/)?|ADEN\/|AEN\/)/i, "").trim();
			blocks.push({
				start: c,
				name,
				kind
			});
		}
		if (!blocks.length) continue;
		const sheetAenMatch = sheetName.match(/AEN\s+(.+)/i);
		const sheetAen = sheetAenMatch ? sheetAenMatch[1].trim() : blocks[0].name;
		for (let r = hdr + 2; r < grid.length; r++) {
			const row = grid[r] || [];
			const sr = clean(row[0]);
			const item = clean(row[1]);
			const unit = clean(row[2]) || null;
			if (!sr && !item) continue;
			if (!sr) continue;
			for (const b of blocks) {
				const cells = [
					0,
					1,
					2,
					3,
					4,
					5
				].map((i) => num(row[b.start + i]));
				if (cells.every((x) => x === 0)) continue;
				const [scope_start, new_accrual, cum_scope, progress_month, cum_progress, net_balance] = cells;
				const isAen = b.kind === "AEN";
				const aenName = isAen ? b.name || sheetAen : sheetAen;
				const sseName = isAen ? null : b.name;
				const key = `${aenName}|${sseName ?? ""}|${sr}`;
				if (isAen) {
					if (seenAen.has(key)) continue;
					seenAen.add(key);
				}
				out.push({
					aen: aenName,
					sse: sseName,
					level: isAen ? "AEN" : "SSE",
					item_sr_no: sr,
					item_name: item,
					unit,
					scope_start,
					new_accrual,
					cum_scope,
					progress_month,
					cum_progress,
					net_balance
				});
			}
		}
	}
	return out;
}
/** Render a workbook's first non-empty sheet to HTML preserving merges,
* column widths, row heights, and freeze panes.
* Injects data-r / data-c attributes on every cell for edit tracking. */
function workbookToViewerHtml(buf) {
	const wb = readSync(buf, {
		type: "array",
		cellStyles: true,
		cellHTML: true
	});
	const sheetName = pickPrimarySheet(wb);
	const ws = wb.Sheets[sheetName];
	return {
		html: sheetToRichHtml(ws, sheetName),
		sheetName
	};
}
function pickPrimarySheet(wb) {
	for (const name of wb.SheetNames) {
		const ws = wb.Sheets[name];
		if (ws && ws["!ref"]) return name;
	}
	return wb.SheetNames[0];
}
function sheetToRichHtml(ws, sheetName) {
	const ref = ws["!ref"];
	if (!ref) return `<div class="p-4 text-sm text-muted-foreground">Empty sheet</div>`;
	const range = utils.decode_range(ref);
	const cols = ws["!cols"] ?? [];
	const rows = ws["!rows"] ?? [];
	const merges = ws["!merges"] ?? [];
	ws["!freeze"] || ws["!margins"];
	const paneXSplit = extractSplit(ws, "xSplit");
	const paneYSplit = extractSplit(ws, "ySplit");
	const covered = /* @__PURE__ */ new Set();
	const spans = /* @__PURE__ */ new Map();
	for (const m of merges) {
		const key = `${m.s.r}:${m.s.c}`;
		spans.set(key, {
			rs: m.e.r - m.s.r + 1,
			cs: m.e.c - m.s.c + 1
		});
		for (let r = m.s.r; r <= m.e.r; r++) for (let c = m.s.c; c <= m.e.c; c++) {
			if (r === m.s.r && c === m.s.c) continue;
			covered.add(`${r}:${c}`);
		}
	}
	let html = `<div class="excel-viewer-wrap">`;
	html += `<div class="excel-sheet-name">${escapeHtml(sheetName)}</div>`;
	html += `<div class="excel-scroll"><table class="excel-table"><colgroup>`;
	for (let c = range.s.c; c <= range.e.c; c++) {
		const w = cols[c]?.wpx ?? (cols[c]?.wch ? cols[c].wch * 7 : 90);
		html += `<col style="width:${w}px" />`;
	}
	html += `</colgroup><tbody>`;
	for (let r = range.s.r; r <= range.e.r; r++) {
		const h = rows[r]?.hpx ?? (rows[r]?.hpt ? rows[r].hpt * 1.333 : 22);
		html += `<tr style="height:${h}px" class="excel-row${paneYSplit > 0 && r < paneYSplit ? ` excel-sticky-row` : ""}">`;
		for (let c = range.s.c; c <= range.e.c; c++) {
			if (covered.has(`${r}:${c}`)) continue;
			const addr = utils.encode_cell({
				r,
				c
			});
			const cell = ws[addr];
			const span = spans.get(`${r}:${c}`);
			const rs = span ? ` rowspan="${span.rs}"` : "";
			const cs = span ? ` colspan="${span.cs}"` : "";
			const stickyCol = paneXSplit > 0 && c < paneXSplit ? ` excel-sticky-col` : "";
			const style = cellStyle(cell);
			const val = cellDisplay(cell);
			html += `<td data-r="${r}" data-c="${c}" data-addr="${addr}"${rs}${cs} class="excel-cell${stickyCol}" style="${style}">${val}</td>`;
		}
		html += `</tr>`;
	}
	html += `</tbody></table></div></div>`;
	return html;
}
function extractSplit(ws, kind) {
	const view = ws["!views"]?.[0]?.pane;
	return Number(view?.[kind] ?? 0) || 0;
}
function cellDisplay(cell) {
	if (!cell) return "";
	if (cell.h) return cell.h;
	if (cell.w !== void 0) return escapeHtml(cell.w);
	if (cell.v === void 0 || cell.v === null) return "";
	return escapeHtml(String(cell.v));
}
function cellStyle(cell) {
	const s = [];
	const st = cell?.s;
	if (st) {
		const font = st.font;
		const fill = st.fill;
		const align = st.alignment;
		const border = st.border;
		if (font?.bold) s.push("font-weight:600");
		if (font?.italic) s.push("font-style:italic");
		if (font?.sz) s.push(`font-size:${font.sz}px`);
		if (font?.color?.rgb) s.push(`color:#${normColor(font.color.rgb)}`);
		if (fill?.fgColor?.rgb) s.push(`background:#${normColor(fill.fgColor.rgb)}`);
		if (align?.horizontal) s.push(`text-align:${align.horizontal}`);
		if (align?.vertical) s.push(`vertical-align:${mapVAlign(align.vertical)}`);
		if (align?.wrapText) s.push("white-space:normal");
		if (border) {
			for (const side of [
				"top",
				"right",
				"bottom",
				"left"
			]) if (border[side]?.style) s.push(`border-${side}:1px solid #${normColor(border[side].color?.rgb) || "cbd5e1"}`);
		}
	}
	return s.join(";");
}
function normColor(rgb) {
	if (!rgb) return "";
	return rgb.length === 8 ? rgb.slice(2) : rgb;
}
function mapVAlign(v) {
	return v === "center" ? "middle" : v === "top" ? "top" : "bottom";
}
function escapeHtml(s) {
	return s.replace(/[&<>"']/g, (c) => ({
		"&": "&amp;",
		"<": "&lt;",
		">": "&gt;",
		"\"": "&quot;",
		"'": "&#39;"
	})[c]);
}
function AenUploadPage() {
	const { division, aen } = Route.useParams();
	const { isAdmin, user } = useAuth();
	const qc = useQueryClient();
	const nav = useNavigate();
	const { data: items = [] } = useItems();
	const { data: uploads = [] } = useAenUploads(division, aen);
	const [fy, setFy] = (0, import_react.useState)(fyForDate());
	const [month, setMonth] = (0, import_react.useState)((/* @__PURE__ */ new Date()).getMonth() + 1);
	const [file, setFile] = (0, import_react.useState)(null);
	const [busy, setBusy] = (0, import_react.useState)(false);
	const [conflict, setConflict] = (0, import_react.useState)(null);
	const fileRef = (0, import_react.useRef)(null);
	const year = yearForFyMonth(fy, month);
	const startUpload = async () => {
		if (!isAdmin) return toast.error("Only HQ Admins can upload data.");
		if (!file) return toast.error("Pick a file first.");
		const existing = uploads.filter((u) => u.year === year && u.month === month);
		if (existing.length) {
			setConflict({ existing });
			return;
		}
		await performUpload("new");
	};
	const performUpload = async (mode) => {
		if (!file) return;
		setConflict(null);
		setBusy(true);
		try {
			const buf = await file.arrayBuffer();
			const rows = parseWorkbook(buf);
			if (!rows.length) throw new Error("Could not parse any rows from the file.");
			const { html } = workbookToViewerHtml(buf);
			let version = 1;
			if (mode === "replace") {
				const existing = uploads.filter((u) => u.year === year && u.month === month);
				for (const e of existing) {
					if (e.storage_path) await supabase.storage.from("aen-uploads").remove([e.storage_path]);
					await supabase.from("uploads").delete().eq("id", e.id);
				}
			} else if (mode === "version") {
				const existing = uploads.filter((u) => u.year === year && u.month === month);
				version = Math.max(...existing.map((e) => e.version)) + 1;
			}
			const storagePath = `${division}/${aen}/${fy}/${String(month).padStart(2, "0")}/v${version}-${Date.now()}-${file.name}`;
			const { error: sErr } = await supabase.storage.from("aen-uploads").upload(storagePath, file, { contentType: file.type || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
			if (sErr) throw sErr;
			const { data: up, error: upErr } = await supabase.from("uploads").insert({
				division,
				aen,
				month,
				year,
				financial_year: fy,
				version,
				file_name: file.name,
				uploaded_by: user?.id,
				row_count: rows.length,
				storage_path: storagePath,
				sheet_html: html
			}).select().single();
			if (upErr) throw upErr;
			const wMap = new Map(items.map((i) => [i.sr_no, i.weightage]));
			const factRows = rows.map((r) => ({
				upload_id: up.id,
				division,
				month,
				year,
				aen: r.aen,
				sse: r.sse,
				level: r.level,
				item_sr_no: r.item_sr_no,
				item_name: r.item_name,
				unit: r.unit,
				scope_start: r.scope_start,
				new_accrual: r.new_accrual,
				cum_scope: r.cum_scope,
				progress_month: r.progress_month,
				cum_progress: r.cum_progress,
				net_balance: r.net_balance,
				weightage: wMap.get(r.item_sr_no) ?? null
			}));
			const CHUNK = 500;
			for (let i = 0; i < factRows.length; i += CHUNK) {
				const { error } = await supabase.from("fact_progress").insert(factRows.slice(i, i + CHUNK));
				if (error) throw error;
			}
			toast.success(`Uploaded v${version} · ${rows.length} rows`);
			qc.invalidateQueries();
			setFile(null);
			if (fileRef.current) fileRef.current.value = "";
			nav({
				to: "/upload/$division/$aen/$uploadId",
				params: {
					division,
					aen,
					uploadId: up.id
				}
			});
		} catch (e) {
			toast.error("Upload failed: " + e.message);
		} finally {
			setBusy(false);
		}
	};
	const deleteUpload = async (id, path) => {
		if (!confirm("Delete this version and its data?")) return;
		if (path) await supabase.storage.from("aen-uploads").remove([path]);
		const { error } = await supabase.from("uploads").delete().eq("id", id);
		if (error) return toast.error(error.message);
		toast.success("Deleted");
		qc.invalidateQueries();
	};
	const downloadOriginal = async (path, name) => {
		if (!path) return;
		const { data } = await supabase.storage.from("aen-uploads").createSignedUrl(path, 60);
		if (!data) return;
		const a = document.createElement("a");
		a.href = data.signedUrl;
		a.download = name ?? "sheet.xlsx";
		a.click();
	};
	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: `${aen} — ${division}`,
				subtitle: "Upload monthly AEN Excel sheet, view previous versions, or download originals.",
				right: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
					variant: "outline",
					asChild: true,
					children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
						to: "/upload/$division",
						params: { division },
						children: [
							/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrowLeft, { className: "h-4 w-4 mr-2" }),
							"Back to ",
							division
						]
					})
				})
			}),
			!isAdmin && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
				className: "mb-4 rounded-md border border-warning/40 bg-warning/10 p-3 text-sm",
				children: "You have viewer access. Only HQ Admins can upload data."
			}),
			/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card, {
				className: "mb-6",
				children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardTitle, { children: "Upload monthly sheet" }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CardContent, {
					className: "space-y-4",
					children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
						className: "grid grid-cols-1 md:grid-cols-4 gap-4",
						children: [
							/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
								className: "space-y-2",
								children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: "Financial Year" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Select, {
									value: fy,
									onValueChange: setFy,
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectValue, {}) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectContent, { children: fyList(6).map((f) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItem, {
										value: f,
										children: f
									}, f)) })]
								})]
							}),
							/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
								className: "space-y-2",
								children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: "Month" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Select, {
									value: String(month),
									onValueChange: (v) => setMonth(Number(v)),
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectValue, {}) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectContent, { children: FY_MONTHS.map((m) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SelectItem, {
										value: String(m.v),
										children: [
											m.label,
											" (",
											yearForFyMonth(fy, m.v),
											")"
										]
									}, m.v)) })]
								})]
							}),
							/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
								className: "space-y-2 md:col-span-2",
								children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: "Excel file (.xls or .xlsx)" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input, {
									ref: fileRef,
									type: "file",
									accept: ".xls,.xlsx",
									onChange: (e) => setFile(e.target.files?.[0] ?? null),
									disabled: !isAdmin
								})]
							})
						]
					}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
						className: "flex justify-end",
						children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
							onClick: startUpload,
							disabled: !isAdmin || !file || busy,
							children: [
								busy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoaderCircle, { className: "h-4 w-4 mr-2 animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Upload, { className: "h-4 w-4 mr-2" }),
								"Upload for ",
								FY_MONTHS.find((m) => m.v === month)?.label,
								" ",
								year
							]
						})
					})]
				})]
			}),
			/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardTitle, { children: "Version history" }) }), /* @__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: "Period" }),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { children: "FY" }),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { children: "Version" }),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { children: "File" }),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
						className: "text-right",
						children: "Rows"
					}),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, { children: "Uploaded" }),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableHead, {
						className: "text-right",
						children: "Actions"
					})
				] }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableBody, { children: [uploads.map((u) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow, { children: [
					/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableCell, { children: [
						MONTHS[u.month - 1].label,
						" ",
						u.year
					] }),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: u.financial_year ?? "—" }),
					/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableCell, { children: ["v", u.version] }),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
						className: "text-sm text-muted-foreground max-w-[280px] truncate",
						children: u.file_name
					}),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
						className: "text-right",
						children: u.row_count
					}),
					/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
						className: "text-sm text-muted-foreground",
						children: new Date(u.uploaded_at).toLocaleString()
					}),
					/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableCell, {
						className: "text-right space-x-1",
						children: [
							/* @__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,
										aen,
										uploadId: u.id
									},
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Eye, { className: "h-3.5 w-3.5 mr-1" }), "View"]
								})
							}),
							/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
								size: "sm",
								variant: "ghost",
								onClick: () => downloadOriginal(u.storage_path, u.file_name),
								disabled: !u.storage_path,
								children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Download, { className: "h-3.5 w-3.5" })
							}),
							isAdmin && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
								size: "sm",
								variant: "ghost",
								onClick: () => deleteUpload(u.id, u.storage_path),
								children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Trash2, { className: "h-3.5 w-3.5" })
							})
						]
					})
				] }, u.id)), uploads.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
					colSpan: 7,
					className: "text-center text-sm text-muted-foreground py-8",
					children: "No uploads yet for this AEN."
				}) })] })] })
			})] }),
			/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialog, {
				open: !!conflict,
				onOpenChange: (o) => !o && setConflict(null),
				children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AlertDialogContent, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AlertDialogHeader, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialogTitle, { children: "Upload already exists" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AlertDialogDescription, { children: [
					conflict?.existing.length,
					" upload(s) already exist for ",
					aen,
					" · ",
					FY_MONTHS.find((m) => m.v === month)?.label,
					" ",
					year,
					". Choose an action:"
				] })] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AlertDialogFooter, {
					className: "gap-2 sm:gap-2",
					children: [
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialogCancel, { children: "Cancel" }),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
							variant: "outline",
							onClick: () => performUpload("version"),
							children: "Create New Version"
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialogAction, {
							onClick: () => performUpload("replace"),
							children: "Replace Existing"
						})
					]
				})] })
			})
		]
	});
}
//#endregion
export { AenUploadPage as component };
