1import{at as ye,G as be,H as Ce,r as t,ar as ae,j as e,a1 as we,a2 as _e,a3 as Se,a4 as Re,v as r,aI as me,O as D,ai as f,Z as te,L as U,Y as ke,a6 as Ie,ao as Le,ap as Ae,ae as De,z as _,aq as Te,av as Pe,a9 as $,aA as Ee,f as re,d as Me,aR as Oe,I as Be,J as He,n as ze,a7 as Ue,a8 as Fe,S as Ye,m as qe,ad as ne,D as ie,C as j,b4 as le,e as $e,P as T}from"./index-CcCokqI7.js";import{T as Ge,a as Ve,b as ce,c as oe}from"./tabs-CfUF0uN5.js";import{u as xe,A as We,U as Je,a as Ke}from"./useCareTeam-Bg-S1Bjl.js";import{T as Xe}from"./textarea-BkYu2MVj.js";import{C as Ze}from"./calendar-CqbBEOV2.js";import{u as Qe}from"./useClientAssignments-CAkjsjO5.js";import{C as P}from"./circle-check-WhEtYRdV.js";import{I as de}from"./inbox-BX5kWuf7.js";import"./subDays-BYnL-81a.js";import"./startOfMonth-BmawN8C1.js";import"./addMonths-Bqg2Xts7.js";import"./isSameMonth-BGxfcPY6.js";import"./isBefore-Bt_0xPqa.js";import"./addWeeks-B-LQogMC.js";import"./endOfWeek-BIKT4Lnx.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const es=ye("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]),ss=[{value:"clinical_assessment",label:"Referral for clinical assessment",description:"Client may need clinical assessment or injury evaluation"},{value:"rehabilitation",label:"Referral for rehabilitation",description:"Client needs a rehabilitation program"},{value:"pain_management",label:"Referral for pain management",description:"Client is reporting persistent pain"},{value:"return_to_sport",label:"Referral for return to sport clearance",description:"Client needs clinical clearance"},{value:"co_management_coordinated",label:"Co-management â coordinated care",description:"Coordinate training with their clinical care"}],as=[{value:"dual_coaching",label:"Co-management â dual coaching",description:"Coordinate programming with another coach or trainer working with this client",tag:"Both coaches contribute to the plan"},{value:"specialist_coaching",label:"Peer referral â specialist coaching",description:"Refer to a coach with a specific specialization this client needs"}],ts=[{value:"co_management_shared",label:"Co-management â shared clinical care",description:"Share clinical responsibility with another clinician or hybrid practitioner"},{value:"specialist_assessment",label:"Specialist referral â assessment only",description:"Refer for specialist assessment"},{value:"specialist_treatment",label:"Specialist referral â treatment",description:"Refer for specialist treatment"},{value:"consultant_advisory",label:"Consultant â advisory only",description:"Request advisory consultation"}],rs=[{value:"care_delegation_training",label:"Care delegation â training",description:"Delegate progressive training to a coach. You retain clinical oversight.",tag:"You = Clinical oversight and rehab · Coach = Training"},{value:"care_delegation_conditioning",label:"Care delegation â conditioning",description:"Delegate conditioning and fitness to a coach. You retain clinical oversight.",tag:"You = Clinical oversight · Coach = Conditioning"},{value:"co_management_coordinated_plan",label:"Co-management â coordinated plan",description:"Coordinate your clinical care with their training plan",tag:"Shared plan â rehab and training connected"}],ns=[{value:"co_management_shared",label:"Co-management â shared care",description:"Formally share care of this client with another practitioner. Both of you contribute to their plan.",tag:"Coordinated care â fully connected plan"},{value:"specialist_assessment",label:"Specialist referral â assessment",description:"Refer for specialist assessment"},{value:"specialist_treatment",label:"Specialist referral â treatment",description:"Refer for specialist treatment"},{value:"consultant_advisory",label:"Consultant â advisory",description:"Request advisory consultation"}],is=[{value:"co_management_coordinated_plan",label:"Co-management â coordinated plan",description:"Coordinate your work with a coach or trainer working with this client",tag:"Training and clinical care connected"},{value:"care_delegation_training",label:"Care delegation â training",description:"Bring in a coach to manage their progressive training",tag:"You = Clinical care · Coach = Training"}],ls=({open:m,onOpenChange:v,referralTarget:g,preSelectedRecipient:S})=>{const{user:R}=be(),{isCoach:N,isClinician:x}=Ce(),{sendReferral:E}=xe(),{myClients:F,loading:M}=Qe(),o=N&&!x,c=N&&x,[n,k]=t.useState(1),[I,y]=t.useState(""),[l,b]=t.useState(null),[C,L]=t.useState(""),[O,A]=t.useState([]),[B,H]=t.useState(!1),[u,w]=t.useState(null),[d,s]=t.useState(""),[i,h]=t.useState("co_manage"),[G,V]=t.useState(""),[Y,W]=t.useState("routine"),[J,K]=t.useState(ae(new Date,90)),[X,Z]=t.useState(!1);t.useEffect(()=>{m&&(z(),S&&w(S))},[m,S]);const ue=c?g==="clinician"?ns:is:o?g==="clinician"?ss:as:g==="clinician"?ts:rs,he=g==="clinician"?"Search clinicians and hybrid practitioners":"Search coaches and trainers",Q=F.filter(a=>{var p;return!I||((p=a.client_name)==null?void 0:p.toLowerCase().includes(I.toLowerCase()))}),ee=async()=>
6{if(C.trim()){H(!0);try{const{data:a}=await re.from("user_roles").select("user_id").in("role",g==="clinician"?["clinician"]:["coach"]),p=(a||[]).map(Ne=>Ne.user_id),{data:ve}=await re.from("profiles").select("user_id, full_name, email, avatar_url").or(`full_name.ilike.%${C}%,email.ilike.%${C}%`).in("user_id",p.length>0?p:["__none__"]).neq("user_id",(R==null?void 0:R.id)||"").limit(10);A(ve||[])}finally{H(!1)}}},pe=async()=>{if(!(!u||!l)){Z(!0);try{await E({receivingPractitionerId:u.user_id,clientUserId:l.client_id,referralType:d,discipline:"training",referralNotes:G||void 0,accessLevelGranted:i,urgency:Y}),v(!1),z()}finally{Z(!1)}}},z=()=>{k(1),y(""),b(null),L(""),A([]),w(null),s(""),h("co_manage"),V(""),W("routine"),K(ae(new Date,90))},se=()=>{switch(n){case 1:return!!l;case 2:return!!u;case 3:return!!d;case 4:return!!i;case 5:return!0;case 6:return!0;case 7:return!0;default:return!1}},ge=x||c?7:5,fe=()=>!!(o&&n===5||(x||c)&&n===7),je=()=>{switch(n){case 1:return"Select Client";case 2:return"Select Practitioner";case 3:return"Referral Type";case 4:return"Access Level";case 5:return"Notes";case 6:return"Urgency";case 7:return"Expiry";default:return""}};return e.jsx(we,{open:m,onOpenChange:a=>{a||z(),v(a)},children:e.jsxs(_e,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(Se,{children:e.jsxs(Re,{className:"flex items-center gap-2",children:[n>1&&e.jsx(r,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>k(a=>Math.max(1,a-1)),children:e.jsx(me,{className:"w-4 h-4"})}),je()," â Step ",n]})}),e.jsx("div",{className:"flex gap-1 mb-2",children:Array.from({length:ge}).map((a,p)=>e.jsx("div",{className:D("h-1 flex-1 rounded-full",p<n?"bg-primary":"bg-muted")},p))}),n===1&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{children:"Select Client"}),e.jsx(te,{placeholder:"Search clients...",value:I,onChange:a=>y(a.target.value)}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:M?e.jsx("div",{className:"py-4 text-center",children:e.jsx(U,{className:"w-4 h-4 animate-spin mx-auto"})}):Q.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No clients found"}):Q.map(a=>e.jsx("button",{className:D("w-full text-left px-3 py-2 rounded-lg text-sm border-2 transition-all",(l==null?void 0:l.id)===a.id?"border-primary bg-primary/10":"border-transparent hover:bg-muted/50"),onClick:()=>b(a),children:e.jsxs("div",{className:"flex items-center gap-2",children:[(l==null?void 0:l.id)===a.id&&e.jsx(P,{className:"w-4 h-4 text-primary shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:a.client_name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a.client_email})]})]})},a.id))})]}),n===2&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{children:he}),u?e.jsxs("div",{className:"flex items-center justify-between p-3 bg-primary/5 border-2 border-primary rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"w-4 h-4 text-primary shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:u.full_name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:u.email})]})]}),e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>w(null),children:"Change"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(te,{placeholder:"Search by name or email...",value:C,onChange:a=>L(a.target.value),onKeyDown:a=>a.key==="Enter"&&ee()}),e.jsx(r,{variant:"outline",size:"icon",onClick:ee,disabled:B,children:B?e.jsx(U,{className:"w-4 h-4 animate-spin"}):e.jsx(ke,{className:"w-4 h-4"})})]}),O.length>0&&e.jsx("div",{className:"border rounded-lg divide-y max-h-40 overflow-y-auto",children:O.map(a=>e.jsxs("button",{className:"w-full text-left px-3 py-2 hover:bg-muted/50 text-sm",onClick:()=>{w(a),A([])},children:[e.jsx("div",{className:"font-medium",children:a.full_name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a.email})]},a.user_id))})]})]}),n===3&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{children:"Referral Type"}),e.jsx("div",{className:"space-y-2 max-h-60 overflow-y-auto",children:ue.map(a=>e.jsx("button",{type:"button",className:D("w-full text-left px-4 py-3 rounded-xl border-2 text-sm transition-all cursor-pointer",d===a.value?"border-primary bg-primary/10 shadow-sm":"border-border hover:border-primary/50 hover:bg-muted/30"),onClick:()=>
6s(a.value),children:e.jsxs("div",{className:"flex items-start gap-2",children:[d===a.value&&e.jsx(P,{className:"w-4 h-4 text-primary shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-semibold",children:a.label}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:a.description}),a.tag&&e.jsx("div",{className:"text-[11px] text-primary/80 mt-1.5 font-medium",children:a.tag})]})]})},a.value))})]}),n===4&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{children:"Access Level"}),We.map(a=>e.jsx("button",{type:"button",className:D("w-full text-left px-4 py-3 rounded-xl border-2 text-sm transition-all cursor-pointer",i===a.value?"border-primary bg-primary/10 shadow-sm":"border-border hover:border-primary/50 hover:bg-muted/30"),onClick:()=>h(a.value),children:e.jsxs("div",{className:"flex items-start gap-2",children:[i===a.value&&e.jsx(P,{className:"w-4 h-4 text-primary shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:a.label}),a.value==="view_only"&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:"Can see but not edit"}),a.value==="co_manage"&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:"Can edit, requires primary approval"}),a.value==="full_access"&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:"Can edit without approval. Only available if you are primary practitioner."})]})]})},a.value))]}),n===5&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{children:"Referral Notes"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Add any relevant context for the practitioner receiving this referral"}),e.jsx(Xe,{placeholder:"Clinical or coordination notes...",value:G,onChange:a=>V(a.target.value),rows:5}),o&&e.jsxs("div",{className:"flex gap-2 p-3 bg-amber-500/10 rounded-lg",children:[e.jsx(Ie,{className:"w-4 h-4 text-amber-500 shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"When you refer a client to a clinician, you are sharing their information with that practitioner. Ensure you have the client's consent to share their health information."})]})]}),n===6&&(x||c)&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{children:"Urgency"}),Je.map(a=>e.jsx("button",{type:"button",className:D("w-full text-left px-4 py-3 rounded-xl border-2 text-sm transition-all cursor-pointer",Y===a.value?"border-primary bg-primary/10 shadow-sm":"border-border hover:border-primary/50 hover:bg-muted/30"),onClick:()=>
6W(a.value),children:e.jsxs("div",{className:"flex items-center gap-2",children:[Y===a.value&&e.jsx(P,{className:"w-4 h-4 text-primary shrink-0"}),e.jsx("span",{className:"font-semibold",children:a.label})]})},a.value))]}),n===7&&(x||c)&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{children:"Referral Expiry Date"}),e.jsxs(Le,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(r,{variant:"outline",className:"w-full justify-start text-left font-normal",children:[e.jsx(De,{className:"w-4 h-4 mr-2"}),_(J,"PPP")]})}),e.jsx(Te,{className:"w-auto p-0",align:"start",children:e.jsx(Ze,{mode:"single",selected:J,onSelect:a=>a&&K(a),disabled:a=>a<new Date,initialFocus:!0,className:"p-3 pointer-events-auto"})})]}),e.jsxs("div",{className:"flex gap-2 p-3 bg-muted/50 rounded-lg",children:[e.jsx(Pe,{className:"w-4 h-4 text-muted-foreground shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Setting an expiry helps document the care period clearly. Default is 90 days."})]})]}),e.jsxs("div",{className:"flex justify-between pt-2",children:[e.jsx(r,{variant:"ghost",onClick:()=>{z(),v(!1)},children:"Cancel"}),fe()?e.jsxs(r,{onClick:pe,disabled:!se()||X,children:[X&&e.jsx(U,{className:"w-4 h-4 mr-2 animate-spin"}),e.jsx($,{className:"w-4 h-4 mr-2"}),"Send Referral"]}):e.jsxs(r,{onClick:()=>k(a=>a+1),disabled:!se(),children:["Next ",e.jsx(Ee,{className:"w-4 h-4 ml-1"})]})]})]})})},q=m=>{switch(m){case"pending":return e.jsx(T,{variant:"outline",className:"bg-amber-500/10 text-amber-500 border-amber-500/30",children:"Pending"});case"accepted":case"approved":return e.jsx(T,{variant:"outline",className:"bg-green-500/10 text-green-500 border-green-500/30",children:"Accepted"});case"declined":return e.jsx(T,{variant:"destructive",children:"Declined"});case"expired":return e.jsx(T,{variant:"outline",className:"bg-muted-foreground/10 text-muted-foreground",children:"Expired"});default:return e.jsx(T,{variant:"outline",children:m})}},ws=()=>{const m=Me(),v=Oe(),{isCollapsed:g}=Be(),S=He(),[R,N]=t.useState(!1),[x,E]=t.useState("clinician"),[F,M]=t.useState(null);t.useEffect(()=>{const s=v.state;s!=null&&s.preSelectedRecipient&&(M(s.preSelectedRecipient),E(s.referralTarget||"clinician"),N(!0),window.history.replaceState({},document.title))},[v.state]);const{sent:o,received:c,pendingSent:n,pendingReceived:k,loading:I,respondToReferral:y}=xe(),{pendingIncoming:l,myRequests:b,loading:C,respondToRequest:L}=Ke(),O=I||C,A=()=>S?"0px":g?"80px":"288px",B=o.filter(s=>s.status==="accepted").length+c.filter(s=>s.status==="accepted").length,H=o.filter(s=>s.status==="declined").length+c.filter(s=>s.status==="declined").length,u=k.length+l.length,w=[{title:"Pending",count:n.length,icon:ze,color:"text-amber-500"},{title:"Accepted",count:B,icon:Ue,color:"text-green-500"},{title:"Declined",count:H,icon:Fe,color:"text-destructive"},{title:"Incoming",count:u,icon:de,color:"text-primary"}],d=s=>{E(s),N(!0)};return e.jsxs("div",{className:"min-h-screen bg-background pb-24",children:[e.jsx(Ye,{}),e.jsx(qe.main,{className:"min-h-screen p-4 md:p-8",animate:{marginLeft:A()},initial:!1,transition:{duration:.3,ease:"easeInOut"},children:e.jsxs("div",{className:"max-w-5xl mx-auto ",children:[e.jsxs(r,{variant:"ghost",size:"sm",onClick:()=>m(-1),className:"-ml-2 mb-4",children:[e.jsx(me,{className:"h-4 w-4 mr-2"}),"Back"]}),e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between mb-6 gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx($,{className:"w-6 h-6 text-primary"}),e.jsx("h1",{className:"text-2xl md:text-3xl font-black text-foreground tracking-tight",children:"REFERRALS"})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Send and track referrals & co-management requests"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(r,{variant:"outline",onClick:()=>d("clinician"),className:"gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),"Refer to Clinician / Hybrid"]}),e.jsxs(r,{variant:"outline",onClick:()=>d("coach"),className:"gap-2",children:[e.jsx(ie,{className:"w-4 h-4"}),"Refer to Coach / Trainer"]})]})]}),O?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(U,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4 mb-6",children:w.map(s=>{const i=s.icon;return e.jsxs(j,{className:"p-4 bg-card border-border text-center",children:[e.jsx("div",{className:"text-2xl font-black text-foreground",children:s.count}),e.jsxs("div",{className:`text-xs uppercase flex items-center justify-center gap-1 ${s.color}`,children:[e.jsx(i,{className:"w-3 h-3"})," ",s.title]})]},s.title)})}),e.jsxs(Ge,{defaultValue:"sent",className:"space-y-4",children:[e.jsxs(Ve,{className:"grid w-full grid-cols-2",children:[e.jsxs(ce,{value:"sent",children:["Sent Referrals (",o.length+b.length,")"]}),e.jsxs(ce,{value:"received",children:["Received (",c.length+l.length,")"]})]}),e.jsx(oe,{value:"sent",children:o.length===0&&b.length===0?e.jsx(j,{className:"p-8 bg-muted/30 border-dashed",children:e.jsxs("div",{className:"text-center",children:[e.jsx($,{className:"w-12 h-12 mx-auto text-muted-foreground mb-3 opacity-50"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"No sent referrals or co-management requests yet"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 justify-center mt-4",children:[e.jsxs(r,{variant:"outline",onClick:()=>d("clinician"),children:[e.jsx(ne,{className:"w-4 h-4 mr-2"})," Refer to Clinician / Hybrid"]}
6),e.jsxs(r,{variant:"outline",onClick:()=>d("coach"),children:[e.jsx(ie,{className:"w-4 h-4 mr-2"})," Refer to Coach / Trainer"]})]})]})}):e.jsxs("div",{className:"space-y-2",children:[o.map(s=>{var i,h;return e.jsx(j,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm",children:((i=s.client)==null?void 0:i.full_name)||"Unknown Client"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:((h=s.receiving_practitioner)==null?void 0:h.full_name)||"Unknown"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 flex flex-wrap gap-2",children:[e.jsx("span",{children:s.referral_type.replace(/_/g," ")}),e.jsx("span",{children:"·"}),e.jsx("span",{children:s.discipline}),e.jsx("span",{children:"·"}),e.jsx("span",{children:_(new Date(s.created_at),"MMM d, yyyy")}),s.expires_at&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:["Exp: ",_(new Date(s.expires_at),"MMM d")]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[q(s.status),s.status==="pending"&&e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>y({referralId:s.id,status:"declined",declineReason:"Cancelled by sender"}),children:e.jsx(es,{className:"w-3.5 h-3.5"})})]})]})},s.id)}),b.map(s=>e.jsx(j,{className:"p-4 border-dashed",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-sm",children:"Co-management request"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[s.discipline," · ",s.access_requested.replace(/_/g," ")," · ",_(new Date(s.created_at),"MMM d, yyyy")]})]}),q(s.status)]})},s.id))]})}),e.jsx(oe,{value:"received",children:c.length===0&&l.length===0?e.jsx(j,{className:"p-8 bg-muted/30 border-dashed",children:e.jsxs("div",{className:"text-center",children:[e.jsx(de,{className:"w-12 h-12 mx-auto text-muted-foreground mb-3 opacity-50"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"No referrals received yet"})]})}):e.jsxs("div",{className:"space-y-2",children:[c.map(s=>{var i,h;return e.jsx(j,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"From"}),e.jsx("span",{className:"font-medium text-sm",children:((i=s.referring_practitioner)==null?void 0:i.full_name)||"Unknown"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 flex flex-wrap gap-2",children:[e.jsxs("span",{children:["Client: ",(h=s.client)==null?void 0:h.full_name]}),e.jsx("span",{children:"·"}),e.jsx("span",{children:s.referral_type.replace(/_/g," ")}),e.jsx("span",{children:"·"}),e.jsx("span",{children:_(new Date(s.created_at),"MMM d, yyyy")})]}),s.referral_notes&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2 italic",children:['"',s.referral_notes,'"']})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[q(s.status),s.status==="pending"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsx(r,{size:"sm",variant:"default",className:"h-7 text-xs",onClick:()=>y({referralId:s.id,status:"accepted"}),children:"Accept"}),e.jsx(r,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>y({referralId:s.id,status:"declined"}),children:"Decline"})]})]})]})},s.id)}),l.map(s=>{var i;return e.jsx(j,{className:"p-4 border-primary/30",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"w-3.5 h-3.5 text-primary"}),e.jsxs("span",{className:"font-medium text-sm",children:["Access request from ",(i=s.requesting_practitioner)==null?void 0:i.full_name]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[s.discipline," · ",s.access_requested.replace(/_/g," ")," · ",_(new Date(s.created_at),"MMM d, yyyy")]})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(r,{size:"sm",variant:"default",className:"h-7 text-xs",onClick:()=>L({requestId:s.id,status:"approved",approvedWithLevel:s.access_requested}),children:"Approve"}),e.jsx(r,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>L({requestId:s.id,status:"declined"}),children:"Decline"})]})]})},s.id)})]})})]})]})]})}),e.jsx($e,{}),e.jsx(ls,{open:R,onOpenChange:s=>{N(s),s||M(null)},referralTarget:x,preSelectedRecipient:F})]})};export{ws 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.