1import{u as K,d as Q,r as i,j as e,b as g}from"./index-Bqwhn9mJ.js";import{A as X}from"./AppLayout-B7on84ct.js";import"./en-US-BiydZC27.js";function se(){const{showToast:d}=K(),{user:w}=Q(),S=w?.role==="admin"||w?.role==="office_manager"||w?.is_super_admin===!0,[j,F]=i.useState([]),[M,H]=i.useState({}),[B,D]=i.useState(null),[I,O]=i.useState(!0),[G,h]=i.useState(!1),[b,P]=i.useState(null),[p,y]=i.useState({name:"",description:"",consultation_price:""}),[E,L]=i.useState(!1),[W,C]=i.useState(null),[x,v]=i.useState({self_pay:"",insurance:{},corporate:{}}),[k,$]=i.useState(!1),z=s=>{const t={};for(const r of s.insurance)t[r.payer_id]={price:r.price!=null?String(r.price):"",excluded:r.excluded};const n={};for(const r of s.corporate)n[r.payer_id]={price:r.price!=null?String(r.price):"",excluded:r.excluded};v({self_pay:s.self_pay!=null?String(s.self_pay):"",insurance:t,corporate:n}),C(s.id)},R=async s=>{$(!0);try{const t=[...Object.entries(x.insurance).map(([c,o])=>({payer_type:"insurance",payer_id:Number(c),price:o.price===""?null:Number(o.price),excluded:o.excluded})),...Object.entries(x.corporate).map(([c,o])=>({payer_type:"corporate",payer_id:Number(c),price:o.price===""?null:Number(o.price),excluded:o.excluded}))],{data:n}=await g.put(`/clinics/${s}/pricing`,{self_pay:x.self_pay===""?null:Number(x.self_pay),payers:t}),r=(n.changes||[]).length;d(r>0?`Prices updated (${r} change${r!==1?"s":""}); admins notified`:"No price changes","success"),C(null),N()}catch(t){d(t.response?.data?.error||"Failed to update prices","error")}finally{$(!1)}},N=async()=>{try{const[s,t]=await Promise.all([g.get("/clinics"),g.get("/clinics/pricing")]);F(s.data.clinics);const n={};for(const r of t.data.clinics)n[r.id]=r;H(n)}catch{d("Failed to load clinics","error")}finally{O(!1)}};i.useEffect(()=>{N()},[]);const T=s=>s.excluded?"Not covered":s.price===0?"Covered (free)":`GHS ${Number(s.price).toFixed(2)}`,q=()=>{P(null),y({name:"",description:"",consultation_price:""}),h(!0)},U=s=>{P(s),y({name:s.name,description:s.description||"",consultation_price:s.consultation_price!=null?String(s.consultation_price):""}),h(!0)},V=async()=>{if(!p.name.trim()){d("Clinic name is required","error");return}L(!0);try{b?(await g.put(`/clinics/${b.id}`,p),d("Clinic updated successfully","success")):(await g.post("/clinics",p),d("Clinic created successfully","success")),h(!1),N()}catch(s){d(s.response?.data?.error||"Failed to save clinic","error")}finally{L(!1)}},J=async s=>{if(window.confirm(`Deactivate "${s.name}"? It will no longer appear in dropdowns.`))try{await g.delete(`/clinics/${s.id}`),d("Clinic deactivated","success"),N()}catch{d("Failed to deactivate clinic","error")}};return e.jsxs(X,{title:"Clinic Management",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Clinics"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Manage specialist clinics available for encounters and billing"})]}),e.jsxs("button",{onClick:q,className:"flex items-center gap-2 px-5 py-2.5 bg-primary-600 text-white rounded-lg hover:bg-primary-700 transition-colors font-medium",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"Add Clinic"]})]}),e.jsxs("p",{className:"text-sm text-gray-500",children:[j.length," clinic",j.length!==1?"s":""]}),e.jsx("div",{className:"bg-white rounded-xl shadow-lg border border-gray-200 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Clinic Name"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Description"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Consultation Price"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Status"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:I?Array.from({length:5}).map((s,t)=>e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-6 py-4",children:e.jsx("div",{className:"h-4 bg-gray-200 rounded animate-pulse",style:{width:`${50+Math.random()*40}%`}})})},t)):j.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-6 py-12 text-center text-gray-500",children:'No clinics foun
1d. Click "Add Clinic" to create one.'})}):j.map(s=>{const t=M[s.id],n=!!t&&t.charge_master_id!=null,r=B===s.id;return e.jsxs(i.Fragment,{children:[e.jsxs("tr",{className:`transition-colors ${n?"cursor-pointer hover:bg-gray-50":"hover:bg-gray-50"}`,onClick:n?()=>D(r?null:s.id):void 0,children:[e.jsx("td",{className:"px-6 py-3",children:e.jsxs("span",{className:"flex items-center gap-2 font-medium text-gray-900",children:[n&&e.jsx("svg",{className:`w-4 h-4 text-gray-400 transition-transform ${r?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),s.name]})}),e.jsx("td",{className:"px-6 py-3",children:e.jsx("span",{className:"text-sm text-gray-500",children:s.description||"â"})}),e.jsx("td",{className:"px-6 py-3",children:e.jsx("span",{className:"text-sm font-medium text-gray-900",children:s.consultation_price!=null?`GHS ${Number(s.consultation_price).toFixed(2)}`:"â"})}),e.jsx("td",{className:"px-6 py-3",children:e.jsx("span",{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${s.is_active?"bg-green-100 text-green-700":"bg-gray-100 text-gray-500"}`,children:s.is_active?"Active":"Inactive"})}),e.jsx("td",{className:"px-6 py-3 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:c=>{c.stopPropagation(),U(s)},className:"p-1.5 text-gray-500 hover:text-primary-600 hover:bg-primary-50 rounded-lg transition-colors",title:"Edit",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),e.jsx("button",{onClick:c=>{c.stopPropagation(),J(s)},className:"p-1.5 text-gray-500 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors",title:"Deactivate",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})})]}),r&&n&&(()=>{const c=W===s.id,o=(l,m)=>e.jsx("div",{className:"space-y-2",children:m.map(a=>{const u=x[l][a.payer_id]||{price:"",excluded:!1};return e.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm",children:[e.jsx("span",{className:"text-gray-700 flex-1 truncate",children:a.name}),e.jsx("input",{type:"number",min:"0",step:"0.01",value:u.excluded?"":u.price,disabled:u.excluded,placeholder:"self-pay",onChange:_=>v(f=>({...f,[l]:{...f[l],[a.payer_id]:{...u,price:_.target.value}}})),className:"w-24 px-2 py-1 border border-gray-300 rounded focus:ring-1 focus:ring-primary-500 disabled:bg-gray-100"}),e.jsxs("label",{className:"flex items-center gap-1 text-xs text-gray-500 whitespace-nowrap",children:[e.jsx("input",{type:"checkbox",checked:u.excluded,onChange:_=>v(f=>({...f,[l]:{...f[l],[a.payer_id]:{...u,excluded:_.target.checked}}}))}),"Not covered"]})]},a.payer_id)})}),A=l=>{const m=l.filter(a=>a.set);return m.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"No special rates â billed at self-pay."}):e.jsx("div",{className:"space-y-1",children:m.map(a=>e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-700",children:a.name}),e.jsx("span",{className:a.excluded?"text-gray-400":a.price===0?"text-green-600 font-medium":"text-gray-900 font-medium",children:T(a)})]},a.payer_id))})};return e.jsx("tr",{className:"bg-gray-50/60",children:e.jsxs("td",{colSpan:5,className:"px-6 py-4",onClick:l=>l.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"Self-pay: "}),c?e.jsx("input",{type:"number",min:"0",step:"0.01",value:x.self_pay,onChange:l=>v(m=>({...m,self_pay:l.target.value})),className:"w-28 px-2 py-1 border border-gray-300 rounded focus:ring-1 focus:ring-primary-500"}):e.jsx("span",{className:"font-medium text-gray-700",children:t.self_pay!=null?`GHS ${t.self_pay.toFixed(2)}`:"â"})]}),S&&(c?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>C(null),disabled:k,className:"px-3 py-1.5 text-sm text-gray-600 hover:bg-gray-200 rounded-lg",children:"Cancel"}),e.jsx("button",{onClick:()=>
1R(s.id),disabled:k,className:"px-4 py-1.5 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 disabled:opacity-50",children:k?"Savingâ¦":"Save prices"})]}):e.jsx("button",{onClick:()=>z(t),className:"px-3 py-1.5 text-sm font-medium text-primary-600 bg-primary-50 border border-primary-200 rounded-lg hover:bg-primary-100",children:"Edit prices"}))]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2",children:"Insurance"}),c?o("insurance",t.insurance):A(t.insurance)]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2",children:"Corporate"}),c?o("corporate",t.corporate):A(t.corporate)]})]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-3",children:["Payers left blank are billed the self-pay rate. The matching rate applies automatically on the invoice based on the patient's payer source.",S?" Admins are notified of any price change.":""]})]})},`${s.id}-detail`)})()]},s.id)})})]})})})]}),G&&e.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:e.jsxs("div",{className:"flex items-center justify-center min-h-screen px-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 transition-opacity",onClick:()=>h(!1)}),e.jsxs("div",{className:"relative bg-white rounded-xl shadow-xl max-w-md w-full p-6 z-10",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:b?"Edit Clinic":"Add New Clinic"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Clinic Name *"}),e.jsx("input",{type:"text",value:p.name,onChange:s=>y({...p,name:s.target.value}),className:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500",autoFocus:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Consultation Price (GHS)"}),e.jsx("input",{type:"number",min:"0",step:"0.01",value:p.consultation_price,onChange:s=>y({...p,consultation_price:s.target.value}),placeholder:"e.g. 400.00",className:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500"}),e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"Charged at check-in when this clinic is selected. Leave blank for none."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Description (optional)"}),e.jsx("textarea",{value:p.description,onChange:s=>y({...p,description:s.target.value}),rows:2,className:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500"})]})]}),e.jsxs("div",{className:"flex justify-end gap-3 mt-6",children:[e.jsx("button",{onClick:()=>h(!1),className:"px-4 py-2 text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors font-medium",children:"Cancel"}),e.jsx("button",{onClick:V,disabled:E,className:"px-5 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 transition-colors font-medium disabled:opacity-50",children:E?"Saving...":b?"Update":"Create"})]})]})]})})]})}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.