1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Layout-DJPFJEnW.js","assets/vendor-react-CoJda1Bd.js","assets/vendor-router-BG1ccVOB.js","assets/LogoMark-C8Gzk_Eb.js","assets/branding-CSuvK0zE.js","assets/index-DRQAaCbt.js","assets/vendor-radix-I618Mglk.js","assets/vendor-supabase-BI1TbgRl.js","assets/vendor-charts-Df9hQbmF.js","assets/vendor-icons-BbhXjgy5.js","assets/vendor-query-_n4XbDCE.js","assets/vendor-date-Ctl2uRge.js","assets/index-CHjfJmCN.css","assets/button-ozMsoqIh.js"])))=>i.map(i=>d[i]); 2import{s as d,t as a,w as q,_ as $}from"./index-DRQAaCbt.js";import{r,j as e}from"./vendor-react-CoJda1Bd.js";import{L as b}from"./Layout-DJPFJEnW.js";import{P as G}from"./PortalBottomNav-C8v4d43x.js";import{B as h}from"./button-ozMsoqIh.js";import{I as k}from"./input-B2adqXLP.js";import{L as C}from"./label-BPNmfi2k.js";import{C as g}from"./checkbox-DMpx7LYF.js";import{a as V}from"./vendor-router-BG1ccVOB.js";import{L as E,n as z,x as K,t as U,C as j,aq as Y,r as M,u as H,D as J,c as Q}from"./vendor-icons-BbhXjgy5.js";import"./vendor-radix-I618Mglk.js";import"./vendor-supabase-BI1TbgRl.js";import"./vendor-charts-Df9hQbmF.js";import"./vendor-query-_n4XbDCE.js";import"./vendor-date-Ctl2uRge.js";import"./LogoMark-C8Gzk_Eb.js";import"./branding-CSuvK0zE.js";import"./haptics-IUZ9jpTP.js";import"./VoiceEntryRecorder-Dv8acccw.js";import"./sinceLastVisitAnchor-Il07-Rd-.js";import"./calendar-31DnDnJr.js";import"./select-DPNV9hN7.js";import"./textarea-B9C9WMMJ.js";import"./radio-group-D83kb3uo.js";import"./badge-CHLB95D3.js";import"./alert-BldCaXLd.js";import"./card-CGxU6Ujh.js";import"./use-caregiver-context-B5bWaKto.js";import"./schemas-5iI55soa.js";import"./vendor-forms-BFc0VN4G.js";import"./treatmentDerivation-BmzSioBR.js";import"./intake-DaqTMNW9.js";import"./treatmentMatchers-CruuOT3h.js";import"./mgRelevance-C5hIcfPS.js";function Ie(){const[n,S]=r.useState(null),[A,L]=r.useState(!0),[w,_]=r.useState(!1),[f,I]=r.useState([]),[l,N]=r.useState(""),[c,v]=r.useState({can_view_entries:!0,can_view_attachments:!1,can_download_pdf:!1}),[m,P]=r.useState(null),[D,y]=r.useState(!1),x=V(),p=r.useCallback(async t=>{try{const{data:s,error:i}=await d.from("patient_clinician_access").select("id, invited_email, invite_token, status, can_view_entries, can_view_attachments, can_download_pdf, expires_at, created_at").eq("patient_id",t).order("created_at",{ascending:!1});if(i){console.error("Error loading access grants:",i);return}I(s||[])}catch(s){console.error("Error:",s)}},[]);r.useEffect(()=>{(async()=>{try{const{data:{session:s}}=await d.auth.getSession();if(!s){x(`/auth?redirect=${encodeURIComponent(window.location.pathname)}`);return}const{data:i,error:o}=await d.from("patients").select("id").eq("patient_id",s.user.id).maybeSingle();if(o){console.error("Error loading patient:",o),a({title:"Error loading data",description:"Could not load patient information.",variant:"destructive"});return}if(!i){x("/onboarding");return}S(i.id),await p(i.id)}catch(s){console.error("Error:",s),a({title:"Error",description:"An unexpected error occurred.",variant:"destructive"})}finally{L(!1)}})()},[x,p]);const F=async()=>{if(n){if(!l.trim()){a({title:"Email required",description:"Please enter your clinician's email address.",variant:"destructive"});return}if(!q(l)){a({title:"Invalid email",description:"Please enter a valid email address.",variant:"destructive"});return}_(!0);try{const t=new Date;t.setDate(t.getDate()+90);const{data:s,error:i}=await d.from("patient_clinician_access").insert([{patient_id:n,invited_email:l.toLowerCase().trim(),status:"pending",can_view_entries:c.can_view_entries,can_view_attachments:c.can_view_attachments,can_download_pdf:c.can_download_pdf,expires_at:t.toISOString()}]).select("id, invite_token").single();if(i){console.error("Error creating access grant:",i),a({title:"Error creating invite",description:i.message||"Please try again.",variant:"destructive"});return}const o=`${window.location.origin}/clinician/accept-invite#${s.invite_token}`;P(o);const{error:u}=await d.functions.invoke("send-clinician-invite",{body:{accessId:s.id}});u?(console.error("Error sending clinician invite email:",u),a({title:"Couldn't send email",description:"The invite was created. Copy and share the link manually.",variant:"destructive"})):a({title:"Invitation sent",description:`An invitation email was sent to ${l}.`}),N(""),await p(n)}catch(t){console.error("Error:",t),a({title:"Error",description:"An unexpected error occurred.",variant:"destructive"})}finally{_(!1)}}},T=async()=>
2{if(!m)return;const{copyText:t,CLIPBOARD_FALLBACK_TOAST:s}=await $(async()=>{const{copyText:o,CLIPBOARD_FALLBACK_TOAST:u}=await import("./Layout-DJPFJEnW.js").then(R=>R.t);return{copyText:o,CLIPBOARD_FALLBACK_TOAST:u}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13]));await t(m)==="ok"?(y(!0),a({title:"Copied",description:"Invite link copied to clipboard."}),setTimeout(()=>y(!1),2e3)):a({title:"Copy failed",description:s,variant:"destructive"})},B=async t=>{if(n)try{const{error:s}=await d.from("patient_clinician_access").delete().eq("id",t.id);if(s){console.error("Error revoking access:",s),a({title:"Error",description:"Could not revoke access.",variant:"destructive"});return}a({title:"Access revoked",description:`Access for ${t.invited_email} has been removed.`}),await p(n)}catch(s){console.error("Error:",s)}},O=t=>{switch(t){case"accepted":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",children:[e.jsx(j,{className:"w-3 h-3"}),"Active"]});case"pending":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400",children:[e.jsx(Q,{className:"w-3 h-3"}),"Pending"]});default:return e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-muted text-muted-foreground",children:t})}};return A?e.jsx(b,{children:e.jsx("section",{className:"section-padding",children:e.jsx("div",{className:"content-container flex items-center justify-center min-h-[60vh]",children:e.jsx(E,{className:"w-8 h-8 animate-spin text-muted-foreground"})})})}):e.jsxs(b,{children:[e.jsx("section",{className:"px-2.5 md:section-padding pb-24 xl:pb-6",children:e.jsx("div",{className:"content-container",children:e.jsxs("div",{className:"max-w-2xl mx-auto",children:[e.jsxs("div",{className:"mb-8",children:[e.jsxs(h,{variant:"ghost",size:"sm",className:"hidden md:inline-flex gap-1 -ml-2 mb-2 text-muted-foreground hover:text-foreground",onClick:()=>x("/portal/dashboard"),children:[e.jsx(z,{className:"w-4 h-4"}),"Dashboard"]}),e.jsx("h1",{className:"text-2xl md:text-3xl font-serif font-bold text-foreground",children:"Share Access"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Invite a clinician to view your health records securely."})]}),e.jsxs("div",{className:"card-elevated p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-3 pb-4 border-b border-border",children:[e.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10",children:e.jsx(K,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold text-foreground",children:"Invite a Clinician"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Enter their email and choose what they can access."})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"email",children:"Clinician's Email Address"}),e.jsx(k,{id:"email",type:"email",value:l,onChange:t=>N(t.target.value),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{children:"Permissions"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(g,{id:"view_entries",checked:c.can_view_entries,onCheckedChange:t=>v(s=>({...s,can_view_entries:!!t}))}),e.jsx("label",{htmlFor:"view_entries",className:"text-sm font-medium leading-none cursor-pointer",children:"View timeline entries & intake"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(g,{id:"view_attachments",checked:c.can_view_attachments,onCheckedChange:t=>v(s=>({...s,can_view_attachments:!!t}))}),e.jsx("label",{htmlFor:"view_attachments",className:"text-sm font-medium leading-none cursor-pointer",children:"View uploaded documents"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(g,{id:"download_pdf",checked:c.can_download_pdf,onCheckedChange:t=>v(s=>({...s,can_download_pdf:!!t}))}),e.jsx("label",{htmlFor:"download_pdf",className:"text-sm font-medium leading-none cursor-pointer",children:"Download PDF summaries"})]})]})]}),e.jsx(h,{variant:"hero",onClick:F,disabled:w,className:"w-full",children:w?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"w-4 h-4 mr-2 animate-spin"}),"Creating Invite..."]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-4 h-4 mr-2"}),"Create Invite Link"]})})]}),m&&e.jsxs("div",{className:"mt-4 p-4 rounded-lg bg-primary/5 border border-primary/20",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[e.jsx(j,{className:"w-5 h-5 text-primary shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:"Invite link created!"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Share this link with your clinician:"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{value:m,readOnly:!0,className:"text-sm font-mono bg-background"}),e.jsx(h,{variant:"outline",onClick:T,children:D?e.jsx(j,{className:"w-4 h-4"}):e.jsx(Y,{className:"w-4 h-4"})})]})]})]}),f.length>0&&e.jsxs("div",{className:"mt-8",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(M,{className:"w-5 h-5 text-muted-foreground"}),e.jsxs("h2",{className:"font-semibold text-foreground",children:["Shared Access (",f.length,")"]})]}),e.jsx("div",{className:"space-y-3",children:f.map(t=>e.jsx("div",{className:"card-elevated p-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:t.invited_email}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Created ",new Date(t.created_at).toLocaleDateString(),t.expires_at&&e.jsxs(e.Fragment,{children:[" ⢠Expires ",new Date(t.expires_at).toLocaleDateString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[O(t.status),e.jsx(h,{variant:"ghost",size:"icon",onClick:()=>B(t),className:"text-muted-foreground hover:text-destructive",children:e.jsx(H,{className:"w-4 h-4"})})]})]})},t.id))})]}),e.jsxs("div",{className:"mt-6 p-4 rounded-lg bg-muted/50 border border-border flex items-start gap-3",children:[e.jsx(J,{className:"w-5 h-5 text-muted-foreground shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Your data stays private"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Clinicians only see what you explicitly share. You can revoke access at any time."})]})]})]})})}),n&&e.jsx(G,{patientId:n}
2)]})}export{Ie 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.