PageSourceSearch

https://zonovai.vercel.app/assets/MedicalStaff-C4W20bDH.js

js zonovai.vercel.app collected 2026-10-03 08:05:41 UTC 33,878 bytes, 1 lines download raw bytes

1import{i as e}from"./rolldown-runtime-jxEyR9vv.js";import{v as t}from"./charts-BqcS3ABW.js";import{t as a}from"./react-aNZyGp20.js";import{$n as s,Dt as r,E as l,Jn as i,Pn as n,St as o,Yn as d,i as c,it as m}from"./icons-B3484nFG.js";import{Or as u}from"./index-CpvLNjQu.js";import{t as p}from"./alert-C8dtXGVU.js";import{n as x,t as h}from"./SortControl-DvpZhW60.js";import{g as f}from"./listPages-C6_iiYvC.js";import{a as g,n as b,o as y,r as j,t as v}from"./staff.api-ycfErPlW.js";import{a as w,r as N}from"./staffType.api-CYHoI85e.js";var S=e(t(),1),_=a(),C=[{code:"doctor",label:"Doctor"},{code:"nurse",label:"Nurse"},{code:"lab_technician",label:"Lab Technician"},{code:"pharmacist",label:"Pharmacist"},{code:"pharmacy_admin",label:"Pharmacy Admin"},{code:"front_office_person",label:"Front Office Person"},{code:"dietitian",label:"Dietitian"},{code:"admin",label:"Admin"},{code:"store",label:"Store"},{code:"tpa",label:"TPA"},{code:"accountant",label:"Accountant"},{code:"call_centre",label:"Call Centre"},{code:"ot_incharge",label:"OT Incharge"}];function A({search:e,setSearch:t,onAdd:a,onExport:r,filters:l,onFiltersChange:i,staffTypes:d=[],sort:c,onSortChange:u,sortableFields:p}){const x=Array.isArray(d)&&d.length>0?d.map(e=>({code:e.code,label:e.label})):C,[f,g]=(0,S.useState)(!1),[b,y]=(0,S.useState)({staffType:"",department:"",nameOrId:"",mobile:"",email:""}),j=(0,S.useMemo)(()=>"function"==typeof i,[i]),v=(e,t)=>{y(a=>({...a,[e]:t}))};(0,S.useEffect)(()=>{f&&y({staffType:l?.staffType??"",department:l?.department??"",nameOrId:l?.nameOrId??"",mobile:l?.mobile??"",email:l?.email??""})},[f,l]);return(0,_.jsxs)("div",{className:"block gap-3 lg:flex items-center justify-between px-4 py-3 bg-white rounded-xl border border-gray-100",children:[(0,_.jsxs)("div",{className:"block md:flex items-center gap-2",children:[(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsxs)("button",{type:"button",onClick:()=>g(e=>!e),className:"flex items-center gap-2 px-5 py-2 bg-gray-100 text-gray-700 rounded-lg text-base font-medium hover:bg-gray-200 transition-colors border border-transparent h-12 w-full lg:w-auto",children:[(0,_.jsx)(n,{size:18})," Filters"]}),f&&(0,_.jsx)("div",{className:"absolute left-0 mt-2 w-90 bg-white border border-gray-200 rounded-xl shadow-lg p-4 z-20",children:(0,_.jsxs)("div",{className:"grid grid-cols-1 gap-3",children:[(0,_.jsxs)("div",{children:[(0,_.jsx)("label",{className:"text-sm text-gray-600",children:"Staff Type"}),(0,_.jsxs)("select",{value:b.staffType,onChange:e=>v("staffType",e.target.value),className:"mt-1 w-full h-11 px-3 border border-gray-200 rounded-lg bg-white text-gray-700",children:[(0,_.jsx)("option",{value:"",children:"All"}),x.map(e=>(0,_.jsx)("option",{value:e.code,children:e.label},e.code))]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("label",{className:"text-sm text-gray-600",children:"Department"}),(0,_.jsx)("input",{value:b.department,onChange:e=>v("department",e.target.value),placeholder:"Search department",className:"mt-1 w-full h-11 px-3 border border-gray-200 rounded-lg"})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("label",{className:"text-sm text-gray-600",children:"Name / ID"}),(0,_.jsx)("input",{value:b.nameOrId,onChange:e=>v("nameOrId",e.target.value),placeholder:"Search name or ID",className:"mt-1 w-full h-11 px-3 border border-gray-200 rounded-lg"})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("label",{className:"text-sm text-gray-600",children:"Mobile no."}),(0,_.jsx)("input",{value:b.mobile,onChange:e=>v("mobile",e.target.value),placeholder:"Search mobile",className:"mt-1 w-full h-11 px-3 border border-gray-200 rounded-lg"})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("label",{className:"text-sm text-gray-600",children:"Email"}),(0,_.jsx)("input",{value:b.email,onChange:e=>v("email",e.target.value),placeholder:"Search email",className:"mt-1 w-full h-11 px-3 border border-gray-200 rounded-lg"})]}),(0,_.jsxs)("div",{className:"mt-1 grid grid-cols-2 gap-3",children:[(0,_.jsx)("button",{type:"button",onClick:()=>{const e={staffType:"",department:"",nameOrId:"",mobile:"",email:""};y(e),j&&i(e)},className:"h-11 border border-[#347BD7] text-[#347BD7] bg-white rounded-lg text-base font-medium hover:bg-blue-50 transition-colors",children:"Clear"}),(0,_.jsx)("button",{type:"button",onClick:()=>{j&&(i({...b}),g(!1))},className:"h-11 bg-[#347BD7] text-white rounded-lg text-base font-medium hover:bg-[#2a5ea8] transition-colors",children:"Apply"})]})]})})]}),(0,_.jsxs)("button",{type:"button",onClick:r,className:"toolbar-btn flex items-center gap-2 px-5 py-2 bg-gray-100 text-gray-700 rounded-lg text-base font-medium hover:bg-gray-200 transition-colors border border-transparent h-12 mt-3 md:mt-0 w-full lg:w-auto",children:[(0,_.jsx)(s,{size:14}),"Export"]})]}),(0,_.jsxs)("div",{className:"block md:flex items-center gap-3 mt-3 lg:mt-0",children:[(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsx)(m,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}
1),(0,_.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:"Search",className:"search-btn"})]}),(0,_.jsx)(h,{sortableFields:p,sort:c,onSortChange:u,className:"mt-3 md:mt-0"}),(0,_.jsxs)("button",{onClick:a,className:"flex items-center gap-2 px-6 py-3 bg-[#347BD7] text-white rounded-lg text-base font-medium shadow hover:bg-[#2a5ea8] transition-colors duration-150 mt-3 md:mt-0 w-full lg:w-auto",children:[(0,_.jsx)(o,{size:14}),"Add New Staff"]})]})]})}function P({staff:e,onDelete:t,onEdit:a}){const s=(e,t=10)=>{const a=String(e??"").trim();return a&&"—"!==a?a.length>t?`${a.slice(0,t)}...`:a:"—"},i=e?.staff_name??"—",n=e?.staff_type_display||e?.staff_type||"—",o=e?.phone??"—",d=e?.email??"—",c=e?.department_name||"—",m=e?.specialization||"—",u=e?.license_number||"—",p=Boolean(e?.is_active);return(0,_.jsxs)("div",{className:"grid grid-cols-[1.4fr_1.2fr_1.2fr_1.2fr_1.2fr_1.2fr_1.2fr_1.2fr_0.8fr] px-6 py-4 text-sm text-gray-700 bg-white rounded-xl mb-2 shadow-sm hover:shadow-md transition-all border border-gray-100 items-center",children:[(0,_.jsx)("div",{children:i}),(0,_.jsx)("div",{title:"—"!==n?String(n):void 0,children:s(n,10)}),(0,_.jsx)("div",{children:o}),(0,_.jsx)("div",{className:"truncate",title:"—"!==d?String(d):void 0,children:s(d,10)}),(0,_.jsx)("div",{children:c}),(0,_.jsx)("div",{title:"—"!==m?String(m):void 0,children:s(m,10)}),(0,_.jsx)("div",{children:u}),(0,_.jsx)("span",{className:"px-3 py-1 rounded-full text-xs font-medium border w-fit "+(p?"bg-green-50 text-green-600 border-green-200":"bg-red-50 text-red-600 border-red-200"),children:p?"Active":"Inactive"}),(0,_.jsxs)("div",{className:"flex gap-2 justify-center",children:[(0,_.jsx)("button",{onClick:()=>a&&a(e),className:"p-2 rounded-lg bg-gray-50 hover:bg-blue-50 text-gray-500 hover:text-[#347BD7] transition border border-gray-200",title:"Edit",children:(0,_.jsx)(r,{size:16,className:"cursor-pointer"})}),(0,_.jsx)("button",{onClick:()=>t&&t(e.id),className:"p-2 rounded-lg bg-gray-50 hover:bg-red-50 text-gray-400 hover:text-red-600 transition border border-gray-200",title:"Delete",children:(0,_.jsx)(l,{size:16})})]})]})}function k({data:e,onDelete:t,onEdit:a,hospitalId:s}){const[r,l]=(0,S.useState)([]),[i,n]=(0,S.useState)(!1),[o,d]=(0,S.useState)(""),c=(0,S.useMemo)(()=>String(s||localStorage.getItem("hospitalId")||"1"),[s]);(0,S.useEffect)(()=>{if(void 0!==e)return;let t=!1;return(async()=>{n(!0),d("");try{const e=await j(c),a=Array.isArray(e)?e:e?.results||[];t||l(a)}catch(e){t||(l([]),d(e?.response?.data?.detail||e?.message||"Failed to load staff"))}finally{t||n(!1)}})(),()=>{t=!0}},[e,c]);const m=void 0!==e?Array.isArray(e)?e:[]:r;return(0,_.jsxs)("div",{className:"bg-white rounded-xl overflow-x-auto min-w-6xl",children:[(0,_.jsxs)("div",{className:"grid grid-cols-[1.4fr_1.2fr_1.2fr_1.2fr_1.2fr_1.2fr_1.2fr_1.2fr_0.8fr]\n        px-6 py-3 bg-blue-50 text-xs font-medium text-gray-600 mb-4 rounded-2xl ",children:[(0,_.jsx)("div",{children:"Staff Name"}),(0,_.jsx)("div",{children:"Type"}),(0,_.jsx)("div",{children:"Phone No."}),(0,_.jsx)("div",{children:"Email"}),(0,_.jsx)("div",{children:"Department"}),(0,_.jsx)("div",{children:"Specialization"}),(0,_.jsx)("div",{children:"License No."}),(0,_.jsx)("div",{children:"Status"}),(0,_.jsx)("div",{children:"Action"})]}),i&&0===m.length&&(0,_.jsx)("div",{className:"px-6 py-8 text-sm text-gray-500",children:"Loading staff..."}),!i&&o&&(0,_.jsx)("div",{className:"px-6 py-3 text-sm text-red-600",children:o}),!i&&!o&&0===m.length&&(0,_.jsx)("div",{className:"px-6 py-8 text-sm text-gray-500",children:"No staff found."}),m.map(e=>(0,_.jsx)(P,{staff:e,onDelete:t,onEdit:a},e.id))]})}function D({page:e,setPage:t,totalPages:a,total:s=0,pageSize:r=10,onPageSizeChange:l,onPageChange:i,pageSizeOptions:n=[5,10,20,50,100]}){const o=Number.isFinite(s)?Math.max(0,s):0,d=Number.isFinite(r)&&r>0?r:10,c=Math.max(1,Math.ceil(o/d)),m=Number.isFinite(a)&&a>0?a:c,u=Number.isFinite(e)&&e>0?Math.min(e,m):1,p=0===o?0:(u-1)*d+1,x=Math.min(o,u*d),h=e=>{const a=Math.max(1,Math.min(m,e));"function"==typeof t&&t(a),"function"==typeof i&&i(a)};const f=function(){const e=m,t=u;if(e<=7)return Array.from({length:e},(e,t)=>t+1);const a=[],s=t>3,r=t<e-2;a.push(1),s&&a.push("...");const l=s?Math.max(2,t-1):2,i=r?Math.min(e-1,t+1):e-1;for(let n=l;n<=i;n++)a.includes(n)||a.push(n);return r&&e>1&&a.push("..."),e>1&&a.push(e),a}(),g=u>1,b=u>1,y=u<m,j=u<m,v="inline-flex items-center justify-center min-w-10 h-10 rounded-lg border transition-colors disabled:opacity-50 disabled:cursor-not-allowed",w="bg-white text-gray-900 border-gray-300 hover:bg-gray-50";return(0,_.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4 px-6 py-4 text-sm text-gray-500 bg-gray-100 rounded-b-2xl border border-gray-200",children:[(0,_.jsxs)("div",{className:"flex items-center gap-3 flex-wrap",children:[(0,_.jsxs)("span",{className:"text-gray-600",children:["Showing ",p,"–",x," of ",o," records"]}),"function"==typeof l&&(0,_.jsxs)("div",{className:"flex items-center gap-2",children:[(0,_.jsx)("span",{className:"text-gray-500",children:"Per page"}),(0,_.jsx)("select",{value:String(d),onChange:e=>{const t=parseInt(e.target.value,10);!Number.isFinite(t)||t<=0||(l(t),h(1))},className:"border border-gray-300 rounded-lg px-2 py-1.5 bg-white text-gray-800",children:n.map(e=>(0,_.jsx)("option",{value:String(e),children:e},e))})]})]}),(0,_.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,_.jsx)("button",{type:"button","aria-label":"First page",disabled:!g,onClick:()=>h(1),className:`${v} ${w} px-2`,children:"«"}),(0,_.jsx)("button",{type:"button","aria-label":"Previous page",disabled:!b,onClick:()=>h(u-1),className:`${v} ${w} px-2`,children:"‹"}),(0,_.jsx)("div",{className:"flex items-center gap-1.5 mx-1",children:f.map((e,t)=>"..."===e?(0,_.jsx)("span",{className:"inline-flex items-center justify-center min-w-10 h-10 rounded-lg bg-white text-gray-700 border border-gray-300",children:"..."},`ellipsis-${t}`):(0,_.jsx)("button",{type:"button",onClick:()=>h(e),className:`${v} ${u===e?"bg-[#347BD7] text-white border-[#347BD7]":w}`,children:e},e))}),(0,_.jsx)("button",{type:"button","aria-label":"Next page",disabled:!y,onClick:()=>h(u+1),className:`${v} ${w} px-2`,children:"›"}),(0,_.jsx)("button",{type:"button","aria-label":"Last page",disabled:!j,onClick:()=>h(m),className:`${v} ${w} px-2`,children:"»"})]})]})}var E=/^[a-zA-Z\s]{2,50}$/,z=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,L=/^[A-Za-z0-9\-\/\.]{2,50}$/,T=[{code:"doctor",label:"Doctor"},{code:"nurse",label:"Nurse"},{code:"lab_technician",label:"Lab Technician"},{code:"pharmacist",label:"Pharmacist"},{code:"pharmacy_admin",label:"Pharmacy Admin"},{code:"front_office_person",label:"Front Office Person"},{code:"dietitian",label:"Dietitian"},{code:"admin",label:"Admin"},{code:"store",label:"Store"},{code:"tpa",label:"TPA"},{code:"accountant",label:"Accountant"},{code:"call_centre",label:"Call Centre"},{code:"ot_incharge",label:"OT Incharge"}];function $({onClose:e,onCreate:t,initialData:a=null,onUpdate:s,existingStaff:r=[],onPasswordChange:l,departments:n=[],staffTypes:o=[]}){const[c,m]=(0,S.useState)({}),[u,x]=(0,S.useState)(a?.staff_type||""),[h,f]=(0,S.useState)(!1),[g,b]=(0,S.useState)(""),[y,j]=(0,S.useState)(""),[v,w]=(0,S.useState)(!1),[N,C]=(0,S.useState)(!1),[A,P]=(0,S.useState)(!1),[k,D]=(0,S.useState)(""),[$,F]=(0,S.useState)(!1);(0,S.useEffect)(()=>{x(a?.staff_type||"")},[a?.staff_type]);const O="doctor"===String(u||"").toLowerCase(),B="nurse"===String(u||"").toLowerCase(),M=O||B,q=[...Array.isArray(o)&&o.length>0?o.map(e=>({code:e.code,label:e.label})):T],V=a?.staff_type;V&&!q.some(e=>e.code===V)&&q.push({code:V,label:a?.staff_type_display||V});const U=e=>"w-full px-4 py-2 rounded-lg bg-white text-sm outline-none transition\n     "+(c[e]?"border border-red-500 focus:ring-2 focus:ring-red-500":"border border-gray-200 focus:ring-2 focus:ring-blue-500"),H=e=>{const t=(e=>{const t=String(e||"").trim();return t?t.length<6?"Password must be at least 6 characters":/\d/.test(t)?"":"Password must contain at least 1 digit":"Password is required"})(e);return m(e=>{const a={...e};return t?a.password=t:delete a.password,a}),t},R=e=>({name:e.get("name"),staffType:e.get("type"),department:e.get("department"),phone:e.get("phone"),email:e.get("email"),password:e.get("password"),status:e.get("status"),specialization:e.get("specialization"),license:e.get("license"),doctorPrice:e.get("doctorPrice"),signature:e.get("signature")}),Z=()=>{D(""),b(""),j(""),C(!1),P(!1),f(!1)};return(0,_.jsx)("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50",children:(0,_.jsxs)("div",{className:"bg-white w-full max-w-4xl rounded-2xl shadow-xl border border-gray-100",children:[(0,_.jsx)("div",{className:"px-8 py-6",children:(0,_.jsx)("h2",{className:"text-xl font-semibold text-[#347BD7]",children:a?"Edit Staff":"Add New Staff"})}),(0,_.jsxs)("form",{onSubmit:async e=>{e.preventDefault();const l=R(new FormData(e.target)),i=Boolean(a&&s);if(!i&&H(l.password))return;const n=(l.email||"").trim().toLowerCase(),o=(a?.email||"").trim().toLowerCase();if(n&&(Array.isArray(r)?r:[]).some(e=>{const t=(e?.email||"").trim().toLowerCase();return!!t&&((!o||t!==o)&&t===n)}))return void m(e=>({...e,email:"Email already exists. Add new email."}));const d=(e=>{const t={};if(E.test(e.name)||(t.name="Enter valid staff name"),e.staffType||(t.staffType="Staff type is required"),10!==(e.phone??"").toString().replace(/\D/g,"").length&&(t.phone="Enter valid 10-digit phone number"),z.test(e.email)||(t.email="Invalid email address"),"string"==typeof e.password&&e.password.trim().length>0){const a=e.password.trim();a.length<6?t.password="Password must be at least 6 characters":/\d/.test(a)||(t.password="Password must contain at least 1 digit")}return e.status||(t.status="Status is required"),e.license&&!L.test(e.license)&&(t.license="Invalid license number"),t})(l);if(Object.keys(d).length>0)return void m(d);m({});const c=String(l.password||"").trim(),u=l.status||"Active",p=(l.department||"").trim(),x={staff_name:l.name,staff_type:{Doctor:"doctor",Nurse:"nurse","Lab Technician":"lab_technician",Pharmacist:"pharmacist","Pharmacy Admin":"pharmacy_admin","Front Office Person":"front_office_person",Dietitian:"dietitian",Admin:"admin",Store:"store",TPA:"tpa",Accountant:"accountant","Call Centre":"call_centre","OT Incharge":"ot_incharge",doctor:"doctor",nurse:"nurse",lab_technician:"lab_technician",pharmacist:"pharmacist",pharmacy_admin:"pharmacy_admin",front_office_person:"front_office_person",dietitian:"dietitian",admin:"admin",store:"store",tpa:"tpa",accountant:"accountant",call_centre:"call_centre",ot_incharge:"ot_incharge"}[l.staffType]||l.staffType||"doctor",phone:l.phone,email:l.email,department:p||null,specialization:l.specialization,license_number:l.license,is_active:"Active"===u}
1,h=String(x.staff_type||"").toLowerCase(),f=String(l.doctorPrice??"").trim();"doctor"===h&&f&&(x.consulting_fee=f),("doctor"===h||"nurse"===h)&&l.signature instanceof File&&l.signature.size>0&&(x.signature=l.signature),i||(x.password=c);try{a&&s?await s({...x,id:a.id}):t&&await t(x)}catch(g){if((e=>{const t=e?.response?.data,a=[];"string"==typeof t&&a.push(t),t?.detail&&a.push(String(t.detail)),t?.message&&a.push(String(t.message)),t?.email&&(Array.isArray(t.email)?a.push(t.email.join(" ")):a.push(String(t.email)));const s=a.join(" ").toLowerCase();return s.includes("email")&&(s.includes("already")||s.includes("exists")||s.includes("unique"))})(g))return void m(e=>({...e,email:"Email already exists. Add new email."}));throw g}},className:"px-8 py-8 rounded-b-2xl",children:[(0,_.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-x-6 gap-y-6",children:[(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsxs)("label",{className:"block text-sm text-gray-500 mb-1",children:["Staff Name ",(0,_.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,_.jsx)("input",{name:"name",required:!0,defaultValue:a?.staff_name||"",placeholder:"Enter Staff Name",className:U("name")}),(0,_.jsx)(I,{error:c.name})]}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsxs)("label",{className:"block text-sm text-gray-500 mb-1",children:["Staff Type ",(0,_.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,_.jsxs)("select",{name:"type",defaultValue:a?.staff_type||"",className:U("staffType"),required:!0,onChange:e=>{const t=e.target.value;x(t),"doctor"!==String(t||"").toLowerCase()&&m(e=>{if(!e?.doctorPrice)return e;const t={...e};return delete t.doctorPrice,t})},children:[(0,_.jsx)("option",{value:"",children:"Enter Staff Type"}),q.map(e=>(0,_.jsx)("option",{value:e.code,children:e.label},e.code))]}),(0,_.jsx)(I,{error:c.staffType})]}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsx)("label",{className:"block text-sm text-gray-500 mb-1",children:"Department"}),n.length>0?(0,_.jsxs)("select",{name:"department",defaultValue:null!=a?.department_id?String(a.department_id):null==a?.department||isNaN(Number(a.department))?"":String(a.department),className:U("department"),children:[(0,_.jsx)("option",{value:"",children:"Select Department"}),n.map(e=>(0,_.jsx)("option",{value:String(e.id),children:e.name},e.id))]}):(0,_.jsx)("input",{name:"department",defaultValue:a?.department_name||("string"==typeof a?.department?a.department:""),placeholder:"Enter Department (ID or name)",className:U("department")}),(0,_.jsx)(I,{error:c.department})]}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsxs)("label",{className:"block text-sm text-gray-500 mb-1",children:["Phone no. ",(0,_.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,_.jsx)("input",{name:"phone",type:"tel",inputMode:"numeric",autoComplete:"tel",maxLength:10,defaultValue:a?.phone||"",placeholder:"Enter 10-digit phone no.",className:U("phone"),required:!0,onInput:e=>{const t=e.target.value.replace(/\D/g,"").slice(0,10);e.target.value=t}}),(0,_.jsx)(I,{error:c.phone})]}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsxs)("label",{className:"block text-sm text-gray-500 mb-1",children:["Email ",(0,_.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,_.jsx)("input",{name:"email",required:!0,defaultValue:a?.email||"",placeholder:"Enter Email",className:U("email"),onChange:e=>{const t=(e.target.value||"").trim().toLowerCase(),s=(a?.email||"").trim().toLowerCase();t?(Array.isArray(r)?r:[]).some(e=>{const a=(e?.email||"").trim().toLowerCase();return!!a&&((!s||a!==s)&&a===t)})?"Email already exists. Add new email."!==c.email&&m(e=>({...e,email:"Email already exists. Add new email."})):"Email already exists. Add new email."===c.email&&m(e=>{const t={...e};return delete t.email,t}):c.email&&m(e=>{const t={...e};return delete t.email,t})}}),(0,_.jsx)(I,{error:c.email})]}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsx)("label",{className:"block text-sm text-gray-500 mb-1",children:a?"Password":(0,_.jsxs)(_.Fragment,{children:["Password ",(0,_.jsx)("span",{className:"text-red-500",children:"*"})]})}),a?(0,_.jsx)("button",{type:"button",onClick:()=>{D(""),b(""),j(""),C(!1),P(!1),f(!0)},className:"text-sm font-medium text-[#347BD7] hover:text-[#347BD7]",children:"Change Password"}):(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsx)("input",{type:v?"text":"password",name:"password",required:!0,placeholder:"Enter Password",className:`${U("password")} pr-10`,onChange:e=>H(e.target.value),onBlur:e=>H(e.target.value)}),(0,_.jsx)("button",{type:"button",onClick:()=>w(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700","aria-label":v?"Hide password":"Show password",children:v?(0,_.jsx)(d,{size:18}):(0,_.jsx)(i,{size:18})})]}),(0,_.jsx)(I,{error:c.password})]}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsxs)("label",{className:"block text-sm text-gray-500 mb-1",children:["Status ",(0,_.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,_.jsxs)("select",{name:"status",defaultValue:a?.is_active?"Active":"",className:U("status"),required:!0,children:[(0,_.jsx)("option",{value:"",children:"Select Status"}),(0,_.jsx)("option",{children:"Active"}),(0,_.jsx)("option",{children:"Inactive"})]}),(0,_.jsx)(I,{error:c.status})]}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsx)("label",{className:"block text-sm text-gray-500 mb-1",children:"Specialization"}),(0,_.jsx)("input",{name:"specialization",defaultValue:a?.specialization||"",placeholder:"Enter Specialization",className:U("specialization")}),(0,_.jsx)(I,{error:c.specialization})]}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsx)("label",{className:"block text-sm text-gray-500 mb-1",children:"License No."}),(0,_.jsx)("input",{name:"license",defaultValue:a?.license_number||"",placeholder:"Enter License No.",className:U("license")})]}),(0,_.jsx)(I,{error:c.license}),O?(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsxs)("label",{htmlFor:"doctorPrice",className:"block text-sm text-gray-500 mb-1",children:["Consultation Fee ",(0,_.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,_.jsx)("input",{id:"doctorPrice",name:"doctorPrice",defaultValue:a?.consulting_fee??a?.consultation_fee??a?.doctor_price??a?.doctorPrice??"",placeholder:"Enter Consultation Fee",required:!0,className:U("doctorPrice")}),(0,_.jsx)(I,{error:c.doctorPrice})]}):null,M?(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsx)("label",{htmlFor:"signature",className:"block text-sm text-gray-500 mb-1",children:"Upload Signature"}),(0,_.jsx)("input",{id:"signature",name:"signature",type:"file",accept:"image/*",className:U("signature")})]}):null]}),(0,_.jsxs)("div",{className:"flex justify-end gap-4 mt-8",children:[(0,_.jsx)("button",{type:"button",onClick:e,className:"px-6 py-2 rounded-lg border border-blue-500 text-[#347BD7] font-medium hover:bg-blue-50",children:"Cancel"}),(0,_.jsx)("button",{type:"submit",className:"px-6 py-2 rounded-lg bg-[#347BD7] text-white font-medium hover:bg-blue-700",children:a?"Save Changes":"Create Staff"})]})]}),h?(0,_.jsx)("div",{className:"fixed inset-0 z-60 bg-black/40 flex items-center justify-center",children:(0,_.jsxs)("div",{className:"bg-white w-full max-w-md rounded-xl shadow-xl border border-gray-100",children:[(0,_.jsx)("div",{className:"px-6 py-4 border-b",children:(0,_.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Change Password"})}),(0,_.jsxs)("div",{className:"p-6 space-y-4",children:[(0,_.jsxs)("div",{children:[(0,_.jsx)("label",{className:"block text-sm text-gray-600 mb-1",children:"Admin Password"}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsx)("input",{type:N?"text":"password",value:g,onChange:e=>b(e.target.value),className:"w-full px-4 py-2 pr-10 rounded-lg bg-white border border-gray-200 text-sm outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Enter admin password"}),(0,_.jsx)("button",{type:"button",onClick:()=>C(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700","aria-label":N?"Hide admin password":"Show admin password",children:N?(0,_.jsx)(d,{size:18}):(0,_.jsx)(i,{size:18})})]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("label",{className:"block text-sm text-gray-600 mb-1",children:"Staff Password"}),(0,_.jsxs)("div",{className:"relative",children:[(0,_.jsx)("input",{type:A?"text":"password",value:y,onChange:e=>j(e.target.value),className:"w-full px-4 py-2 pr-10 rounded-lg bg-white border border-gray-200 text-sm outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Enter staff password"}),(0,_.jsx)("button",{type:"button",onClick:()=>P(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700","aria-label":A?"Hide staff password":"Show staff password",children:A?(0,_.jsx)(d,{size:18}):(0,_.jsx)(i,{size:18})})]})]}),k?(0,_.jsx)("p",{className:"text-sm text-red-600 font-medium",children:k}):null]}),(0,_.jsxs)("div",{className:"px-6 pb-6 flex justify-end gap-3",children:[(0,_.jsx)("button",{type:"button",onClick:Z,className:"px-5 py-2 rounded-lg bg-gray-100 text-gray-700 hover:bg-gray-200",children:"Cancel"}),(0,_.jsx)("button",{type:"button",onClick:async()=>{const e=String(g||"").trim(),t=String(y||"").trim();if(e&&t)if(t.length<6)D("Staff password must be at least 6 characters.");else if(/\d/.test(t))try{"function"==typeof l&&a?.id&&await l({id:a.id,admin_password:e,staff_password:t}),F(!0),Z(),p("Password updated successfully")}catch(s){D(s?.response?.data?.detail||s?.response?.data?.error||s?.message||"Failed to update password")}else D("Staff password must contain at least 1 digit.");else D("Please enter both admin password and staff password.")},className:"px-5 py-2 rounded-lg bg-[#347BD7] text-white hover:bg-blue-700",children:"Confirm"})]})]})}):null]})})}function I({error:e}){return e?(0,_.jsx)("p",{className:"text-xs text-red-600 font-medium absolute mt-1 ml-1",children:e}):null}function F({open:e,onClose:t,staff:a=[]}){const s=(0,S.useMemo)(()=>(Array.isArray(a)?a:[]).filter(e=>"doctor"===String(e?.staff_type??e?.staff_type_display??"").trim().toLowerCase().replace(/\s+/g,"_")).slice().sort((e,t)=>
1String(e?.staff_name||"").localeCompare(String(t?.staff_name||""))),[a]);return e?(0,_.jsx)("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50 p-4",role:"dialog","aria-modal":"true",children:(0,_.jsxs)("div",{className:"bg-white w-full max-w-7xl rounded-2xl shadow-xl border border-gray-100 overflow-hidden",children:[(0,_.jsxs)("div",{className:"px-6 py-4 border-b flex items-center justify-between",children:[(0,_.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Doctor Price"}),(0,_.jsx)("button",{type:"button",onClick:t,className:"p-2 rounded-lg hover:bg-gray-100 text-gray-600","aria-label":"Close",children:(0,_.jsx)(c,{size:18})})]}),(0,_.jsxs)("div",{className:"p-6",children:[0===s.length?(0,_.jsx)("div",{className:"text-sm text-gray-500",children:"No doctors found."}):(0,_.jsx)("div",{className:"overflow-x-auto",children:(0,_.jsxs)("table",{className:"w-full text-sm",children:[(0,_.jsx)("thead",{children:(0,_.jsxs)("tr",{className:"bg-blue-50 text-gray-700",children:[(0,_.jsx)("th",{className:"px-4 py-3 text-left font-medium",children:"Doctor Name"}),(0,_.jsx)("th",{className:"px-4 py-3 text-left font-medium",children:"Department"}),(0,_.jsx)("th",{className:"px-4 py-3 text-left font-medium",children:"Specialization"}),(0,_.jsx)("th",{className:"px-4 py-3 text-left font-medium",children:"License No."}),(0,_.jsx)("th",{className:"px-4 py-3 text-left font-medium",children:"Consultation Fee"})]})}),(0,_.jsx)("tbody",{className:"divide-y divide-gray-100",children:s.map(e=>{const t=e?.department_name||("string"==typeof e?.department?e.department:"")||"—",a=e?.consulting_fee??e?.consultation_fee??e?.doctor_price??e?.doctorPrice??"";return(0,_.jsxs)("tr",{children:[(0,_.jsx)("td",{className:"px-4 py-3",children:e?.staff_name||"—"}),(0,_.jsx)("td",{className:"px-4 py-3",children:t}),(0,_.jsx)("td",{className:"px-4 py-3",children:e?.specialization||"—"}),(0,_.jsx)("td",{className:"px-4 py-3",children:e?.license_number||"—"}),(0,_.jsx)("td",{className:"px-4 py-3",children:""!==a&&null!=a?String(a):"—"})]},e?.id??`${e?.staff_name}-${e?.license_number}`)})})]})}),(0,_.jsx)("div",{className:"mt-6 flex justify-end",children:(0,_.jsx)("button",{type:"button",onClick:t,className:"px-5 py-2 rounded-lg bg-gray-100 text-gray-700 hover:bg-gray-200",children:"Close"})})]})]})}):null}function O(){const[e,t]=(0,S.useState)([]),[a,s]=(0,S.useState)(0),[r,l]=(0,S.useState)([]),[i,n]=(0,S.useState)([]),[o,d]=(0,S.useState)(!1),[c,m]=(0,S.useState)(""),[h,j]=(0,S.useState)(""),[C,P]=(0,S.useState)(""),[E,z]=(0,S.useState)({staffType:"",department:"",nameOrId:"",mobile:"",email:""}),[L,T]=(0,S.useState)(1),[I,O]=(0,S.useState)(10),[B,M]=(0,S.useState)(!1),[q,V]=(0,S.useState)(null),[U,H]=(0,S.useState)(!1),R=(0,S.useRef)(0),Z=(0,S.useCallback)(async(e,a,r)=>{const l=++R.current;try{d(!0),m("");const i=await g({hospitalId:localStorage.getItem("hospitalId")||"1",page:e,pageSize:a,search:String(r??"").trim()});if(l!==R.current)return;const n=Array.isArray(i)?i:i?.results??[],o="number"==typeof i?.count?i.count:n.length;t(n),s(o)}catch(i){if(l!==R.current)return;const a=i?.response?.status,r=i?.response?.data?.detail||i?.response?.data?.message||i?.message||"Failed to load staff";if(404===a&&String(r).toLowerCase().includes("invalid page")&&e>1)return void T(1);t([]),s(0),m(a?`(${a}) ${r}`:String(r))}finally{if(l!==R.current)return;d(!1)}},[]);(0,S.useEffect)(()=>{const e=setTimeout(()=>{P(h),T(1)},300);return()=>clearTimeout(e)},[h]),(0,S.useEffect)(()=>{Z(L,I,C)},[L,I,C,Z]),(0,S.useEffect)(()=>{u(localStorage.getItem("hospitalId")||"1").then(e=>l(Array.isArray(e)?e:[])).catch(()=>l([]))},[]),(0,S.useEffect)(()=>{N().then(e=>n((Array.isArray(e)?e:[]).filter(e=>e.is_active))).catch(()=>n([]))},[]);const J=(0,S.useMemo)(()=>{const t=(h||"").trim().toLowerCase(),a=(E.staffType||"").trim().toLowerCase(),s=(E.department||"").trim().toLowerCase(),r=(E.nameOrId||"").trim().toLowerCase(),l=(E.mobile||"").trim().toLowerCase(),i=(E.email||"").trim().toLowerCase();return(Array.isArray(e)?e:[]).filter(e=>{const n=`${e.id??""}`.toLowerCase(),o=`${e.staff_name??e.name??""}`.toLowerCase(),d=`${e.staff_type??e.staff_type_display??""}`.toLowerCase(),c=`${e.department_name??("string"==typeof e.department?e.department:"")}`.toLowerCase(),m=`${e.phone??""}`.toLowerCase(),u=`${e.email??""}`.toLowerCase();return!(t&&!`${n} ${o} ${d} ${c} ${m} ${u}`.includes(t))&&(!(a&&!d.replace(/\s+/g,"_").includes(a))&&(!(s&&!c.includes(s))&&(!(r&&!`${n} ${o}`.includes(r))&&(!(l&&!m.includes(l))&&!(i&&!u.includes(i))))))})},[e,h,E]);(0,S.useEffect)(()=>{T(1)},[E.staffType,E.department,E.nameOrId,E.mobile,E.email,I]);const Y=Math.max(1,Math.ceil(a/I)),{sort:G,setSort:K,items:Q}=x(J,f);return(0,_.jsxs)("div",{className:"space-y-4",children:[(0,_.jsxs)("div",{className:"flex",children:[(0,_.jsxs)("div",{children:[(0,_.jsx)("h2",{className:"text-2xl font-semibold mb-1 text-[#347BD7]",children:"Staff Management"}),(0,_.jsx)("p",{className:"text-gray-500 mb-6",children:"Manage staff, view details, and perform actions."})]}),(0,_.jsx)("div",{className:"ml-auto",children:(0,_.jsx)("button",{type:"button",onClick:()=>H(!0),className:"flex items-center gap-2 px-6 py-3 bg-[#347BD7] text-white rounded-lg text-base font-medium shadow hover:bg-[#2a5ea8] transition-colors duration-150 mt-3 md:mt-0 w-full lg:w-auto",children:"Consultation Fee"})})]}),(0,_.jsxs)("div",{className:"bg-white p-4 rounded-xl shadow-sm border border-gray-100 space-y-4 overflow-auto overflow-y-auto h-100vh-minus-300",children:[(0,_.jsxs)("div",{className:"",children:[(0,_.jsx)(A,{search:h,setSearch:j,filters:E,onFiltersChange:z,staffTypes:i,onAdd:()=>{V(null),M(!0)},onExport:()=>(e=>{const t=Object.keys(e[0]).join(","),a=e.map(e=>
1Object.values(e).join(",")).join("\n"),s=new Blob([t+"\n"+a],{type:"text/csv"}),r=URL.createObjectURL(s),l=document.createElement("a");l.href=r,l.download="staff.csv",l.click()})(J),sort:G,onSortChange:K,sortableFields:f.sortableFields}),o&&(0,_.jsx)("div",{className:"px-2 text-sm text-gray-500",children:"Loading staff…"}),!o&&c&&(0,_.jsx)("div",{className:"px-2 text-sm text-red-600",children:c}),(0,_.jsx)(k,{data:Q,onDelete:async e=>{if(await w("Are you sure you want to delete this staff member?"))try{await b(e),await Z(L,I,C)}catch(t){p("Failed to delete staff. Please try again.")}},onEdit:e=>{V(e),M(!0)}}),(0,_.jsx)(D,{page:L,setPage:T,total:a,totalPages:Y,pageSize:I,onPageSizeChange:O})]}),B&&(0,_.jsx)($,{onClose:()=>{M(!1),V(null)},onCreate:async e=>{try{const t=localStorage.getItem("hospitalId")||"1";await v({...e,hospital:t}),await Z(L,I,C),M(!1)}catch(t){const e=t?.response?.data,a=(Array.isArray(e?.email)?e.email.join(" "):e?.email)||e?.detail||e?.message||"",s=String(a).toLowerCase();throw s.includes("email")&&(s.includes("already")||s.includes("exists")||s.includes("unique"))||p("Failed to create staff. Please try again."),t}},existingStaff:e,initialData:q,onUpdate:async e=>{try{const t=localStorage.getItem("hospitalId")||"1",a={...e,hospital:t};await y(e.id,a),await Z(L,I,C),M(!1),V(null)}catch(t){const e=t?.response?.data,a=(Array.isArray(e?.email)?e.email.join(" "):e?.email)||e?.detail||e?.message||"",s=String(a).toLowerCase();throw s.includes("email")&&(s.includes("already")||s.includes("exists")||s.includes("unique"))||p("Failed to update staff. Please try again."),t}},onPasswordChange:async({id:e,admin_password:t,staff_password:a})=>{const s=e||q?.id;if(!s)throw new Error("Staff id is required");await y(s,{id:s,admin_password:t,staff_password:a})},departments:r,staffTypes:i}),(0,_.jsx)(F,{open:U,onClose:()=>H(!1),staff:e})]})]})}export{O 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.