"use client"; import { useRouter } from "next/navigation"; import { useLocale, useTranslations } from "next-intl"; import { useCallback, useMemo, useState } from "react"; import { exportPermissions } from "@/actions/admin-housekeeping"; import { Button } from "@/components/ui/button"; /* ────────── Export Section ────────── */ export function ExportSection() { const t = useTranslations("pages.admin.housekeeping"); const [data, setData] = useState(null); const [copying, setCopying] = useState(false); const [exporting, setExporting] = useState(false); const handleExport = useCallback(async () => { setExporting(true); try { const json = await exportPermissions(); setData(json); } finally { setExporting(false); } }, []); const handleCopy = useCallback(async () => { if (!data) return; setCopying(true); try { await navigator.clipboard.writeText(data); } catch { /* fallback */ } setTimeout(() => setCopying(false), 1500); }, [data]); return (

{t("exportTitle")}

{t("exportHint")}

{data && (
							{data}
						
)}
); } /* ────────── Audit Section ────────── */ interface AuditEntry { id: number; userId: number; username: string | null; action: string; target: string; targetId: number | null; createdAt: string; } interface AuditSectionProps { initialLogs: { rows: AuditEntry[]; total: number; page: number; perPage: number; lastPage: number; } | null; } export function AuditSection({ initialLogs }: AuditSectionProps) { const t = useTranslations("pages.admin.housekeeping"); const locale = useLocale(); const router = useRouter(); const dateFmt = useMemo( () => new Intl.DateTimeFormat(locale, { dateStyle: "short", timeStyle: "short", }), [locale], ); if (!initialLogs || initialLogs.rows.length === 0) { return (

{t("auditTitle")}

{t("auditHint")}

{t("auditLogsAt")}

); } return (

{t("auditTitle")}

{t("auditHint")}

{initialLogs.rows.map((log) => ( ))}
{t("auditTime")} {t("auditUser")} {t("auditAction")} {t("auditTarget")}
{dateFmt.format(new Date(log.createdAt))} {log.username ?? "System"} {log.action} {log.target} {log.targetId != null ? ` #${log.targetId}` : ""}
{t("auditLogsAt")}{" "}
); }