import{u as H,c as z,b as E,j as e,M as B}from"./index-D9pJRAs5.js";import{r as d}from"./vendor-D6aTFYy9.js";import{P as I}from"./PageHeader-qe8kxWqe.js";import{S as K}from"./StatCard-B6PlblaT.js";import{M as U}from"./ModernButton-pccD6_if.js";import{M as W}from"./ModernTable-CF_GWw7E.js";import{F as y,C as _,A as P,ad as O,v as Y,ac as G,b5 as Q,av as V,ae as b,aS as X,ag as w,ah as k,ai as N,aj as u,aT as q,al as J,am as Z,an as ee,b6 as te,a2 as ae,aV as se,aW as ne,Q as re}from"./ui-CtYVlq7P.js";import"./pdf-Bz_mU5mG.js";const ge=()=>{const{t:a}=H(),{employees:T,attendanceRecords:f}=z(),{theme:$}=E(),s=$.mode==="dark",[m,S]=d.useState("overview"),[c,D]=d.useState("week"),[x,C]=d.useState("all"),[h,L]=d.useState(""),g={backgroundColor:s?"#0f172a":"#ffffff",border:"none",borderRadius:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",fontSize:"12px",color:s?"#e2e8f0":"#334155"},i=d.useMemo(()=>{const t=new Date;return f.filter(n=>{const r=new Date(n.timestamp);let o=!0;return c==="today"?o=r.toDateString()===t.toDateString():c==="week"?o=r>=new Date(t.getTime()-7*24*60*60*1e3):c==="month"&&(o=r.getMonth()===t.getMonth()&&r.getFullYear()===t.getFullYear()),o&&(x==="all"||n.employeeId===x)&&n.employeeName.toLowerCase().includes(h.toLowerCase())}).sort((n,r)=>new Date(r.timestamp).getTime()-new Date(n.timestamp).getTime())},[f,c,x,h]),l=d.useMemo(()=>{if(i.length===0)return{count:0,onTime:0,avgHours:0,late:0};const t=i.filter(o=>o.action==="clock_in"),n=t.filter(o=>new Date(o.timestamp).getHours()<9).length,r=t.length-n;return{count:i.length,onTime:t.length>0?n/t.length*100:100,late:t.length>0?r/t.length*100:0,avgHours:8.5}},[i]),j=d.useMemo(()=>{const t=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n={};return i.forEach(r=>{const o=t[new Date(r.timestamp).getDay()];n[o]=(n[o]||0)+1}),t.map(r=>({day:r,records:n[r]||0}))},[i]),v=[{name:a("attendance.charts.onTime"),value:l.onTime,color:"#10b981"},{name:a("attendance.charts.late"),value:l.late,color:"#f59e0b"},{name:a("attendance.charts.absent"),value:i.length===0?100:0,color:"#ef4444"}],R=()=>{const t=`${a("attendance.report.title")} - ${c} 

${a("attendance.report.generated")}: ${new Date().toLocaleString()} 

${a("attendance.report.summary")}: 
 - ${a("attendance.report.totalRecords")}: ${i.length} 
 - ${a("attendance.report.onTimeRate")}: ${l.onTime.toFixed(1)}%

${a("attendance.report.records")}: 
${i.map(p=>`${new Date(p.timestamp).toLocaleString()} - ${p.employeeName}: ${a("hr."+p.action.replace("_",""))}`).join(`
`)} `,n=new Blob([t],{type:"text/plain"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=`attendance-report - ${new Date().toISOString().split("T")[0]}.txt`,o.click(),URL.revokeObjectURL(r)},M=[{label:a("attendance.stats.totalRecords"),value:l.count,icon:y,gradient:"from-indigo-500 to-blue-600"},{label:a("attendance.stats.onTimeRate"),value:`${l.onTime.toFixed(0)}% `,icon:_,gradient:"from-emerald-500 to-teal-600"},{label:a("attendance.stats.lateRate"),value:`${l.late.toFixed(0)}% `,icon:P,gradient:"from-amber-500 to-orange-600"},{label:a("attendance.stats.avgHours"),value:`${l.avgHours} h`,icon:O,gradient:"from-violet-500 to-purple-600"}],A=[{key:"overview",label:a("attendance.tabs.overview"),icon:Y},{key:"detailed",label:a("attendance.tabs.detailed"),icon:y},{key:"analytics",label:a("attendance.tabs.analytics"),icon:G}],F=[{header:a("hr.employee"),accessor:"employeeName",render:t=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center text-xs font-bold ${s?"bg-indigo-900 text-indigo-300":"bg-indigo-100 text-indigo-700"} `,children:t.charAt(0)}),e.jsx("span",{className:"font-bold",children:t})]})},{header:a("hr.date"),accessor:"timestamp",render:t=>new Date(t).toLocaleDateString()},{header:a("attendance.table.time"),accessor:"timestamp",render:t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},{header:a("attendance.table.action"),accessor:"action",render:t=>e.jsx("span",{className:"capitalize",children:a(`hr.${t.replace("_","")} `)})},{header:a("hr.status"),accessor:"id",render:(t,n)=>{const r=new Date(n.timestamp),o=n.action==="clock_in"&&r.getHours()>=9;return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded-md text-xs font-bold uppercase ${o?s?"bg-amber-500/10 text-amber-400":"bg-amber-100 text-amber-700":s?"bg-emerald-500/10 text-emerald-400":"bg-emerald-100 text-emerald-700"} `,children:a(o?"attendance.table.late":"attendance.table.onTime")})}}];return e.jsxs("div",{className:"space-y-8 animate-fade-in pb-20",children:[e.jsx(I,{title:a("attendance.reportsTitle"),subtitle:a("attendance.reportsSubtitle"),description:a("attendance.reportsDesc"),icon:Q,gradient:"from-indigo-600 to-blue-600",action:e.jsx(U,{onClick:R,icon:V,variant:"outline",size:"sm",children:a("attendance.exportReport")})}),e.jsxs("div",{className:"flex flex-col lg:flex-row justify-between items-start lg:items-center gap-4",children:[e.jsx("div",{className:`p-1 rounded-xl flex ${s?"bg-slate-800":"bg-slate-100"} `,children:A.map(t=>{const n=t.icon,r=m===t.key;return e.jsxs("button",{onClick:()=>S(t.key),className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold transition-all ${r?"bg-white text-indigo-600 shadow-sm dark:bg-slate-700 dark:text-white":"text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-white"} `,children:[e.jsx(n,{size:16}),e.jsx("span",{children:t.label})]},t.key)})}),e.jsxs("div",{className:"flex gap-2 w-full lg:w-auto",children:[e.jsxs("select",{value:c,onChange:t=>D(t.target.value),className:`px-4 py-2 rounded-xl text-sm font-bold border outline-none cursor-pointer transition-colors ${s?"bg-slate-900 border-slate-700 text-white focus:border-indigo-500":"bg-white border-slate-200 text-slate-700 focus:border-indigo-500"} `,children:[e.jsx("option",{value:"today",children:"Today"}),e.jsx("option",{value:"week",children:"This Week"}),e.jsx("option",{value:"month",children:"This Month"})]}),e.jsxs("select",{value:x,onChange:t=>C(t.target.value),className:`px-4 py-2 rounded-xl text-sm font-bold border outline-none cursor-pointer transition-colors ${s?"bg-slate-900 border-slate-700 text-white focus:border-indigo-500":"bg-white border-slate-200 text-slate-700 focus:border-indigo-500"} `,children:[e.jsx("option",{value:"all",children:"All Staff"}),T.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]})]}),e.jsxs("div",{className:"min-h-[500px]",children:[m==="overview"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:M.map((t,n)=>e.jsx(K,{label:t.label,value:t.value,icon:t.icon,gradient:t.gradient},n))}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:`p-6 rounded-3xl border shadow-sm ${s?"bg-slate-900 border-slate-800":"bg-white border-slate-100"} `,children:[e.jsx("h3",{className:`text-lg font-bold mb-6 ${s?"text-white":"text-slate-900"} `,children:a("attendance.charts.weeklyActivity")}),e.jsx("div",{className:"h-[300px]",children:e.jsx(b,{width:"100%",height:"100%",children:e.jsxs(X,{data:j,children:[e.jsx(w,{strokeDasharray:"3 3",vertical:!1,stroke:s?"#1e293b":"#f1f5f9"}),e.jsx(k,{dataKey:"day",axisLine:!1,tickLine:!1,tick:{fill:s?"#94a3b8":"#64748b"},dy:10}),e.jsx(N,{axisLine:!1,tickLine:!1,tick:{fill:s?"#94a3b8":"#64748b"}}),e.jsx(u,{contentStyle:g,cursor:{fill:s?"#334155":"#f8fafc"}}),e.jsx(q,{dataKey:"records",fill:"#6366f1",radius:[6,6,0,0],name:a("attendance.charts.scans"),barSize:32})]})})})]}),e.jsxs("div",{className:`p-6 rounded-3xl border shadow-sm ${s?"bg-slate-900 border-slate-800":"bg-white border-slate-100"} `,children:[e.jsx("h3",{className:`text-lg font-bold mb-6 ${s?"text-white":"text-slate-900"} `,children:a("attendance.charts.punctuality")}),e.jsx("div",{className:"h-[300px]",children:e.jsx(b,{width:"100%",height:"100%",children:e.jsxs(J,{children:[e.jsx(Z,{data:v,cx:"50%",cy:"50%",innerRadius:80,outerRadius:110,paddingAngle:4,dataKey:"value",stroke:"none",children:v.map((t,n)=>e.jsx(ee,{fill:t.color},n))}),e.jsx(u,{contentStyle:g}),e.jsx(te,{verticalAlign:"bottom",height:36,iconType:"circle"})]})})})]})]})]}),m==="detailed"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"w-full max-w-md",children:e.jsx(B,{placeholder:"Search employee name...",value:h,onChange:t=>L(t.target.value),icon:ae})}),e.jsx(W,{data:i,columns:F,keyField:"id",emptyMessage:"No attendance records found for this period."})]}),m==="analytics"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:`p-6 rounded-3xl border shadow-sm ${s?"bg-slate-900 border-slate-800":"bg-white border-slate-100"} `,children:[e.jsx("h3",{className:`text-lg font-bold mb-6 ${s?"text-white":"text-slate-900"} `,children:a("attendance.charts.trendAnalysis")}),e.jsx("div",{className:"h-[350px]",children:e.jsx(b,{width:"100%",height:"100%",children:e.jsxs(se,{data:j,children:[e.jsx(w,{strokeDasharray:"3 3",vertical:!1,stroke:s?"#1e293b":"#f1f5f9"}),e.jsx(k,{dataKey:"day",axisLine:!1,tickLine:!1,tick:{fill:s?"#94a3b8":"#64748b"},dy:10}),e.jsx(N,{axisLine:!1,tickLine:!1,tick:{fill:s?"#94a3b8":"#64748b"}}),e.jsx(u,{contentStyle:g}),e.jsx(ne,{type:"monotone",dataKey:"records",stroke:"#6366f1",strokeWidth:3,dot:{r:4,fill:"#6366f1",strokeWidth:2,stroke:"#fff"},activeDot:{r:6}})]})})})]}),e.jsx("div",{className:`p-6 rounded-3xl border ${s?"bg-indigo-900/10 border-indigo-500/20":"bg-indigo-50 border-indigo-100"} `,children:e.jsxs("div",{className:"flex gap-4",children:[e.jsx("div",{className:`p-3 rounded-xl h-fit ${s?"bg-indigo-500/20 text-indigo-300":"bg-indigo-100 text-indigo-600"} `,children:e.jsx(re,{size:24})}),e.jsxs("div",{children:[e.jsx("h4",{className:`text-lg font-bold mb-2 ${s?"text-indigo-300":"text-indigo-900"} `,children:a("attendance.security.biometricTitle")}),e.jsx("div",{className:`space-y - 1 text-sm ${s?"text-indigo-200/70":"text-indigo-800/70"} `,children:e.jsx("p",{children:a("attendance.security.biometricDesc")})})]})]})})]})]})]})};export{ge as default};
