1import{v as te,j as e,T as re,C as E,a0 as ae,a1 as se,a2 as le,a3 as ne}from"./index-BqXoy4fy.js";import{E as ce}from"./EmptyState-B-Pcpc4w.js";import{r as a}from"./react-DBTFCQ9V.js";import{a0 as U,am as _,a2 as oe,c as de,R as xe,V as ie,aq as me,X as L,T as be,at as ue,aa as pe}from"./utils-DRBGurlB.js";import{T as ve}from"./TableSkeleton-D0RMBCQd.js";import"./firebase-DUmv6NEE.js";const Se=({permission:b})=>{const n=a.useId(),[O,T]=a.useState([]),[q,R]=a.useState(!0),[W,m]=a.useState(!1),[u,z]=a.useState(null),[p,P]=a.useState(!1),[v,B]=a.useState(""),[h,f]=a.useState({isOpen:!1,recordId:null}),[V,g]=a.useState(!1),w=a.useRef(null),[s,i]=a.useState({name:"",idNumber:"",effectiveDate:"",expiryDate:null}),[S,$]=a.useState(null);a.useEffect(()=>{C()},[]);const C=async()=>{R(!0);try{const t=await te();T(t)}catch(t){console.error("Error fetching health records:",t),c("è¼å ¥è³æå¤±æ","error")}finally{R(!1)}},c=(t,r="success")=>{$({id:Date.now(),message:t,type:r})},D=t=>{if(!t.expiryDate)return!1;const r=new Date;r.setHours(0,0,0,0);const o=new Date(t.expiryDate);return r>o},k=a.useMemo(()=>O.filter(t=>{const r=t.name.toLowerCase().includes(v.toLowerCase())||t.idNumber&&t.idNumber.toLowerCase().includes(v.toLowerCase()),o=D(t);return r&&(p?!o:!0)}),[O,v,p]),F=t=>{t?(z(t.id||null),i(t)):(z(null),i({name:"",idNumber:"",effectiveDate:new Date().toISOString().split("T")[0],expiryDate:null})),m(!0)},X=async t=>{t.preventDefault();try{u?await se(u,s):await le(s),m(!1),C(),c(u?"æ´æ°æå":"æ°å¢æå")}catch(r){console.error("Error saving:",r),c("å²å失æ","error")}},G=t=>{t&&f({isOpen:!0,recordId:t})},J=async()=>{if(h.recordId)try{await ne(h.recordId),T(t=>t.filter(r=>r.id!==h.recordId)),f({isOpen:!1,recordId:null}),c("åªé¤æå")}catch(t){console.error("Deletion failed:",t),c("åªé¤å¤±æ","error")}},K=t=>{var l;const r=(l=t.target.files)==null?void 0:l[0];if(!r)return;const o=new FileReader;o.onload=async d=>{var j;try{const I=(j=d.target)==null?void 0:j.result,M=ue(I,{type:"binary"}),Y=M.SheetNames[0],Z=M.Sheets[Y],ee=pe.sheet_to_json(Z),y=[];ee.forEach(x=>{if(x.å§å&&x.çææä»½){const H=N=>{if(!N)return null;if(typeof N=="number")return new Date((N-25569)*86400*1e3).toISOString().split("T")[0];const A=new Date(N);return isNaN(A.getTime())?null:A.toISOString().split("T")[0]};y.push({name:x.å§å,idNumber:x.身åèåè?String(x.身åèåè).toUpperCase().trim():"",effectiveDate:H(x.çææä»½)||new Date().toISOString().split("T")[0],expiryDate:H(x.失ææä»½)})}}),y.length>0?(await ae(y),C(),g(!1),c(`æåå¯å ¥ ${y.length} çè³æ`)):c("æ¾ä¸å°ææè³æï¼è«æª¢æ¥ Excel æ¨é¡æ¯å¦æ£ç¢º","error")}catch(I){console.error("Import Error",I),c("å¯å ¥å¤±æï¼è«æª¢æ¥æªæ¡æ ¼å¼","error")}finally{w.current&&(w.current.value="")}},o.readAsBinaryString(r)},Q=()=>{const r="data:text/csv;charset=utf-8,\uFEFF"+["å§å","身åèåè","çææä»½","失ææä»½","çæ "].join(",")+` 2`+k.map(d=>{const j=D(d)?"已失æ":"ææ";return[d.name,d.idNumber||"",d.effectiveDate,d.expiryDate||"",j].join(",")}).join(` 3`),o=encodeURI(r),l=document.createElement("a");l.setAttribute("href",o),l.setAttribute("download",`å¥ä¿ç´é_${new Date().toISOString().split("T")[0]}.csv`),document.body.appendChild(l),l.click(),document.body.removeChild(l)};return e.jsxs("div",{className:"p-4 md:p-6 lg:p-8 h-full flex flex-col relative font-sans",children:[S&&e.jsx(re,{message:S.message,type:S.type,onClose:()=>$(null)}),e.jsxs("div",{className:"flex flex-col gap-6 mb-6 flex-shrink-0",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[e.jsx("h2",{className:"text-xl md:text-3xl font-bold text-[var(--text-primary)] tracking-tight flex items-center gap-2 md:gap-3",children:"å¥ä¿ç´éæ·»å "}),e.jsxs("div",{className:"flex items-center gap-2 text-[var(--text-secondary)] text-xs md:text-sm",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-[var(--success)] shadow-lg shadow-green-500/50"}),e.jsx("span",{className:"hidden sm:inline",children:"系統é£ç·æ£å¸¸"})]})]}),e.jsxs("div",{className:"flex flex-col md:flex-row items-center justify-between gap-4 bg-[var(--bg-card)] p-4 rounded-2xl border border-[var(--border)] backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-4 w-full md:w-auto",children:[e.jsxs("div",{className:"relative group w-full sm:w-auto",children:[e.jsx(U,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--text-muted)] group-focus-within:text-[var(--accent)] transition-colors",size:18}
3),e.jsx("input",{"aria-label":"æå°å§åæèº«åè...",type:"text",placeholder:"æå°å§åæèº«åè...",value:v,onChange:t=>B(t.target.value),className:"bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] pl-10 pr-4 py-2 rounded-xl focus:border-[var(--accent)] outline-none transition-all w-full sm:w-64"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none group",children:[e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",checked:p,onChange:t=>P(t.target.checked),className:"peer sr-only"}),e.jsx("div",{className:"w-10 h-6 bg-[var(--bg-card-alt)] rounded-full peer-checked:bg-[var(--accent)] transition-colors"}),e.jsx("div",{className:"absolute left-1 top-1 w-4 h-4 bg-white rounded-full transition-transform peer-checked:translate-x-4"})]}),e.jsx("span",{className:`text-sm font-medium transition-colors ${p?"text-[var(--text-primary)]":"text-[var(--text-secondary)] group-hover:text-[var(--text-primary)]"}`,children:"é±èå·²éæ"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 w-full md:w-auto justify-end",children:[b.create&&e.jsxs("button",{onClick:()=>g(!0),className:"flex items-center gap-2 px-4 py-2 bg-[var(--bg-card-alt)] hover:bg-[var(--bg-card-alt)] text-[var(--text-primary)] rounded-xl transition-all border border-[var(--border)] hover:border-[var(--border-hover)] font-medium active:scale-95 text-sm",children:[e.jsx(_,{size:16}),e.jsx("span",{children:"å¯å
¥"})]}),e.jsxs("button",{onClick:Q,className:"flex items-center gap-2 px-4 py-2 bg-[var(--bg-card-alt)] hover:bg-[var(--bg-card-alt)] text-[var(--text-primary)] rounded-xl transition-all border border-[var(--border)] hover:border-[var(--border-hover)] font-medium active:scale-95 text-sm",children:[e.jsx(oe,{size:16}),e.jsx("span",{children:"å¯åº"})]}),b.create&&e.jsxs("button",{onClick:()=>F(),className:"flex items-center gap-2 px-5 py-2 bg-[var(--accent)] hover:bg-[var(--accent-hover)] text-[var(--button-text)] rounded-xl transition-all shadow-lg shadow-blue-500/25 font-bold active:scale-95 text-sm",children:[e.jsx(de,{size:16}),e.jsx("span",{children:"æ°å¢"})]})]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-[var(--bg-card)] rounded-3xl border border-[var(--border)] shadow-2xl relative",children:q?e.jsx(ve,{rows:6,cols:6}):k.length===0?e.jsx(ce,{icon:U,title:e.jsx(e.Fragment,{children:"æ¾ä¸å°ç¸éè³æ"}),className:"h-64"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left border-collapse min-w-[700px]",children:[e.jsx("thead",{className:"sticky top-0 z-10 bg-[var(--bg-card-alt)] shadow-md",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-4 px-6 text-left text-sm font-bold text-[var(--text-primary)] border-b border-[var(--border)] w-1/5",children:"å§å"}),e.jsx("th",{className:"py-4 px-6 text-center text-sm font-bold text-[var(--text-primary)] border-b border-[var(--border)] w-1/5",children:"身åèåè"}),e.jsx("th",{className:"py-4 px-6 text-center text-sm font-bold text-[var(--text-primary)] border-b border-[var(--border)] w-1/5",children:"çææä»½"}),e.jsx("th",{className:"py-4 px-6 text-center text-sm font-bold text-[var(--text-primary)] border-b border-[var(--border)] w-1/5",children:"失ææä»½"}),e.jsx("th",{className:"py-4 px-6 text-center text-sm font-bold text-[var(--text-primary)] border-b border-[var(--border)] w-1/10",children:"çæ
"}),e.jsx("th",{className:"py-4 px-6 text-center text-sm font-bold text-[var(--text-primary)] border-b border-[var(--border)] w-1/10",children:"æä½"})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border)] nk-list nk-zebra",children:k.map(t=>{const r=D(t);return e.jsxs("tr",{className:`transition-all duration-200 group border-b border-[var(--border)] last:border-0 ${r?"bg-[var(--bg-card)] text-[var(--text-secondary)] hover:bg-[var(--bg-card)]":"hover:bg-[var(--bg-card-alt)] text-[var(--text-primary)]"}`,children:[e.jsx("td",{className:"py-3 px-6 font-bold text-base",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center text-xs font-bold transition-colors ${r?"bg-[var(--bg-card-alt)] text-[var(--text-muted)]":"bg-[var(--accent)]/20 text-[var(--accent)]"}`,children:t.name.charAt(0)}),t.name]})}),e.jsx("td",{className:"py-3 px-6 text-center font-mono font-medium tracking-wide",children:t.idNumber||e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})}),e.jsx("td",{className:"py-3 px-6 text-center font-mono",children:t.effectiveDate}),e.jsx("td",{className:"py-3 px-6 text-center font-mono",children:t.expiryDate||e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})}),e.jsx("td",{className:"py-3 px-6 text-center",children:e.jsx("div",{className:"flex justify-center",children:r?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1 rounded-md text-xs font-medium bg-[var(--bg-card-alt)] text-[var(--text-muted)] border border-[var(--border)] select-none",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[var(--text-muted)]"}),"已失æ"]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold bg-[var(--success)]/10 text-[var(--success)] border border-[var(--success)]/20 shadow-[0_0_10px_rgba(16,185,129,0.15)] select-none",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-[var(--success)] opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-[var(--success)]"})]}),"ææ"]})})}),e.jsx("td",{className:"py-3 px-6 text-center",children:e.jsxs("div",{className:"flex justify-center gap-2",children:[b.edit&&e.jsx("button",{onClick:()=>
3F(t),className:"p-1.5 text-[var(--accent)] hover:bg-[var(--accent)]/10 hover:text-[var(--accent)] rounded-lg transition-colors",children:e.jsx(xe,{size:16})}),b.delete&&e.jsx("button",{onClick:()=>G(t.id),className:"p-1.5 text-[var(--error)] hover:bg-[var(--error)]/10 hover:text-[var(--error)] rounded-lg transition-colors",children:e.jsx(ie,{size:16})})]})})]},t.id)})})]})})}),e.jsxs(E,{isOpen:V,onClose:()=>g(!1),maxWidth:"max-w-md",contentClassName:"bg-[var(--bg-card)] border border-[var(--border)] w-full rounded-2xl shadow-2xl p-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("h3",{className:"text-xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(me,{className:"text-[var(--success)]"}),"å¯å
¥è³æ"]}),e.jsx("button",{onClick:()=>g(!1),className:"text-[var(--text-secondary)] hover:text-[var(--text-primary)] z-20 relative",children:e.jsx(L,{size:24})})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"relative p-4 bg-[var(--bg-card-alt)] rounded-xl border border-[var(--border)] border-dashed flex flex-col items-center justify-center text-center gap-2 min-h-[150px]",children:[e.jsx(_,{size:32,className:"text-[var(--text-muted)] mb-2"}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)] font-medium",children:"é»ææææ³æªæ¡è³æ¤"}),e.jsx("p",{className:"text-xs text-[var(--text-muted)]",children:"æ¯æ´ .xlsx, .csv æ ¼å¼"}),e.jsx("input",{"aria-label":"鏿è¦å¯å
¥çå¥ä¿è³ææªæ¡",ref:w,type:"file",accept:".xlsx, .xls, .csv",onChange:K,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"})]}),e.jsx("div",{className:"bg-[var(--accent)]/10 p-3 rounded-lg border border-[var(--accent)]/20",children:e.jsxs("p",{className:"text-xs text-[var(--accent)] leading-relaxed",children:[e.jsx("span",{className:"font-bold block mb-1",children:"ð¡ Excel æ ¼å¼è¦æ±ï¼"}),"第ä¸åæ¨é¡éå
å«ï¼",e.jsx("br",{}),e.jsx("code",{className:"bg-black/30 px-1 py-0.5 rounded text-[var(--accent)]",children:"å§å"}),"ã",e.jsx("code",{className:"bg-black/30 px-1 py-0.5 rounded text-[var(--accent)]",children:"身åèåè"}),"ã",e.jsx("br",{}),e.jsx("code",{className:"bg-black/30 px-1 py-0.5 rounded text-[var(--accent)]",children:"çææä»½"}),"ã",e.jsx("code",{className:"bg-black/30 px-1 py-0.5 rounded text-[var(--accent)]",children:"失ææä»½"})]})})]})]}),e.jsxs(E,{isOpen:W,onClose:()=>m(!1),maxWidth:"max-w-md",contentClassName:"bg-[var(--bg-card)] border border-[var(--border)] w-full rounded-2xl shadow-2xl p-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)]",children:u?"編輯å¥ä¿ç´é":"æ°å¢å¥ä¿ç´é"}),e.jsx("button",{onClick:()=>m(!1),className:"text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:e.jsx(L,{size:24})})]}),e.jsxs("form",{onSubmit:X,className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("label",{htmlFor:`${n}-0`,className:"text-sm text-[var(--text-secondary)]",children:["å§å ",e.jsx("span",{className:"text-[var(--error)]",children:"*"})]}),e.jsx("input",{id:`${n}-0`,required:!0,type:"text",value:s.name,onChange:t=>i({...s,name:t.target.value}),className:"bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] rounded-xl p-3 focus:border-[var(--accent)] outline-none"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:`${n}-1`,className:"text-sm text-[var(--text-secondary)]",children:"身åèåè"}),e.jsx("input",{id:`${n}-1`,type:"text",value:s.idNumber,onChange:t=>i({...s,idNumber:t.target.value.toUpperCase()}),className:"bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] rounded-xl p-3 focus:border-[var(--accent)] outline-none uppercase font-mono",placeholder:"é¸å¡«"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("label",{htmlFor:`${n}-2`,className:"text-sm text-[var(--text-secondary)]",children:["çææä»½ ",e.jsx("span",{className:"text-[var(--error)]",children:"*"})]}),e.jsx("input",{id:`${n}-2`,required:!0,type:"date",value:s.effectiveDate,onChange:t=>i({...s,effectiveDate:t.target.value}),className:"bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] rounded-xl p-3 focus:border-[var(--accent)] outline-none"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:`${n}-3`,className:"text-sm text-[var(--text-secondary)]",children:"失ææä»½ (é¸å¡«)"}),e.jsx("input",{id:`${n}-3`,type:"date",value:s.expiryDate||"",onChange:t=>i({...s,expiryDate:t.target.value||null}),className:"bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] rounded-xl p-3 focus:border-[var(--accent)] outline-none"}),e.jsx("p",{className:"text-xs text-[var(--text-muted)]",children:"è¥ç空åä»£è¡¨é·æææ"})]}),e.jsxs("div",{className:"flex gap-3 mt-4",children:[e.jsx("button",{type:"button",onClick:()=>m(!1),className:"flex-1 py-2.5 rounded-xl bg-[var(--bg-card-alt)] text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)]",children:"åæ¶"}),e.jsx("button",{type:"submit",className:"flex-1 py-2.5 rounded-xl bg-[var(--accent)] text-[var(--button-text)] hover:bg-[var(--accent-hover)] font-bold shadow-lg shadow-blue-500/20",children:"å²å"})]})]})]}),e.jsx(E,{isOpen:h.isOpen,onClose:()=>f({isOpen:!1,recordId:null}),zIndex:60,maxWidth:"max-w-sm",contentClassName:"bg-[var(--bg-card)] border border-[var(--error)]/50 w-full rounded-2xl shadow-2xl p-6",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-[var(--error)]/10 flex items-center justify-center mb-2",children:e.jsx(be,{size:32,className:"text-[var(--error)]"})}),e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)]",children:"確èªåªé¤"}),e.jsxs("div",{className:"flex gap-3 w-full mt-4",children:[e.jsx("button",{onClick:()=>f({isOpen:!1,recordId:null}),className:"flex-1 py-2.5 rounded-xl bg-[var(--bg-card-alt)] text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)]",children:"åæ¶"}),e.jsx("button",{onClick:J,className:"flex-1 py-2.5 rounded-xl bg-[var(--error)] text-[var(--button-text)] hover:bg-[var(--error)] shadow-lg shadow-red-900/20",children:"確èªåªé¤"})]})]})})]})};export{Se as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.