import{i as e,n as t,t as n}from"./jsx-runtime-bzQ4Vb5N.js";import{t as r}from"./page-header-CqpDR1d0.js";import{i,n as a,r as o,t as s}from"./card-2XLQ4Sqm.js";import{i as c,t as l}from"./data-hooks-B3BJoiaE.js";import{t as u}from"./button-CpC4WAFQ.js";import{a as d,i as f,n as p,r as m,t as h}from"./select-Brl3xHTL.js";import{t as g}from"./download-C_iswExO.js";import{n as _}from"./calculations-Djz1Ahac.js";import{n as v,r as y}from"./xlsx-DZIa3EYa.js";var b=e(t()),x=n();function S(){let{data:e=[]}=c(),[t,n]=(0,b.useState)(),{data:S=[]}=l(t),C=e.find(e=>e.id===t),w=e=>{if(!S.length||!C)return;let t=v.json_to_sheet(S),n=v.book_new();v.book_append_sheet(n,t,`Data`);let r=`ER-SPRMS_${C.division}_${C.year}_${C.month}`;e===`xlsx`?y(n,`${r}.xlsx`):y(n,`${r}.csv`,{bookType:`csv`})};return(0,x.jsxs)(`div`,{className:`p-6 max-w-[1000px] mx-auto`,children:[(0,x.jsx)(r,{title:`Reports & Exports`,subtitle:`Download the raw fact table for a chosen upload.`}),(0,x.jsxs)(s,{children:[(0,x.jsx)(o,{children:(0,x.jsx)(i,{children:`Choose an upload`})}),(0,x.jsxs)(a,{className:`space-y-4`,children:[(0,x.jsxs)(h,{value:t,onValueChange:n,children:[(0,x.jsx)(f,{children:(0,x.jsx)(d,{placeholder:`Select…`})}),(0,x.jsx)(p,{children:e.map(e=>(0,x.jsxs)(m,{value:e.id,children:[e.division,` · `,_[e.month-1].label,` `,e.year,` (`,e.row_count,` rows)`]},e.id))})]}),(0,x.jsxs)(`div`,{className:`flex gap-2`,children:[(0,x.jsxs)(u,{onClick:()=>w(`xlsx`),disabled:!S.length,children:[(0,x.jsx)(g,{className:`h-4 w-4 mr-2`}),`Export Excel`]}),(0,x.jsxs)(u,{variant:`outline`,onClick:()=>w(`csv`),disabled:!S.length,children:[(0,x.jsx)(g,{className:`h-4 w-4 mr-2`}),`Export CSV`]})]}),(0,x.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`PDF export uses your browser's print dialog — press Ctrl/⌘+P on any dashboard for a printable version.`})]})]})]})}export{S as component};