1import{r as a,j as e,e as Ns}from"./react-vendor-CU6Sz31W.js";import{R as js}from"./RoutePageHeaderContent-FkxdZGox.js";import{R as ws}from"./RoutePageTitle-D_8Od-sv.js";import{al as We,as as Ce,ax as ot,t as te,u as ht,b as ze,aD as ds,rs as ms,p9 as Vt,cZ as bt,aF as Pe,fg as ks,el as ct,ek as dt,C as st,c3 as Ue,rt as yt,i as Q,cd as kt,cr as pt,I as we,d as mt,ru as Cs,fT as $t,ae as zt,af as Dt,ag as Et,gB as Ot,ah as Ut,S as $e,mF as Bt,hS as Ht,eM as Kt,rv as Ss,f$ as nt,gk as Ct,c4 as Ps,cv as St,cx as Te,i_ as Ve,pV as Ae,ce as et,ef as xs,dg as us,aI as xt,pU as Ts,aJ as Wt,cw as Is,au as it,g as Vs,h9 as zs,at as Ds,f2 as Es,aw as Rs,L as Qe,U as gs,a0 as Se,j as E,az as As,e as Pt,f0 as qt,cc as Ms,c6 as Ls,hM as Fs,ex as _s,eC as $s,bY as Os,jv as Us,et as Bs,eu as Hs,ev as vt,gi as Nt}from"./index-DEXJEDAi.js";import{e as He,f as hs,q as Tt,w as It,d as Xe,c as Gt,m as Zt,s as Me,t as Jt}from"./firebase-w6DYUbFN.js";import{E as Ks}from"./ExplicitAvailabilityManager-ChpJp2X-.js";import{s as Yt}from"./providerOperations-ELdKx_YD.js";import{R as Ws}from"./ReassignVisitDialog-BEbFAHvS.js";import{m as qs,b as Gs,a as Zs,d as Js,P as ps,c as Ys}from"./calendarBounds-DQCPEB1J.js";import{e as Rt,T as At,a as Ke,b as Oe,c as Mt,d as ee}from"./table-CxPdvV_9.js";import{S as ue,a as Qs}from"./DataTableCard-BluwWKn_.js";import{T as Be}from"./text-highlight-BFqqfcjs.js";import{P as _e}from"./pill-filter-CtZSNPVl.js";import{S as Xs}from"./ScrollPagination-ChbtpYdB.js";import{C as ea,a as ta,b as sa,c as Le}from"./context-menu-DwAG_bm5.js";import{D as aa}from"./date-picker-filter-Qp1kqu9t.js";import{u as Lt}from"./useTableSort-KpNOL2n3.js";import{u as Ft}from"./useOpenPatientProfile-CASNKG5E.js";import{P as tt}from"./patient-name-link-BAfQKbEs.js";import{s as fs,f as la}from"./rawTableExport-DjSsUxyR.js";import{V as ra}from"./VisitHistoryStatusBadge-CwrENSqG.js";import{g as Qt,a as na}from"./statusBadge-Dq6-fXVv.js";import{e as Xt,d as Ye,b as Ie,f as jt,g as ut,h as ia,c as oa}from"./visitDisplay-XXmI5Egl.js";import{E as gt}from"./ExportCsvAction-BJr9eiP6.js";import{V as ca}from"./VisitTranscriptModal-JgOe5reP.js";import{u as da,w as ma}from"./useClientsById-BI_N6qCU.js";import{u as xa}from"./useClinicalRecordMessagingActions-DbPdmNJ5.js";import{E as ua}from"./ellipsis-vertical-C-dQ6Kzj.js";import{A as es}from"./arrow-right-left-B4vnGqzD.js";import"./calendar-RV2oTCrW.js";import{C as bs}from"./calendar-range-DRIxB27l.js";import{F as ga,i as ha,a as pa}from"./index-D8wjYP7x.js";import{C as fa}from"./chartPalette-CFmN-0p5.js";import{S as ba}from"./square-D7DkS8S2.js";import{S as ya}from"./square-check-big-BIK4lrHD.js";import{n as Fe,g as va,V as Na}from"./visitIcons-CG7YiClb.js";import{M as ja,o as wa}from"./modal-form-CqN5DZuv.js";import"./ChartStage-kk8qB2rS.js";import{S as wt}from"./StatTile-DQJZPnfG.js";import{P as ka}from"./ProviderScheduleVisitModal-DArCs9CI.js";import{u as Ca,a as Sa}from"./useVisitChartingLauncher-B1f2Z2_Q.js";import"./payment-icons-Daq1K3F1.js";import"./schedulingSelection-CZL0RDzD.js";import"./parseISO-DTktcOZT.js";import"./addWeeks-1hrFjz19.js";import"./networkLicensurePolicy-Ct3PZM4V.js";import"./VisitSchedulePicker-4J6xpsxo.js";import"./clientProviderAvailability-CFIfqNIp.js";import"./user-round-c4EWOTq5.js";import"./index-BSuGcRaZ.js";import"./arrow-up-D6DFVL4j.js";import"./arrow-down-BjUlbB4f.js";import"./clear-filters-button-DmPemFGr.js";import"./modal-option-cards-Dksohkou.js";import"./badge-check-DS4dztDB.js";import"./chartTheme-By-OHNNJ.js";import"./formatters-C_0Kn-_3.js";import"./PatientProfileBrandingContext-B4yn3g4G.js";import"./preferredProtocolEligibility-Wx-sDe0P.js";function Pa({open:s,onOpenChange:u,provider:i}){const{branding:v}=We(),F=(v==null?void 0:v.backgroundColor)||"#ffffff",[p,y]=a.useState([]),[W,O]=a.useState(!1);a.useEffect(()=>{if(!(i!=null&&i.id)||!s)return;O(!0);const R=He(Ce,"Users",i.id,"Hours"),q=hs(R,I=>{const b=I.docs.filter(H=>H.id!=="default").map(H=>({id:H.id,...H.data()}));y(b),O(!1)},I=>{console.error("Error loading hours:",I),O(!1)});return()=>q()},[i==null?void 0:i.id,s]);async function V(R){if(i!=null&&i.id)try{await Yt({providerId:i.id,blocks:R})}catch(q){throw console.error("Error saving availability:",q),te.error("Unable to save availability. Please try again."),q}}async function B(R,{replacementBlocks:q=[]}={}){if(!(!(i!=null&&i.id)||!(R!=null&&R.id)))try{await Yt({providerId:i.id,replaceBlockId:R.id,blocks:q.map(I=>({startAt:{toMillis:()=>I.startMillis},endAt:{toMillis:()=>I.endMillis}}
1))})}catch(I){throw console.error("Error deleting availability:",I),te.error("Unable to remove availability. Please try again."),I}}return e.jsx(ot,{open:s,onOpenChange:u,title:`Manage Availability - ${(i==null?void 0:i.displayName)||""}`,description:"Set availability by selecting specific dates and times for this provider",contentClassName:"h-[calc(100dvh-1rem)] max-w-6xl sm:h-auto sm:max-h-[90vh]",contentStyle:{backgroundColor:F},contentTestId:"dialog-sync-visits-admin-provider-schedule",preventOutsideDismiss:!0,headerClassName:"max-[1024px]:pb-2",titleClassName:"max-[1024px]:truncate",bodyClassName:"max-[1024px]:px-2.5 max-[1024px]:py-2.5",children:e.jsx(Ks,{singleCardLayout:!0,availabilityBlocks:p,onSave:V,onDelete:B,loading:W,providerNetworkId:(i==null?void 0:i.providerNetworkId)||null,businessId:(i==null?void 0:i.businessId)||null,locationIds:(i==null?void 0:i.locationIds)||[]})})}const ts=40,Ta=40;function Ia(s){var i,v;const u=oa(s).toString().trim().toUpperCase();return u?u.slice(0,2):((v=(i=s==null?void 0:s.patientName)==null?void 0:i[0])==null?void 0:v.toUpperCase())||"P"}function Va(s){return String((s==null?void 0:s.visitMode)||(s==null?void 0:s.visitSource)||"").trim().toLowerCase()==="async"||String((s==null?void 0:s.visitSource)||"").trim().toLowerCase()==="async_visit"}function ss(s){return!(s!=null&&s.hasScheduledInstant)&&!!(s!=null&&s.scheduledDateLabel||s!=null&&s.scheduledTimeLabel)}function za({onReassign:s,onView:u,onCreateVisit:i,onVisitsChange:v,onShowCalendar:F,calendarTriggerRef:p}){const{userDoc:y,providerNetwork:W}=ht(),O=(W==null?void 0:W.hideLastProviderColumn)===!0,{branding:V}=We(),B=(V==null?void 0:V.accentColor)||ze,R=!!(y!=null&&y.email)&&y.email.endsWith("@labthree.org"),[q,I]=ds(),{openPatientProfile:b,buildPatientProfileHref:H}=Ft(),{visits:$,loading:j,error:d}=ms(y==null?void 0:y.providerNetworkId,"sync-visits-network-visits-table"),{providers:ie}=Vt(y==null?void 0:y.providerNetworkId,"sync-visits-network-table-providers"),[C,se]=a.useState([]),[_,U]=a.useState(""),[G,ne]=a.useState([]),[ae,he]=a.useState([]),[re,Z]=a.useState([]),[A,n]=a.useState(void 0),[N,h]=a.useState([]),[w,S]=a.useState([]),[K,D]=a.useState(null),[oe,de]=a.useState(null),[ce,ge]=a.useState(null),[me,J]=a.useState(ts),{busyKey:le,openPatientConversationForRecord:Y,openClientConversationForRecord:t}=xa();a.useEffect(()=>{if(d){console.error("Error listening to visits:",d),te.error("Unable to load visits. Please try again."),se([]),v==null||v([]);return}const l=$.filter(g=>!Va(g));l.sort((g,X)=>(bt(X)||0)-(bt(g)||0)),se(l),v==null||v(l)},[$,d,v]);const o=da(a.useMemo(()=>C.map(l=>l.clientId),[C])),x=a.useMemo(()=>{const l=Pe();return C.map(g=>ma(o,g)).map(g=>({...g,patientNameSort:(g.patientName||"").toLowerCase(),providerNameSort:(g.providerName||"").toLowerCase(),clientNameSort:Ye(g,"").toLowerCase(),visitTypeSort:(g.visitType||"").toLowerCase(),statusSort:Qt(g).map(X=>X.label).join(" ").toLowerCase(),scheduledAtSort:bt(g)||0,lastProviderSort:Xt(g).toLowerCase(),scheduledDateLabel:dt(g,l),scheduledTimeLabel:ct(g,l),hasScheduledInstant:ks(g)}))},[o,C]),r=a.useMemo(()=>x.filter(l=>{if(_.trim()){const g=_.toLowerCase(),X=l.patientName||"",ke=l.providerName||"",je=l.visitType||"";if(!(X.toLowerCase().includes(g)||ke.toLowerCase().includes(g)||je.toLowerCase().includes(g)||[l.id,l.userId,l.patientId,l.providerId,l.clientId,l.businessId,l.providerNetworkId].some(Ee=>String(Ee||"").toLowerCase().includes(g))))return!1}if(!qs(l,{visitStatusFilters:G,clinicalOutcomeFilters:ae,fulfillmentFilters:re}))return!1;if(A!=null&&A.from){if(!l.scheduledAtSort)return!1;const g=new Date(A.from);g.setHours(0,0,0,0);const X=new Date(A.to||A.from);if(X.setHours(23,59,59,999),l.scheduledAtSort<g.getTime()||l.scheduledAtSort>X.getTime())return!1}return!(N.length>0&&!N.includes(l.providerId)||w.length>0&&!w.includes(l.clientId))}),[x,_,G,ae,re,A,N,w]),{sortedData:P,sortKey:T,sortDirection:M,handleSort:fe}=Lt(r,"scheduledAtSort","desc"),Ne=P;a.useEffect(()=>{J(ts)},[_,G,ae,re,A,N,w,T,M]);const qe=a.useMemo(()=>
1Ne.slice(0,me),[Ne,me]),ft=Math.max(Ne.length-qe.length,0),c=a.useRef(null),k=a.useCallback(()=>{J(l=>Math.min(l+Ta,Ne.length))},[Ne.length]),m=a.useMemo(()=>ie.map(l=>({id:l.id,label:l.displayName||l.fullName||"Unknown"})),[ie]),f=a.useMemo(()=>{const l=new Map;return C.forEach(g=>{g.clientId&&!l.has(g.clientId)&&l.set(g.clientId,Ye(g,"Unknown Client"))}),Array.from(l,([g,X])=>({id:g,label:X}))},[C]),L=a.useMemo(()=>Gs(C),[C]),z=a.useMemo(()=>Zs(C),[C]),pe=a.useMemo(()=>Js(C),[C]),xe=!!_||G.length>0||ae.length>0||re.length>0||!!(A!=null&&A.from)||N.length>0||w.length>0;function be(){U(""),ne([]),he([]),Z([]),n(void 0),h([]),S([])}async function ye(l){await Ss({visit:l,setResendingVisitId:de})}function De(l,g){if(!g)return;const X=new URLSearchParams(q);X.set(l,g),I(X)}return e.jsxs(st,{className:"rounded-xl border border-subtle dark:bg-slate-800 overflow-hidden",children:[e.jsxs("div",{className:"bg-surface-sunken border-b border-subtle p-4 max-lg:p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3 max-lg:mb-2 max-lg:flex-nowrap max-lg:gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 max-lg:min-w-0 max-lg:gap-1.5",children:[e.jsx("div",{className:"p-1.5 bg-blue-100 dark:bg-blue-900/30 rounded-lg max-lg:shrink-0 max-lg:p-1",children:e.jsx(Ue,{className:"size-4 text-blue-600 dark:text-blue-400 max-lg:size-3"})}),e.jsxs("div",{className:"max-lg:min-w-0",children:[e.jsx("h2",{className:"text-sm font-semibold text-content-primary max-lg:truncate max-lg:text-xs",children:"Network Visits"}),e.jsxs("p",{className:"text-xs text-content-tertiary max-lg:text-3xs max-lg:leading-tight",children:[r.length," of ",C.length]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 max-lg:shrink-0 max-lg:gap-1 max-lg:overflow-x-auto max-lg:[&_button]:h-7 max-lg:[&_button]:min-h-7 max-lg:[&_button]:min-w-0 max-lg:[&_button]:shrink-0 max-lg:[&_button]:gap-1 max-lg:[&_button]:px-2 max-lg:[&_button]:text-3xs max-lg:[&_svg]:h-3 max-lg:[&_svg]:w-3",children:[e.jsx(gt,{feature:"network-visits",tenantSlug:V==null?void 0:V.businessName,view:{getRows:()=>Ne},rawExport:{getRows:()=>fs(Ne,C)},allData:{mode:"client",getRows:()=>x},columns:[{header:"Scheduled",csvValue:l=>ss(l)?`${yt(l)} (Requested time)`:yt(l)},{header:"Patient",csvValue:l=>Ie(l,"Unknown")},{header:"Assigned To",csvValue:l=>jt(l,"Unassigned")},{header:"Client",csvValue:l=>Ye(l,"Unknown")},{header:"Product",csvValue:l=>ut(l,"Visit")},{header:"Duration",csvValue:l=>`${l.duration||30} min`},{header:"Status",csvValue:l=>Qt(l).map(g=>g.label).join("; ")},{header:"Last Provider",csvValue:l=>ia(l)}].filter(l=>!O||l.header!=="Last Provider")}),F&&e.jsxs(Q,{ref:p,type:"button",variant:"outline",size:"sm",className:"h-8 gap-1.5 rounded-full px-3 text-xs",onClick:F,"data-testid":"button-network-visits-show-calendar",children:[e.jsx(Ue,{className:"size-3.5","aria-hidden":"true"}),"Show calendar"]}),i&&e.jsxs(Q,{type:"button",size:"sm",className:"h-8 gap-1.5 px-3 text-xs font-medium text-white",style:{backgroundColor:B},onClick:i,children:[e.jsx(kt,{className:"size-3.5"}),"Create Visit"]})]})]}),e.jsxs("div",{className:"relative mb-3 max-lg:mb-2",children:[e.jsx(pt,{className:"absolute left-2 top-1/2 size-3 -translate-y-1/2 text-slate-400"}),e.jsx(we,{placeholder:"Search visitsâ¦",value:_,onChange:l=>U(l.target.value),className:"pl-7 h-8 text-xs dark:bg-slate-700 dark:border-slate-600 max-lg:h-7"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 max-lg:flex-nowrap max-lg:gap-1 max-lg:overflow-x-auto max-lg:pb-0.5 max-lg:[&>*]:shrink-0 max-lg:[&_.relative.inline-flex.rounded-full]:min-h-7 max-lg:[&_.relative.inline-flex.rounded-full]:min-w-0 max-lg:[&_.relative.inline-flex.rounded-full>button]:min-h-7 max-lg:[&_.relative.inline-flex.rounded-full>button]:px-2 max-lg:[&_.relative.inline-flex.rounded-full>button]:py-0 max-lg:[&_.relative.inline-flex.rounded-full>button]:text-3xs max-lg:[&_button]:h-7 max-lg:[&_button]:min-h-7 max-lg:[&_button]:min-w-0 max-lg:[&_button]:px-2 max-lg:[&_button]:text-3xs",children:[e.jsx(_e,{filters:L,activeFilters:G,onFilterChange:ne,defaultLabel:"Visit status"}),e.jsx(_e,{filters:z,activeFilters:ae,onFilterChange:he,defaultLabel:"Clinical outcome"}),e.jsx(_e,{filters:pe,activeFilters:re,onFilterChange:Z,defaultLabel:"Fulfillment"}),m.length>0&&e.jsx(_e,{filters:m,activeFilters:N,onFilterChange:h,defaultLabel:"All providers",searchable:!0}),f.length>1&&e.jsx(_e,{filters:f,activeFilters:w,onFilterChange:S,defaultLabel:"All clients",searchable:!0}),e.jsx(aa,{date:A,setDate:n,label:"Scheduled date"}),xe&&e.jsx(Q,{variant:"ghost",size:"sm",onClick:be,className:"h-7 px-2 text-2xs font-semibold uppercase tracking-wider text-content-tertiary hover:text-slate-900 dark:hover:text-slate-200",children:"Clear all"})]})]}),e.jsxs("div",{ref:c,className:"overflow-x-auto overflow-y-auto max-h-[600px] max-lg:max-h-[60dvh] max-lg:min-w-0",children:[j?e.jsx("div",{className:"flex items-center justify-center py-12 max-lg:py-6",children:e.jsx(mt,{className:"size-8 animate-spin text-blue-600 max-lg:size-5"})}):Ne.length===0?e.jsx("div",{className:"p-8 sm:p-12 text-center max-lg:p-4",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 max-lg:gap-1.5",children:[e.jsx("div",{className:"size-16 rounded-full bg-slate-100 dar
1k:bg-slate-700 flex items-center justify-center max-lg:size-10",children:e.jsx(Ue,{className:"size-8 text-slate-400 dark:text-slate-500 max-lg:size-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-content-primary max-lg:text-sm",children:xe?"No matching visits found":"No visits"}),e.jsx("p",{className:"mt-1 text-sm text-content-secondary max-lg:mt-0.5 max-lg:text-xs",children:xe?"Try adjusting your search or filters":"Visits will appear here"})]})]})}):e.jsxs(Rt,{className:"table-fixed min-w-[1160px] max-lg:min-w-[1020px]",children:[e.jsx(At,{children:e.jsxs(Ke,{className:"hover:bg-transparent dark:border-slate-700",children:[e.jsx(ue,{sortKey:"scheduledAtSort",currentSortKey:T,currentSortDirection:M,onSort:fe,className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised w-[170px]",children:"Scheduled"}),e.jsx(ue,{sortKey:"patientNameSort",currentSortKey:T,currentSortDirection:M,onSort:fe,className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised w-[230px]",children:"Patient"}),e.jsx(ue,{sortKey:"providerNameSort",currentSortKey:T,currentSortDirection:M,onSort:fe,className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised w-[120px]",children:"Assigned To"}),e.jsx(ue,{sortKey:"clientNameSort",currentSortKey:T,currentSortDirection:M,onSort:fe,className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised w-[140px]",children:"Client"}),e.jsx(ue,{sortKey:"visitTypeSort",currentSortKey:T,currentSortDirection:M,onSort:fe,className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised w-[140px]",children:"Product"}),e.jsx(ue,{sortKey:"duration",currentSortKey:T,currentSortDirection:M,onSort:fe,className:"text-xs py-2 text-center dark:text-slate-300 sticky top-0 bg-surface-raised z-raised w-[90px]",children:"Duration"}),e.jsx(ue,{sortKey:"statusSort",currentSortKey:T,currentSortDirection:M,onSort:fe,className:"text-xs py-2 text-center dark:text-slate-300 sticky top-0 bg-surface-raised z-raised w-[120px]",children:"Status"}),!O&&e.jsx(ue,{sortKey:"lastProviderSort",currentSortKey:T,currentSortDirection:M,onSort:fe,className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised w-[130px]",children:"Last Provider"}),e.jsx(Oe,{className:"text-xs py-2 text-center dark:text-slate-300 sticky top-0 bg-surface-raised z-raised w-[90px]",children:"Actions"})]})}),e.jsx(Mt,{children:qe.map(l=>{const g=()=>{D(null),u==null||u(l)},X=()=>{D(null),s==null||s(l)},ke=Cs(l.status),je=oe===l.id,Ge=async()=>{D(null),await ye(l)},Ee=()=>{D(null),ge({id:l.id,label:l.id})},Ze=()=>{D(null),Y(l)},at=()=>{D(null),t(l)};return e.jsxs(ea,{children:[e.jsx(ta,{asChild:!0,children:e.jsxs(Ke,{className:`hover:bg-slate-50 dark:hover:bg-slate-700/50 dark:border-slate-700 ${u?"cursor-pointer":""}`,onClick:u?g:void 0,children:[e.jsx(ee,{className:"py-2 w-[170px]",children:e.jsxs("div",{className:"text-xs text-content-secondary max-lg:text-2xs max-lg:leading-tight",children:[e.jsx("div",{children:yt(l)}),ss(l)?e.jsx("div",{className:"mt-0.5 uppercase tracking-wide text-3xs text-amber-600 dark:text-amber-400",children:"Requested time"}):null]})}),e.jsx(ee,{className:"py-2",children:e.jsxs("div",{className:"flex items-center gap-2 min-w-0 max-lg:gap-1.5",children:[e.jsx("div",{className:"size-7 rounded-md bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center text-3xs font-semibold text-blue-700 dark:text-blue-300 flex-shrink-0 max-lg:size-5 max-lg:rounded",children:Ia(l)}),e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[l.userId?e.jsx(tt,{name:Ie(l,"Unknown"),patientId:l.userId,onOpen:b,href:H(l.userId),highlight:_,className:"block w-full text-left text-sm font-medium max-lg:text-2xs"}):e.jsx(tt,{name:Ie(l,"Unknown"),highlight:_,className:"block w-full text-left text-sm font-medium max-lg:text-2xs"}),e.jsx(ps,{visit:l})]})]})}),e.jsx(ee,{className:"py-2 w-[120px]",children:l.providerId?e.jsx("button",{type:"button",onClick:ve=>{ve.stopPropagation(),De("user",l.providerId)},className:"text-xs text-content-secondary truncate block hover:text-blue-600 dar
1k:hover:text-blue-400 hover:underline text-left w-full max-lg:text-2xs",children:e.jsx(Be,{text:jt(l,"Unassigned"),highlight:_})}):e.jsx("span",{className:"text-xs text-content-secondary truncate block max-lg:text-2xs",children:e.jsx(Be,{text:jt(l,"Unassigned"),highlight:_})})}),e.jsx(ee,{className:"py-2",children:l.clientId?e.jsx("button",{type:"button",onClick:ve=>{ve.stopPropagation(),De("client",l.clientId)},className:"text-left",children:e.jsx($t,{accentColor:l.clientAccentColor||ze,className:"max-w-[120px] truncate hover:opacity-90 max-lg:max-w-[96px] max-lg:px-1.5",children:Ye(l,"Unknown")})}):e.jsx($t,{accentColor:l.clientAccentColor||ze,className:"max-w-[120px] truncate max-lg:max-w-[96px] max-lg:px-1.5",children:Ye(l,"Unknown")})}),e.jsx(ee,{className:"py-2",children:e.jsx("span",{className:"text-xs text-content-secondary truncate block max-lg:text-2xs",children:e.jsx(Be,{text:ut(l,"Visit"),highlight:_})})}),e.jsx(ee,{className:"text-center py-2",children:e.jsxs("span",{className:"text-xs text-content-secondary max-lg:text-2xs",children:[l.duration||30," min"]})}),e.jsx(ee,{className:"text-center py-2",children:e.jsx(ra,{visit:l,highlight:_,className:"max-lg:px-1.5 max-lg:text-3xs max-lg:leading-tight"})}),!O&&e.jsx(ee,{className:"py-2",children:e.jsx("span",{className:"text-xs text-content-secondary",children:Xt(l)})}),e.jsx(ee,{className:"text-center py-2",onClick:ve=>ve.stopPropagation(),children:(u||s||ke)&&e.jsxs(zt,{open:K===l.id,onOpenChange:ve=>D(ve?l.id:null),children:[e.jsx(Dt,{asChild:!0,children:e.jsx(Q,{size:"sm",variant:"outline",className:"size-7 p-0 dark:border-slate-600 dark:hover:bg-slate-700 max-lg:size-6",onClick:ve=>ve.stopPropagation(),children:e.jsx(ua,{className:"size-3"})})}),e.jsx(Et,{className:"w-40 p-0",align:"end",children:e.jsxs("div",{className:"bg-surface-raised border border-subtle rounded-lg shadow-lg",children:[u&&e.jsxs("button",{type:"button",onClick:g,className:"w-full px-4 py-2 text-left text-sm hover:bg-blue-50 hover:text-blue-600 border-b border-slate-100 dark:hover:bg-slate-700 dark:text-slate-100 dark:border-slate-700 flex items-center gap-2 max-lg:gap-1.5 max-lg:px-3 max-lg:py-1.5 max-lg:text-xs",children:[e.jsx(Ot,{className:"size-3.5"}),"View"]}
1),R&&e.jsxs("button",{type:"button",onClick:Ee,className:"w-full px-4 py-2 text-left text-sm hover:bg-blue-50 hover:text-blue-600 border-b border-slate-100 dark:hover:bg-slate-700 dark:text-slate-100 dark:border-slate-700 flex items-center gap-2 max-lg:gap-1.5 max-lg:px-3 max-lg:py-1.5 max-lg:text-xs",children:[e.jsx(Ut,{className:"size-3.5"}),"View transcript"]}),s&&e.jsxs("button",{type:"button",onClick:X,className:"w-full px-4 py-2 text-left text-sm hover:bg-blue-50 hover:text-blue-600 flex items-center gap-2 dark:hover:bg-slate-700 dark:text-slate-100 dark:border-slate-700 max-lg:gap-1.5 max-lg:px-3 max-lg:py-1.5 max-lg:text-xs",children:[e.jsx(es,{className:"size-3.5"}),"Reassign"]}),(l.patientId||l.userId)&&e.jsxs("button",{type:"button",onClick:Ze,disabled:!!le,className:"flex w-full items-center gap-2 border-t border-slate-100 px-4 py-2 text-left text-sm hover:bg-blue-50 hover:text-blue-600 disabled:cursor-not-allowed disabled:opacity-60 dark:border-slate-700 dark:text-slate-100 dark:hover:bg-slate-700 max-lg:gap-1.5 max-lg:px-3 max-lg:py-1.5 max-lg:text-xs",children:[le===`patient:${l.patientId||l.userId}`?e.jsx($e,{size:"sm"}):e.jsx(Bt,{className:"size-3.5"}),"Message patient"]}),l.clientId&&e.jsxs("button",{type:"button",onClick:at,disabled:!!le,className:"flex w-full items-center gap-2 px-4 py-2 text-left text-sm hover:bg-blue-50 hover:text-blue-600 disabled:cursor-not-allowed disabled:opacity-60 dark:text-slate-100 dark:hover:bg-slate-700 max-lg:gap-1.5 max-lg:px-3 max-lg:py-1.5 max-lg:text-xs",children:[le===`client:${l.clientId}`?e.jsx($e,{size:"sm"}):e.jsx(Ht,{className:"size-3.5"}),"Message client group"]}),ke&&e.jsxs("button",{type:"button",onClick:Ge,disabled:je,className:"w-full px-4 py-2 text-left text-sm hover:bg-blue-50 hover:text-blue-600 flex items-center gap-2 dark:hover:bg-slate-700 dark:text-slate-100 dark:border-slate-700 disabled:opacity-60 disabled:cursor-not-allowed max-lg:gap-1.5 max-lg:px-3 max-lg:py-1.5 max-lg:text-xs",children:[je?e.jsx($e,{size:"sm"}):e.jsx(Kt,{className:"size-3.5"}),je?"Sendingâ¦":"Resend scheduling email"]})]})})]})})]})}),e.jsxs(sa,{className:"w-48",children:[u&&e.jsxs(Le,{onClick:g,className:"gap-2",children:[e.jsx(Ot,{className:"size-3.5"}),e.jsx("span",{children:"View"})]}),R&&e.jsxs(Le,{onClick:Ee,className:"gap-2",children:[e.jsx(Ut,{className:"size-3.5"}),e.jsx("span",{children:"View transcript"})]}),s&&e.jsxs(Le,{onClick:X,className:"gap-2",children:[e.jsx(es,{className:"size-3.5"}),e.jsx("span",{children:"Reassign"})]}),(l.patientId||l.userId)&&e.jsxs(Le,{onClick:Ze,disabled:!!le,className:"gap-2",children:[e.jsx(Bt,{className:"size-3.5"}),e.jsx("span",{children:"Message patient"})]}),l.clientId&&e.jsxs(Le,{onClick:at,disabled:!!le,className:"gap-2",children:[e.jsx(Ht,{className:"size-3.5"}),e.jsx("span",{children:"Message client group"})]}),ke&&e.jsxs(Le,{onClick:Ge,disabled:je,className:"gap-2",children:[je?e.jsx($e,{size:"sm"}):e.jsx(Kt,{className:"size-3.5"}),e.jsx("span",{children:je?"Sendingâ¦":"Resend scheduling email"})]})]})]},l.id)})})]}),e.jsx(Xs,{hasMore:ft>0,loading:j,rootRef:c,progressKey:qe.length,onLoadMore:k})]}),R&&e.jsx(ca,{open:!!ce,onOpenChange:l=>{l||ge(null)},visitId:(ce==null?void 0:ce.id)??null,visitLabel:(ce==null?void 0:ce.label)??null})]})}const lt=80;function Da(s,u){if(!s||s.unavailable)return null;if(s.startAt&&s.endAt){const F=xt(s.startAt),p=xt(s.endAt);return!F||!p?null:{startDate:F,endDate:p,date:Te(F,u,"yyyy-MM-dd"),startTime:Te(F,u,"HH:mm"),endTime:Te(p,u,"HH:mm")}}if(!s.date||!s.startTime||!s.endTime)return null;const i=new Date(`${s.date}T${s.startTime}:00`),v=new Date(`${s.date}T${s.endTime}:00`);return Number.isNaN(i.getTime())||Number.isNaN(v.getTime())?null:{startDate:i,endDate:v,date:s.date,startTime:s.startTime,endTime:s.endTime}}function Ea(s){return String((s==null?void 0:s.visitMode)||(s==null?void 0:s.visitSource)||"").trim().toLowerCase()==="async"||String((s==null?void 0:s.visitSource)||"").trim().toLowerCase()==="async_visit"}function as(s){return(s==null?void 0:s.displayName)||(s==null?void 0:s.fullName)||"Unknown"}function Ra({onManageSchedule:s}){const{userDoc:u}=ht(),{branding:i}=We(),{openPatientProfile:v,buildPatientProfileHref:F}=Ft(),{providers:p,loading:y,error:W}=Vt(u==null?void 0:u.providerNetworkId,"sync-visits-active-providers"),{visits:O,error:V}=ms(u==null?void 0:u.providerNetworkId,"sync-visits-active-provider-visits"),B=a.useMemo(()=>O.filter(n=>!Ea(n)),[O]),[R,q]=a.useState({}),[I,b]=a.useState(""),[H,$]=a.useState(lt),j=a.useRef({}),d=a.useRef(null),ie=a.useCallback((n,N)=>{j.current[n]=N,!d.current&&(d.current=window.requestAnimationFrame(()=>{d.current=null;const h=j.current;j.current={},q(w=>({...w,...h}))}))},[]);a.useEffect(()=>()=>{d.current&&window.cancelAnimationFrame(d.current)},[]),a.useEffect(()=>{W&&te.error("Unable to load providers. Please try again.")},[W]),a.useEffect(()=>{V&&te.error("Unable to load provider visits. Please try again.")},[V]);const C=a.useMemo(()=>p.map(n=>
1n.id).filter(Boolean),[p]);a.useEffect(()=>{if(C.length===0){q({});return}q(N=>{const h={};return C.forEach(w=>{N[w]&&(h[w]=N[w])}),h});const n=C.map(N=>nt(Ct(`Users:Hours@provider:${N}`,()=>He(Ce,"Users",N,"Hours"),{next:h=>{const w=h.docs.filter(S=>S.id!=="default").map(S=>({id:S.id,...S.data()}));ie(N,w)},error:h=>{console.error(`Error loading availability for provider ${N}:`,h),ie(N,[])}}),"sync-visits-active-provider-hours"));return()=>n.forEach(N=>N())},[C,ie]);const se=a.useMemo(()=>{const n=new Date,N=Ps(n,"yyyy-MM-dd"),h=Pe(),w=new Map;return B.forEach(S=>{if(!S.providerId)return;let K=w.get(S.providerId);if(K||(K={inProgressVisit:null,todaysVisits:[],nextVisitData:null},w.set(S.providerId,K)),S.status==="In Progress"&&!K.inProgressVisit&&(K.inProgressVisit=S),(S.status==="Confirmed"||S.status==="In Progress")&&dt(S,h)===N){const D=St(S);K.todaysVisits.push({visit:S,start:D,startTime:(D==null?void 0:D.getTime())||0})}}),w.forEach(S=>{var K;S.todaysVisits.sort((D,oe)=>D.startTime-oe.startTime),S.nextVisitData=((K=S.todaysVisits.find(({start:D})=>D&&D>n))==null?void 0:K.visit)||null,S.todaysVisits=S.todaysVisits.map(({visit:D})=>D)}),{summaries:w,today:N,tz:h}},[B]),_=a.useMemo(()=>{const{summaries:n,today:N,tz:h}=se;return p.map(w=>{const S=n.get(w.id)||{},K=S.inProgressVisit||null,D=S.todaysVisits||[],oe=(R[w.id]||[]).map(Y=>Da(Y,h)).filter(Y=>Y&&Y.date===N);let de=null,ce=null;if(oe.length>0){const Y=oe.reduce((o,x)=>!o||x.startDate<o?x.startDate:o,null),t=oe.reduce((o,x)=>!o||x.endDate>o?x.endDate:o,null);de=Y?Te(Y,h,"HH:mm"):null,ce=t?Te(t,h,"HH:mm"):null}let ge="Available",me=null,J=null,le=null;if(K)ge="In a Visit",me=Ie(K,"Patient"),J=K.userId||K.patientId||null;else if(D.length>0){const Y=S.nextVisitData||null;if(Y){const t=St(Y);le={time:t?Te(t,h,"HH:mm"):ct(Y,h),patient:Ie(Y,"Patient"),patientId:Y.userId||Y.patientId||null}}}return{...w,status:ge,currentPatient:me,currentPatientId:J,nextVisit:le,appointmentsToday:D.length,scheduleStart:de,scheduleEnd:ce,todaysVisits:D}})},[p,se,R]),U=_.filter(n=>{if(I.trim()){const N=I.toLowerCase(),h=n.displayName||n.fullName||"",w=(n.specialties||[]).join(" ");return h.toLowerCase().includes(N)||w.toLowerCase().includes(N)||String(n.id||"").toLowerCase().includes(N)}return!0}),{sortedData:G,sortKey:ne,sortDirection:ae,handleSort:he}=Lt(U,"displayName","asc");a.useEffect(()=>{$(lt)},[I,ne,ae]);const re=a.useMemo(()=>G.slice(0,H),[G,H]),Z=Math.max(G.length-re.length,0),A=Math.min(lt,Z);return e.jsxs(st,{className:"rounded-xl border border-subtle dark:bg-slate-800 overflow-hidden",children:[e.jsxs("div",{className:"bg-surface-sunken border-b border-subtle p-4 max-lg:p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3 max-lg:mb-2 max-lg:flex-nowrap max-lg:gap-1.5 max-lg:[&>*:last-child]:shrink-0 max-lg:[&_button]:h-7 max-lg:[&_button]:min-h-7 max-lg:[&_button]:min-w-0 max-lg:[&_button]:shrink-0 max-lg:[&_button]:gap-1 max-lg:[&_button]:px-2 max-lg:[&_button]:text-3xs max-lg:[&_button_svg]:h-3 max-lg:[&_button_svg]:w-3",children:[e.jsxs("div",{className:"flex items-center gap-2 max-lg:min-w-0 max-lg:gap-1.5",children:[e.jsx("div",{className:"p-1.5 bg-purple-100 dark:bg-purple-900/30 rounded-lg max-lg:shrink-0 max-lg:p-1",children:e.jsx(Ve,{className:"size-4 text-purple-600 dark:text-purple-400 max-lg:size-3"})}),e.jsxs("div",{className:"max-lg:min-w-0",children:[e.jsx("h2",{className:"text-sm font-semibold text-content-primary max-lg:truncate max-lg:text-xs",children:"Active Providers"}),e.jsxs("p",{className:"text-xs text-content-tertiary max-lg:text-3xs max-lg:leading-tight",children:[U.length," of ",p.length]})]})]}),e.jsx(gt,{feature:"active-providers",tenantSlug:i==null?void 0:i.businessName,view:{getRows:()=>G},rawExport:{resolveRows:n=>la({rows:n,collectionPath:["Users"]})},allData:{mode:"client",getRows:()=>_},columns:[{header:"Provider",csvValue:n=>as(n)},{header:"Status",csvValue:n=>n.status},{header:"Today's Schedule",csvValue:n=>n.scheduleStart&&n.scheduleEnd?`${Ae(n.scheduleStart)} - ${Ae(n.scheduleEnd)}`:"No schedule"},{header:"Appointments Today",csvValue:n=>n.appointmentsToday},{header:"Current Visit",csvValue:n=>n.currentPatient||"â"},{header:"Next Visit",csvValue:n=>n.nextVisit?`${Ae(n.nextVisit.time)}
1 ${n.nextVisit.patient}`:"â"}]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(pt,{className:"absolute left-2 top-1/2 size-3 -translate-y-1/2 text-slate-400"}),e.jsx(we,{placeholder:"Search providersâ¦",value:I,onChange:n=>b(n.target.value),className:"pl-7 h-8 text-xs dark:bg-slate-700 dark:border-slate-600 max-lg:h-7"})]})]}),e.jsx("div",{className:"overflow-x-auto overflow-y-auto max-h-[600px] max-lg:max-h-[60dvh] max-lg:min-w-0",children:y?e.jsx("div",{className:"flex items-center justify-center py-12 max-lg:py-6",children:e.jsx(mt,{className:"size-8 animate-spin text-blue-600 max-lg:size-5"})}):G.length===0?e.jsx("div",{className:"p-8 sm:p-12 text-center max-lg:p-4",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 max-lg:gap-1.5",children:[e.jsx("div",{className:"size-16 rounded-full bg-slate-100 dark:bg-slate-700 flex items-center justify-center max-lg:size-10",children:e.jsx(Ve,{className:"size-8 text-slate-400 dark:text-slate-500 max-lg:size-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-content-primary max-lg:text-sm",children:I?"No matching providers found":"No providers"}),e.jsx("p",{className:"mt-1 text-sm text-content-secondary max-lg:mt-0.5 max-lg:text-xs",children:I?"Try adjusting your search":"Providers will appear here"})]})]})}):e.jsxs(e.Fragment,{children:[e.jsxs(Rt,{children:[e.jsx(At,{children:e.jsxs(Ke,{className:"hover:bg-transparent dark:border-slate-700",children:[e.jsx(ue,{sortKey:"displayName",currentSortKey:ne,currentSortDirection:ae,onSort:he,className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Provider"}),e.jsx(ue,{sortKey:"status",currentSortKey:ne,currentSortDirection:ae,onSort:he,className:"text-xs py-2 text-center dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Status"}),e.jsx(Oe,{className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Today's Schedule"}),e.jsx(ue,{sortKey:"appointmentsToday",currentSortKey:ne,currentSortDirection:ae,onSort:he,className:"text-xs py-2 text-center dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Appointments Today"}),e.jsx(Oe,{className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Current Visit"}),e.jsx(Oe,{className:"text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Next Visit"}),e.jsx(Oe,{className:"text-xs py-2 text-center dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Actions"})]})}),e.jsx(Mt,{children:re.map(n=>{var N,h;return e.jsxs(Ke,{className:"hover:bg-slate-50 dark:hover:bg-slate-700/50 dark:border-slate-700",children:[e.jsx(ee,{className:"py-2",children:e.jsxs("div",{className:"flex items-center gap-2 min-w-0 max-lg:gap-1.5",children:[e.jsx("div",{className:"size-8 rounded-full bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center text-purple-600 dark:text-purple-400 font-semibold text-xs flex-shrink-0 max-lg:size-6 max-lg:text-3xs",children:((h=(N=n.displayName)==null?void 0:N[0])==null?void 0:h.toUpperCase())||"P"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium text-content-primary text-sm truncate block max-lg:text-2xs",children:e.jsx(Be,{text:as(n),highlight:I})}),n.specialties&&n.specialties.length>0&&e.jsx("span",{className:"text-xs text-content-tertiary truncate block max-lg:text-3xs",children:n.specialties.join(", ")})]})]})}),e.jsx(ee,{className:"text-center py-2",children:e.jsx(et,{variant:"outline",className:`text-xs border max-lg:px-1.5 max-lg:text-3xs max-lg:leading-tight ${n.status==="In a Visit"?"bg-emerald-50 text-emerald-600 border-emerald-200 dark:bg-emerald-900/30 dark:text-emerald-400 dark:border-emerald-800":"bg-slate-50 text-slate-600 border-slate-200 dark:bg-slate-800/50 dark:text-slate-400 dark:border-slate-600"}`,children:n.status})}),e.jsx(ee,{className:"py-2",children:n.scheduleStart&&n.scheduleEnd?e.jsxs("div",{className:"flex items-center gap-1 text-xs text-content-secondary max-lg:text-2xs",children:[e.jsx(xs,{className:"size-3 max-lg:size-2.5"}),e.jsxs("span",{children:[Ae(n.scheduleStart)," - ",Ae(n.scheduleEnd)]})]}):e.jsx("span",{className:"text-xs text-slate-400 dark:text-slate-500 max-lg:text-2xs",children:"No schedule"})}),e.jsx(ee,{className:"text-center py-2",children:e.jsx("span",{className:"text-xs font-medium text-content-primary max-lg:text-2xs",children:n.appointmentsToday})}),e.jsx(ee,{className:"py-2",children:n.currentPatient?e.jsxs("div",{className:"flex items-center gap-1 text-xs text-content-secondary max-lg:text-2xs",children:[e.jsx(us,{className:"size-3 max-lg:size-2.5"}),e.jsx(tt,{name:n.currentPatient,patientId:n.currentPatientId,onOpen:v,href:F(n.currentPatientId),className:"text-xs text-content-secondary max-lg:text-2xs"})]}):e.jsx("span",{className:"text-xs text-slate-400 dark:text-slate-500 max-lg:text-2xs",children:"â"})}),e.jsx(ee,{className:"py-2",children:n.nextVisit?e.jsxs("div",{className:"text-xs text-content-secondary max-lg:text-2xs max-lg:leading-tight",children:[e.jsx("div",{className:"font-medium",children:Ae(n.nextVisit.time)}
1),e.jsx(tt,{name:n.nextVisit.patient,patientId:n.nextVisit.patientId,onOpen:v,href:F(n.nextVisit.patientId),className:"block text-xs text-content-tertiary max-lg:text-2xs"})]}):e.jsx("span",{className:"text-xs text-slate-400 dark:text-slate-500 max-lg:text-2xs",children:"â"})}),e.jsx(ee,{className:"text-center py-2",children:s&&e.jsxs(Q,{size:"sm",variant:"outline",className:"h-7 px-2 text-xs dark:border-slate-600 dark:hover:bg-slate-700 max-lg:h-6 max-lg:px-1.5 max-lg:text-3xs",onClick:()=>s(n),children:[e.jsx(bs,{className:"size-3 mr-1 max-lg:mr-0.5 max-lg:size-2.5"}),"Schedule"]})})]},n.id)})})]}),Z>0?e.jsx("div",{className:"flex justify-center border-t border-subtle p-3 max-lg:p-2",children:e.jsxs(Q,{variant:"outline",size:"sm",className:"h-8 rounded-full px-4 text-xs dark:border-slate-600 dark:hover:bg-slate-700 max-lg:h-7 max-lg:px-2.5 max-lg:text-3xs",onClick:()=>$(n=>n+lt),children:["Show ",A," more"]})}):null]})})]})}function ls(s,u){if(!(s!=null&&s.providerId))return"Unassigned";const i=u.find(v=>v.id===s.providerId);return i?i.displayName||i.fullName||`Provider ${s.providerId.slice(0,8)}`:`Provider ${s.providerId.slice(0,8)}`}const Aa={"#2563eb":"#eff6ff","#7c3aed":"#f5f3ff","#db2777":"#fdf2f8","#dc2626":"#fef2f2","#ea580c":"#fff7ed","#ca8a04":"#fefce8","#16a34a":"#f0fdf4","#0891b2":"#ecfeff","#64748b":"#f1f5f9","#f59e0b":"#fffbeb","#ef4444":"#fef2f2"};function rt(s){return Aa[s]||"#eff6ff"}const rs=fa;function Ma(){return e.jsx("div",{className:"px-3 pt-2 pb-3 max-lg:px-1.5 max-lg:pt-1.5 max-lg:pb-2",children:e.jsxs("div",{className:"rounded-lg border border-subtle bg-surface-raised dark:bg-slate-900/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-4 py-3 max-lg:gap-1.5 max-lg:px-2 max-lg:py-2",children:[e.jsxs("div",{className:"flex gap-2 max-lg:gap-1",children:[e.jsx(Se,{className:"size-8 rounded-full max-lg:size-6"}),e.jsx(Se,{className:"size-8 rounded-full max-lg:size-6"}),e.jsx(Se,{className:"h-8 w-14 rounded-full max-lg:h-6 max-lg:w-10"})]}),e.jsx(Se,{className:"h-6 w-40 max-lg:h-4 max-lg:w-24"}),e.jsxs("div",{className:"flex gap-2 max-lg:gap-1",children:[e.jsx(Se,{className:"h-8 w-24 rounded-full max-lg:h-6 max-lg:w-14"}),e.jsx(Se,{className:"h-8 w-20 rounded-full max-lg:h-6 max-lg:w-12"})]})]}),e.jsx("div",{className:"grid grid-cols-7 gap-3 px-4 py-4 max-lg:gap-1 max-lg:px-2 max-lg:py-2",children:Array.from({length:7}).map((s,u)=>e.jsxs("div",{className:"space-y-3 max-lg:space-y-1.5",children:[e.jsx(Se,{className:"h-5 w-16 max-lg:h-3 max-lg:w-full"}),Array.from({length:7}).map((i,v)=>e.jsx(Se,{className:"h-14 w-full rounded-lg max-lg:h-8"},v))]},u))})]})})}function La({onSelectVisit:s,onRescheduleVisit:u,fullWidth:i=!1,selectedProviderIds:v=[],providerColors:F,allProviders:p=[],providerNetworkId:y=null,networkTimezone:W=null,visitsOverride:O=null}){const{branding:V}=We(),B=(V==null?void 0:V.accentColor)||ze,R=Ns(),[q,I]=ds(),{openPatientProfile:b,buildPatientProfileHref:H}=Ft(),[$,j]=a.useState(!1),[d,ie]=a.useState(null),[C,se]=a.useState(null),[_,U]=a.useState(!1),[G,ne]=a.useState(""),[ae,he]=a.useState(!1),re=a.useRef(null),Z=a.useRef(null),[A,n]=a.useState([]),[N,h]=a.useState({}),[w,S]=a.useState(null),[K,D]=a.useState(Pe()),[oe,de]=a.useState(!0),[ce,ge]=a.useState(new Date),me=Array.isArray(O),J=a.useMemo(()=>{if(F)return F;const c={};return p.forEach((k,m)=>{c[k.id]=rs[m%rs.length]}),c},[p,F]);a.useEffect(()=>{if(me){n(O),de(!1);return}if(!y){n([]),de(!1);return}de(!0),n([]);const c=nt(Ct(`Visits@pn:${y}`,()=>Tt(He(Ce,"Visits"),It("providerNetworkId","==",y)),{next:k=>{const m=k.docs.map(f=>({id:f.id,...f.data()})).filter(f=>f.visitMode!=="async");n(m),de(!1)},error:k=>{console.error("Error listening to visits:",k),de(!1)}}),"sync-visits-admin-calendar-visits");return()=>c()},[y,me,O]),a.useEffect(()=>{const c=Array.isArray(v)?v:[];if(c.length===0){h({});return}h({});const k=c.map(m=>nt(Ct(`Users:Hours@provider:${m}`,()=>He(Ce,"Users",m,"Hours"),{next:f=>{const L=f.docs.filter(z=>z.id!=="default").map(z=>({id:z.id,...z.data()}));h(z=>({...z,[m]:L}))},error:f=>{console.error(`Error listening to availability for provider ${m}:`,f)}}),`sync-visits-admin-provider-hours-${m}`));return()=>k.forEach(m=>m())},[v]),a.useEffect(()=>{if(!y){S(null);return}const c=Xe(Ce,"ProviderNetworks",y,"Hours","default"),k=nt(hs(c,m=>{m.exists()?S(m.data().schedule||null):S(null)},m=>{console.error("Error listening to network hours:",m)}),"sync-visits-admin-network-hours");return()=>k()},[y]),a.useEffect(()=>{const c=String(W||"").trim();D(c||Pe())},[W]);const le=a.useMemo(()=>Ts(w,ce,K),[w,ce,K]),Y=a.useMemo(()=>{const c=Pe();return Object.entries(N).flatMap(([k,m])=>m.filter(f=>!f.unavailable).map((f,L)=>{try{const z=xt(f.startAt)||Wt(f.date,f.startTime,c),pe=xt(f.endAt)||Wt(f.date,f.endTime,c);if(!z||!pe||z>=pe)return null;const xe=Te(z,c,"HH:mm"),be=Te(pe,c,"HH:mm"),ye=J[k]||"#16a34a";return{id:`avail-${k}-${f.id||L}`,start:z,end:pe,display:"background",backgroundColor:rt(ye),classNames:["admin-provider-availability-block"],extendedProps:{providerId:k,startTime:xe,endTime:be}}}catch(z){return console.error("Error parsing availability block:",z,f),null}}
1).filter(Boolean))},[N,J]),t=a.useMemo(()=>{const c=A.map(m=>{try{const f=St(m),L=Is(m);if(!f||!L||f>=L)return null;const z=m.status==="Confirmed",pe=`${f.toISOString()}|${L.toISOString()}`;return{visit:m,startDate:f,endDate:L,isConfirmed:z,slotKey:pe}}catch(f){return console.error("Error parsing visit:",f,m),null}}).filter(Boolean),k=c.reduce((m,f)=>(f.isConfirmed&&(m[f.slotKey]=(m[f.slotKey]||0)+1),m),{});return c.map(({visit:m,startDate:f,endDate:L,isConfirmed:z,slotKey:pe})=>{try{const xe=z&&(k[pe]||0)>1;let be=J[m.providerId]||B,ye=z?be:rt(be),De=z?"#ffffff":"#0f172a";J[m.providerId]||(m.status==="Completed"?(be="#64748b",ye=z?"#64748b":"#f1f5f9"):m.status==="Pending Review"?(be="#f59e0b",ye=z?"#f59e0b":"#fffbeb"):m.status==="Cancelled"&&(be="#ef4444",ye=z?"#ef4444":"#fef2f2"));const l=Ie(m,"Patient"),g=m.preferredMethod==="video"?"ð¹":"ð",X=ls(m,p),ke=X?`${g} ${l} - ${X}`:`${g} ${l} - ${ut(m,"Visit")}`;return{id:m.id,title:ke,start:f,end:L,backgroundColor:ye,borderColor:xe?"#ffffff":z?ye:be,textColor:De,classNames:xe?["solid-overlap-event"]:[],extendedProps:{visit:m,providerName:X,hasSolidOverlap:xe}}}catch(xe){return console.error("Error parsing visit:",xe,m),null}}).filter(Boolean)},[A,B,J,p]),o=[...le,...Y,...t],{slotMinTime:x,slotMaxTime:r,contentHeight:P,scrollTime:T}=a.useMemo(()=>Ys(w,A),[w,A]),M=a.useMemo(()=>{var L,z;if(!w)return!1;const c=["monday","tuesday","wednesday","thursday","friday"],k=((L=w.saturday)==null?void 0:L.enabled)===!1,m=((z=w.sunday)==null?void 0:z.enabled)===!1,f=c.every(pe=>{var xe;return((xe=w[pe])==null?void 0:xe.enabled)===!0});return k&&m&&f},[w]),fe=a.useCallback(c=>{var m;const k=(m=c.event.extendedProps)==null?void 0:m.visit;k&&(se(c.el),ie(k),j(!0))},[]);a.useEffect(()=>{if(C&&Z.current){const c=C.getBoundingClientRect();Z.current.style.position="fixed",Z.current.style.left=`${c.left}px`,Z.current.style.top=`${c.bottom}px`,Z.current.style.width=`${c.width}px`,Z.current.style.height="0px"}},[C,$]);const Ne=a.useCallback(c=>{c!=null&&c.start&&ge(c.start)},[]);a.useEffect(()=>{const c=()=>{var L,z;return(z=(L=re.current)==null?void 0:L.getApi())==null?void 0:z.updateSize()},k=window.setTimeout(c,0),m=window.setTimeout(c,180),f=window.setTimeout(c,450);return()=>{window.clearTimeout(k),window.clearTimeout(m),window.clearTimeout(f)}},[oe,P,T,R.key]);const qe=a.useCallback(c=>{if(!c.event.classNames.includes("admin-provider-availability-block"))return;const{providerId:k,startTime:m,endTime:f}=c.event.extendedProps||{};if(!k||!m||!f)return;const L=J[k]||"#16a34a";c.el.style.borderLeft=`3px solid ${L}`},[J]),ft=a.useCallback(async()=>{var c;if(d!=null&&d.id)try{he(!0);const k=await((c=it.currentUser)==null?void 0:c.getIdToken());if(!k)throw new Error("Not authenticated");const m=Vs("manageVisit"),L=await(await fetch(m,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${k}`},body:JSON.stringify({action:"updateStatus",visitId:d.id,status:"Cancelled",cancellationReason:G.trim()})})).json();if(!(L!=null&&L.success))throw new Error((L==null?void 0:L.error)||"Unable to cancel visit. Please try again.");te.success("Visit cancelled successfully"),U(!1),ne(""),j(!1)}catch(k){console.error("Error cancelling visit:",k),te.error((k==null?void 0:k.message)||"Unable to cancel visit. Please try again.")}finally{he(!1)}},[d,G]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"min-w-0",children:e.jsxs(st,{className:`rounded-xl border border-subtle dark:bg-slate-800 overflow-hidden provider-calendar admin-weekly-calendar shadow-sm ${i?"w-full":""}`,style:{"--calendar-accent-color":B},children:[oe?e.jsx(Ma,{}):e.jsx("div",{className:"px-3 pt-2 pb-3 max-lg:px-1.5 max-lg:pt-1.5 max-lg:pb-2",children:e.jsx(ga,{ref:re,plugins:[ha,pa],initialView:"timeGridWeek",headerToolbar:{left:"prev,next today",center:"title",right:"timeGridWeek,timeGridDay"},slotMinTime:x,slotMaxTime:r,slotDuration:"00:30:00",slotLabelInterval:"01:00",allDaySlot:!1,nowIndicator:!0,editable:!1,selectable:!1,selectMirror:!1,dayMaxEvents:!1,eventMaxStack:3,slotEventOverlap:!0,weekends:!M,events:o,eventClick:fe,datesSet:Ne,eventDidMount:qe,height:P,scrollTime:T,scrollTimeReset:!1,expandRows:!1,slotLabelFormat:{hour:"numeric",minute:"2-digit",meridiem:"short",omitZeroMinute:!0},eventTimeFormat:{hour:"numeric",minute:"2-digit",meridiem:"short",omitZeroMinute:!1},dayHeaderFormat:{weekday:"short",month:"numeric",day:"numeric",omitCommas:!0},titleFormat:{year:"numeric",month:"long"}})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1.5 px-4 pb-3 text-xs text-content-tertiary border-t border-slate-100 dar
1k:border-slate-700 pt-2 max-lg:gap-x-2 max-lg:gap-y-1 max-lg:px-2 max-lg:pb-2 max-lg:pt-1.5 max-lg:text-3xs",children:[p.filter(c=>v.includes(c.id)).map(c=>{const k=J[c.id]||"#16a34a",m=c.displayName||c.fullName||"Provider";return e.jsxs("span",{className:"flex items-center gap-1.5 max-lg:gap-1",children:[e.jsx("span",{className:"inline-block size-2.5 rounded-sm flex-shrink-0 max-lg:size-2",style:{backgroundColor:rt(k),borderLeft:`3px solid ${k}`}}),e.jsx("span",{className:"max-w-[110px] truncate max-lg:max-w-[84px]",children:m})]},c.id)}),e.jsxs("span",{className:"flex items-center gap-1.5 max-lg:gap-1",children:[e.jsx("span",{className:"inline-block size-2.5 rounded-sm bg-slate-200 dark:bg-slate-600 max-lg:size-2"}),"Network Offline"]}),e.jsxs("span",{className:"flex items-center gap-1.5 max-lg:gap-1",children:[e.jsx("span",{className:"inline-block size-2.5 rounded-sm border border-amber-500 bg-amber-50 dark:bg-amber-950/50 max-lg:size-2"}),"Pending"]}),e.jsxs("span",{className:"flex items-center gap-1.5 max-lg:gap-1",children:[e.jsx("span",{className:"inline-block size-2.5 rounded-sm border max-lg:size-2",style:{borderColor:B,backgroundColor:rt(B)}}),"Confirmed"]})]})]})}),e.jsxs(zt,{open:$,onOpenChange:j,children:[e.jsx(Dt,{asChild:!0,children:e.jsx("div",{ref:Z,style:{position:"fixed",pointerEvents:"none",width:"1px",height:"1px",visibility:"hidden"}})}),e.jsx(Et,{className:"w-[min(20rem,calc(100vw-2rem))] rounded-lg border border-subtle p-0 shadow-xl",align:"start",side:"bottom",sideOffset:5,children:d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start gap-3 p-4 border-b border-slate-100 dark:border-slate-700 max-lg:gap-2 max-lg:p-2.5",children:[e.jsx("div",{className:"w-1 h-16 rounded-full flex-shrink-0 max-lg:h-12",style:{backgroundColor:d.status==="Confirmed"?J[d.providerId]||B:"#f59e0b"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold text-content-primary text-sm mb-1 max-lg:mb-0.5 max-lg:truncate max-lg:text-xs",children:ut(d,"Visit")}),e.jsxs("div",{className:"text-xs text-content-secondary mb-1 max-lg:mb-0.5 max-lg:text-2xs",children:[zs(ct(d,Pe()))," ⢠",d.duration||30," min"]}),e.jsx("span",{className:`${na(d.status)} max-lg:px-1.5 max-lg:text-3xs`,children:d.status||"Confirmed"})]}),e.jsx(Q,{variant:"ghost",size:"sm",className:"size-6 p-0 rounded-full",onClick:()=>j(!1),children:e.jsx(Ds,{className:"size-3"})})]}),e.jsxs("div",{className:"p-4 space-y-3 max-lg:p-2.5 max-lg:space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm max-lg:gap-1.5 max-lg:text-xs",children:[e.jsx(us,{className:"size-4 text-slate-400 max-lg:size-3"}),e.jsx(tt,{name:Ie(d,"Patient"),patientId:d.userId,onOpen:c=>{b(c),j(!1)},href:H(d.userId),className:"text-sm max-lg:text-xs"}),e.jsx(ps,{visit:d})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm max-lg:gap-1.5 max-lg:text-xs",children:[e.jsx(Es,{className:"size-4 text-slate-400 max-lg:size-3"}),e.jsx("button",{type:"button",onClick:()=>{if(d.providerId){const c=new URLSearchParams(q);c.set("user",d.providerId),I(c),j(!1)}},className:"text-slate-700 dark:text-slate-300 hover:text-blue-600 dark:hover:text-blue-400 underline cursor-pointer transition-colors text-left",children:ls(d,p)})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm max-lg:gap-1.5 max-lg:text-xs",children:[e.jsx(Ue,{className:"size-4 text-slate-400 max-lg:size-3"}),e.jsx("span",{className:"text-slate-700 dark:text-slate-300",children:dt(d,Pe(),"EEEE, MMMM d, yyyy")})]}),d.notes&&e.jsx("div",{className:"pt-2 border-t border-slate-100 dark:border-slate-700 max-lg:pt-1.5",children:e.jsx("p",{className:"text-xs text-content-secondary italic max-lg:text-2xs",children:d.notes})})]}),e.jsxs("div",{className:"p-3 border-t border-slate-100 dark:border-slate-700 flex flex-col gap-2 max-lg:gap-1.5 max-lg:p-2",children:[e.jsx(Q,{size:"sm",className:"w-full h-8 text-white max-lg:h-7 max-lg:text-2xs",style:{backgroundColor:B},onClick:()=>{j(!1),s&&s(d)},children:"View Details"}),e.jsx(Q,{size:"sm",variant:"outline",className:"w-full h-8 max-lg:h-7 max-lg:text-2xs",onClick:()=>{const c=Pe(),k=dt(d,c),m=ct(d,c),f=d.duration||30,[L,z,pe]=k.split("-"),[xe,be]=m.split(":"),ye=new Date(L,z-1,pe,xe,be),De=new Date(ye.getTime()+f*6e4);function l(Re){const Je=vs=>String(vs).padStart(2,"0");return`${Re.getUTCFullYear()}${Je(Re.getUTCMonth()+1)}${Je(Re.getUTCDate())}T${Je(Re.getUTCHours())}${Je(Re.getUTCMinutes())}${Je(Re.getUTCSeconds())}Z`}const g=l(ye),X=l(De),ke=encodeURIComponent(d.visitType||"Visit"),je=encodeURIComponent(Ie(d,"Patient")),Ge=window.location.origin,Ee=_t.pathname.startsWith("/visits")?"/visits":"/sync-visits",Ze=`${Ge}${Ee}?visitId=${d.id}`,at=`${d.notes||"Telehealth visit"} 2 3Join video call: ${Ze}`,ve=encodeURIComponent(at),_t=encodeURIComponent(Ze),ys=`https://calendar.google.com/calendar/render?action=TEMPLATE&text=${ke} with ${je}&dates=${g}/${X}&details=${ve}&location=${_t}`;window.open(ys,"_blank")},children:"Add to Google Calendar"}),e.jsx(Q,{size:"sm",variant:"destructive",className:"w-full h-8 max-lg:h-7 max-lg:text-2xs",disabled:d.status==="Cancelled"||ae,onClick:()=>{ne(""),U(!0)},children:"Cancel Visit"}),e.jsx(Q,{size:"sm",variant:"outline",className:"w-full h-8 max-lg:h-7 max-lg:text-2xs",disabled:d.status==="Cancelled",onClick:()=>{j(!1),u&&u(d)},children:"Reschedule Visit"})]})]})})]}),e.jsx(Rs,{open:_,onOpenChange:c=>{U(c),c||ne("")},title:"Cancel Visit",description:"Add an optional reason. This reason will be included in cancellation emails to the provider and patient.",tone
3:"destructive",confirmLabel:ae?"Cancellingâ¦":"Cancel Visit",cancelLabel:"Keep Visit",onConfirm:ft,busy:ae,children:e.jsxs("div",{className:"space-y-2 max-lg:space-y-1.5",children:[e.jsx(Qe,{htmlFor:"admin-cancel-reason",className:"max-lg:text-xs",children:"Cancellation reason"}),e.jsx(gs,{id:"admin-cancel-reason",placeholder:"Enter cancellation reason",value:G,onChange:c=>ne(c.target.value),className:"min-h-[120px] max-lg:min-h-20"})]})})]})}function Fa({providers:s=[],selectedIds:u=[],onSelectionChange:i,providerColors:v={},providerStatuses:F={},providerScheduleState:p=null}){const[y,W]=a.useState(""),O=!!(p&&Object.keys(p).length>0),V=a.useMemo(()=>{const b=[...s].sort(($,j)=>{var C,se;if(O){const _=!!((C=p[$.id])!=null&&C.hasSchedule),U=!!((se=p[j.id])!=null&&se.hasSchedule);if(_!==U)return _?-1:1}const d=$.displayName||$.fullName||"",ie=j.displayName||j.fullName||"";return d.localeCompare(ie,void 0,{sensitivity:"base"})});if(!y.trim())return b;const H=y.toLowerCase();return b.filter($=>{const j=$.displayName||$.fullName||"",d=($.specialties||[]).join(" ");return j.toLowerCase().includes(H)||d.toLowerCase().includes(H)||String($.id||"").toLowerCase().includes(H)})},[s,p,O,y]),B=b=>{u.includes(b)?i(u.filter(H=>H!==b)):i([...u,b])},R=()=>{i(V.map(b=>b.id))},q=()=>{i([])},I=V.length>0&&V.every(b=>u.includes(b.id));return e.jsxs(st,{className:"rounded-xl border border-subtle dark:bg-slate-800 overflow-hidden flex flex-col h-full","data-testid":E("section","sync-visits","provider-filters"),children:[e.jsxs("div",{className:"bg-surface-sunken border-b border-subtle p-4 max-lg:p-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3 max-lg:mb-2 max-lg:gap-1.5",children:[e.jsx("div",{className:"p-1.5 bg-purple-100 dark:bg-purple-900/30 rounded-lg max-lg:shrink-0 max-lg:p-1",children:e.jsx(Ve,{className:"size-4 text-purple-600 dark:text-purple-400 max-lg:size-3"})}),e.jsxs("div",{className:"max-lg:min-w-0",children:[e.jsx("h2",{className:"text-sm font-semibold text-content-primary max-lg:truncate max-lg:text-xs",children:"Providers"}),e.jsxs("p",{className:"text-xs text-content-tertiary max-lg:text-3xs max-lg:leading-tight",children:[u.length," of ",s.length," selected"]})]})]}),e.jsxs("div",{className:"relative mb-3 max-lg:mb-2",children:[e.jsx(pt,{className:"absolute left-2 top-1/2 size-3 -translate-y-1/2 text-slate-400"}),e.jsx(we,{placeholder:"Search providersâ¦",value:y,onChange:b=>W(b.target.value),className:"pl-7 h-8 text-xs dark:bg-slate-700 dark:border-slate-600 max-lg:h-7","aria-label":"Search providers","data-testid":E("input","sync-visits","provider-search")})]}),e.jsx("div",{className:"flex gap-2 max-lg:gap-1.5",children:e.jsx(Q,{size:"sm",variant:"outline",className:"flex-1 h-7 text-xs max-lg:h-6 max-lg:text-3xs",onClick:I?q:R,"aria-pressed":I,"data-testid":E("button","sync-visits",I?"deselect-all-providers":"select-all-providers"),children:I?e.jsxs(e.Fragment,{children:[e.jsx(ba,{className:"size-3 mr-1"}),"Deselect All"]}):e.jsxs(e.Fragment,{children:[e.jsx(ya,{className:"size-3 mr-1"}),"Select All"]})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-2 max-lg:max-h-56 max-lg:p-2 max-lg:space-y-1.5",children:V.length===0?e.jsxs("div",{className:"text-center py-8 max-lg:py-4",children:[e.jsx(Ve,{className:"size-8 text-slate-300 dark:text-slate-600 mx-auto mb-2 max-lg:mb-1 max-lg:size-5"}),e.jsx("p",{className:"text-xs text-content-tertiary max-lg:text-2xs",children:y?"No matching providers":"No providers available"})]}):V.map(b=>{var ie;const H=u.includes(b.id),$=v[b.id]||ze,j=F[b.id],d=!!((ie=p==null?void 0:p[b.id])!=null&&ie.hasSchedule);return e.jsxs("div",{className:`flex items-start gap-2 p-2 rounded-lg border transition-colors cursor-pointer max-lg:gap-1.5 max-lg:p-1.5 ${H?"bg-slate-50 border-slate-300 dark:bg-slate-700/50 dark:border-slate-600":"border-slate-200 hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-700/30"}`,onClick:()=>B(b.id),"data-testid":E("row","sync-visits-provider",b.id),children:[e.jsx("div",{className:"mt-0.5",onClick:C=>C.stopPropagation(),children:e.jsx(As,{checked:H,onCheckedChange:()=>B(b.id),"aria-label":`Select provider ${b.displayName||b.fullName||"Unknown"}`,"data-testid":E("button","sync-visits",`select-provider-${b.id}`)})}),e.jsx("div",{className:"size-3 rounded-full flex-shrink-0 mt-0.5",style:{backgroundColor:$}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5 max-lg:gap-1",children:[e.jsx("span",{className:"text-xs font-medium text-content-primary truncate max-lg:text-2xs",children:b.displayName||b.fullName||"Unknown"}),O&&!d&&e.jsx(et,{variant:"outline",className:"text-3xs px-1 py-0 h-4 border bg-surface-sunken text-content-secondary border-subtle",children:"No schedule"}),j&&e.jsx(et,{variant:"outline",className:`text-3xs px-1 py-0 h-4 border ${j==="In a Visit"?"bg-emerald-50 text-emerald-600 border-emerald-200 dark:bg-emerald-900/30 dark:text-emerald-400 dark:border-emerald-800":"bg-slate-50 text-slate-600 border-slate-200 dark:bg-slate-800/50 dark:text-slate-400 dark:border-slate-600"}`,children:j==="In a Visit"?"Busy":"Free"})]}),b.specialties&&b.specialties.length>0&&e.jsx("p",{className:"text-3xs text-content-tertiary truncate",children:b.specialties.join(", ")})]})]},b.id)})})]})}function _a(s){return(s==null?void 0:s.isRequiredSyncVisit)===!0||((s==null?void 0:s.name)||"").trim()==="Required Sync Visit"}function ns(){return{name:"",description:"",duration:"30",status:"active",icon:"stethoscope",defaultShowPatient:!1}}function is({value:s="stethoscope",onChange:u,accentColor:i="#2563eb",triggerClassName:v="h-8 text-sm"}){const F=va(s),p=F.icon;return e.jsxs(zt,{children:[e.jsx(Dt,{asChild:!0,children:e.jsxs(Q,{type:"button",variant:"outline",className:Pt("w-full justify-between px-2",v),"aria-label":"Select visit icon","data-testid":E("select","sync-visits","visit-icon"),children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(p,{className:"size-4 shrink-0",style:{color:i}}),e.jsx("span",{className:"truncate text-xs font-medium text-slate-700 dark:text-slate-200",children:F.label})]}),e.jsx(Os,{className:"size-3.5 shrink-0 text-slate-400"})]})}),e.jsxs(Et,{className:"w-[min(20rem,calc(100vw-2rem))] p-3 max-lg:p-2",align:"start",children:[e.jsx("div",{className:"grid grid-cols-8 gap-2 max-h-[240px] overflow-y-auto max-lg:max-h-[200px] max-lg:gap-1.5",children:Na.map(y=>{const W=y.icon,O=y.key===F.key;return e.jsx("button",{type:"button",onClick:()=>u(y.key),title:y.label,"aria-label":y.label,className:Pt("size-9 rounded-md border inline-flex items-center justify-center transition-colors max-lg:size-8",O?"border-blue-300 bg-blue-50 dark:border-blue-700 dark:bg-blue-900/30":"border-subtle hover:bg-slate-50 dark:hover:bg-slate-800"),children:e.jsx(W,{className:"size-4",style:{color:O?i:void 0}})},y.key)})}),e.jsxs("p",{className:"mt-2 text-2xs text-content-tertiary max-lg:mt-1.5 max-lg:text-3xs",children:["Selected: ",F.label]})]})]})}function $a(){const{branding:s}=We(),{userDoc:u}
3=ht(),i=(s==null?void 0:s.accentColor)||ze,[v,F]=a.useState(!0),[p,y]=a.useState(!1),[W,O]=a.useState(null),[V,B]=a.useState([]),[R,q]=a.useState(""),[I,b]=a.useState(["active"]),[H,$]=a.useState(!1),[j,d]=a.useState(ns()),[ie,C]=a.useState(!1),[se,_]=a.useState(null),[U,G]=a.useState([]),[ne,ae]=a.useState(!1),[he,re]=a.useState(null),Z=(u==null?void 0:u.providerNetworkId)||null,A=a.useCallback(()=>{if(!Z)throw new Error("Provider network not found for user");return He(Ce,"ProviderNetworks",Z,"Products")},[Z]),n=a.useCallback(async()=>{try{F(!0);const o=(await Gt(Tt(A(),It("type","==","visit")))).docs.map(x=>({id:x.id,...x.data()||{}})).filter(x=>!_a(x)).sort((x,r)=>(x.name||"").localeCompare(r.name||""));B(o)}catch(t){console.error("Error loading visit products:",t),te.error(t.message||"Unable to load visit products. Please try again.")}finally{F(!1)}},[A]);a.useEffect(()=>{n()},[n]);async function N(){var t;try{if(!j.name.trim()){te.error("Visit name is required");return}if(!j.duration||Number(j.duration)<=0){te.error("Duration must be greater than 0");return}y(!0);const o=Xe(A());await Zt(o,{name:j.name.trim(),description:j.description||"",duration:Number(j.duration),icon:Fe(j.icon),type:"visit",status:j.status||"active",providerNetworkId:Z,knowledgeBaseItemIds:[],createdBy:((t=it.currentUser)==null?void 0:t.uid)||null,createdAt:Me(),updatedAt:Me(),defaultShowPatient:!1}),te.success("Visit product created"),d(ns()),$(!1),await n()}catch(o){console.error("Error creating visit product:",o),te.error(o.message||"Unable to create visit product. Please try again.")}finally{y(!1)}}async function h(t,o){var x;try{O(t);const r={updatedBy:((x=it.currentUser)==null?void 0:x.uid)||null,updatedAt:Me()};o.name!==void 0&&(r.name=o.name),o.description!==void 0&&(r.description=o.description),o.duration!==void 0&&(r.duration=Number(o.duration)),o.status!==void 0&&(r.status=o.status),o.icon!==void 0&&(r.icon=Fe(o.icon)),o.defaultShowPatient!==void 0&&(r.defaultShowPatient=o.defaultShowPatient),await Jt(Xe(A(),t),r),te.success("Visit product updated"),await n()}catch(r){console.error("Error updating visit product:",r),te.error(r.message||"Unable to update visit product. Please try again.")}finally{O(null)}}async function w(t){var o;try{y(!0),await Jt(Xe(A(),t),{status:"inactive",updatedBy:((o=it.currentUser)==null?void 0:o.uid)||null,updatedAt:Me()}),te.success("Visit product archived"),await n()}catch(x){console.error("Error archiving visit product:",x),te.error(x.message||"Unable to archive visit product. Please try again.")}finally{y(!1)}}async function S(t){_(t),C(!0),await K(t)}async function K(t){if(Z)try{ae(!0);const o=await Gt(Tt(He(Ce,"Clients"),It("providerNetworkIds","array-contains",Z))),x={};await Promise.all(o.docs.map(async P=>{const M=(await Fs(Ce,P.id,{providerNetworkId:Z,type:"visit"})).find(fe=>(fe.productId||fe.id)===t.id)||null;M&&(x[P.id]=M)}));const r=o.docs.map(P=>({id:P.id,...P.data()})).filter(P=>P.status!=="inactive").sort((P,T)=>(P.name||"").localeCompare(T.name||"")).map(P=>{const T=x[P.id]||null,M=!!T&&T.status!=="inactive";return{clientId:P.id,clientName:P.name||P.id,clientProductId:(T==null?void 0:T.id)||null,enabled:M?T.showPatient!==!1:!1,customerPrice:M&&T.customerPrice!=null?String(T.customerPrice):""}});G(r)}catch(o){console.error("Error loading client rows:",o),te.error("Unable to load client pricing. Please try again.")}finally{ae(!1)}}async function D(t){const o=u==null?void 0:u.providerNetworkId;if(!(!o||!se))try{re(t.clientId);const x={clientId:t.clientId,providerNetworkId:o,productId:se.id,type:"visit",status:t.enabled?"active":"inactive",customerPrice:t.customerPrice===""?"":String(t.customerPrice),showPatient:t.enabled,updatedAt:Me()},r=se.id,P=t.clientProductId===r?x:{...x,createdAt:Me()};await Zt(Xe(Ce,"Clients",t.clientId,"Products",r),P,{merge:!0}),t.clientProductId!==r&&G(T=>T.map(M=>M.clientId===t.clientId?{...M,clientProductId:r}:M)),te.success(`Saved ${t.clientName}`)}catch(x){console.error("Error saving client row:",x),te.error(x.message||"Unable to save. Please try again.")}finally{re(null)}}const oe=a.useMemo(()=>{let t=V;if(R.trim()){const o=R.toLowerCase();t=t.filter(x=>(x.name||"").toLowerCase().includes(o)||(x.description||"").toLowerCase().includes(o)||String(x.duration??"").includes(o)||[x.id,x.productId,x.clientId,x.businessId,x.providerNetworkId].some(r=>String(r||"").toLowerCase().includes(o))||Fe(x.icon).toLowerCase().includes(o))}return I.length>0&&(t=t.filter(o=>I.includes(o.status||"active"))),t},[V,R,I]),de=a.useMemo(()=>({active:V.filter(t=>(t.status||"active")==="active").length,inactive:V.filter(t=>(t.status||"active")==="inactive").length}),[V]),ce=R.trim()||I.length>0,{sortedData:ge,sortKey:me,sortDirection:J,handleSort:le}=Lt(oe,"name","asc"),Y=[{id:"clientName",header:"Client",minWidth:180,renderCell:t=>e.jsx("span",{className:"font-medium text-content-primary max-lg:text-2xs",children:t.clientName})},{id:"customerPrice",cellClassName:"text-metric",align:"right",header:"Price (USD)",minWidth:140,renderCell:t=>e.jsx(we,{type:"text",inputMode:"decimal",value:t.customerPrice,onChange:o=>G(x=>x.map(r=>r.clientId===t.clientId?{...r,customerPrice:o.target.value.replace(/[^0-9.]/g,"")}:r)),placeholder:"0",className:"h-8 text-sm max-lg:h-7","aria-label":`Price for ${t.clientName}`,"data-testid":E("input","sync-visits","client-price")})},{id:"enabled",header:"Available to patient",minWidth:150,renderCell:t=>e.jsx(_s,{checked:t.enabled,onCheckedChange:o=>G(x=>x.map(r=>r.clientId===t.clientId?{...r,enabled:o}:r)),className:"data-[state=checked]:bg-[var(--accent)]",style:{"--accent":i},"aria-label":`Toggle availability for ${t.clientName}`})},{id:"status",header:"Status",minWidth:100,renderCell:t=>e.jsx(et,{variant:"outline",className:$s(t.enabled?"active":"inactive","max-lg:px-1.5 max-lg:text-3xs max-lg:leading-tight"),children:t.enabled?"Active":"Inactive"})},{id:"actions",header:"",fixedWidth:!0,width:70,align:"right",renderCell:t=>e.jsx(Q,{size:"sm",variant:"outline",className:"h-7 rounded-full max-lg:h-6 max-lg:px-1.5",onClick:()=>D(t),disabled:he===t.clientId,style:{borderColor:i,color:i},"aria-label":`Save pricing for ${t.clientName}`,"data-testid":E("button","sync-visits","save-client-price"),children:he===t.clientId?e.jsx($e,{size:"xs"}):e.jsx(qt,{className:"size-3"})})}];return e.jsxs("div",{className:"space-y-4 max-lg:space-y-2.5","data-testid":E("section","sync-visits","visit-products-manager"),children:[e.jsxs(st,{className:"rounded-xl border border-subtle dark:bg-slate-800 overflow-hidden","data-testid":E("section","sync-visits","visit-types"),children:[e.jsxs("div",{className:"bg-surface-sunken border-b border-subtle p-3 max-lg:p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 max-lg:flex-nowrap max-lg:gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 max-lg:min-w-0 max-lg:gap-1.5",children:[e.jsx("div",{className:"p-1.5 rounded-lg max-lg:shrink-0 max-lg:p-1",style:{backgroundColor:`${i}20`},children:e.jsx(Ve,{className:"size-4 max-lg:size-3",style:{color:i}})}),e.jsxs("div",{className:"max-lg:min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-content-primary max-lg:truncate max-lg:text-xs",children:"Visit Types"}),e.jsxs("p",{className:"text-xs text-content-tertiary max-lg:text-3xs max-lg:leading-tight",children:[ge.length," of ",V.length]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 max-lg:shrink-0 max-lg:gap-1 max-lg:overflow-x-auto max-lg:[&_button]:h-7 max-lg:[&_button]:min-h-7 max-lg:[&_button]:min-w-0 max-lg:[&_button]:shrink-0 max-lg:[&_button]:gap-1 max-lg:[&_button]:px-2 max-lg:[&_button]:text-3xs max-lg:[&_svg]:h-3 max-lg:[&_svg]:w-3",children:[e.jsx(gt,{feature:"visit-products",tenantSlug:s==null?void 0:s.businessName,view:{getRows:()=>ge},rawExport:{getRows:()=>fs(ge,V)},allData:{mode:"client",getRows:()=>V},columns:[{header:"Visit Name",csvValue:t=>t.name||""},{header:"Duration",csvValue:t=>t.duration??30},{header:"Description",csvValue:t=>t.description||""},{header:"Status",csvValue:t=>t.status||"active"}],testId:E("button","sync-visits","export-visit-types")}),e.jsxs(Q,{onClick:()=>$(!0),disabled:p,className:"bg-blue-600 hover:bg-blue-700 text-white text-xs h-8 dark:bg-blue-500","data-testid":E("button","sync-visits","add-v
3isit-type"),children:[e.jsx(kt,{className:"size-3 mr-1"}),"Add"]})]})]}),e.jsxs("div",{className:"relative mt-3 max-lg:mt-2",children:[e.jsx(pt,{className:"absolute left-2 top-1/2 size-3 -translate-y-1/2 text-slate-400"}),e.jsx(we,{placeholder:"Search visit type, description, duration, or iconâ¦",value:R,onChange:t=>q(t.target.value),className:"pl-7 h-8 text-xs dark:bg-slate-700 dark:border-slate-600 max-lg:h-7","aria-label":"Search visit types","data-testid":E("input","sync-visits","visit-type-search")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-3 max-lg:mt-2 max-lg:flex-nowrap max-lg:gap-1 max-lg:overflow-x-auto max-lg:pb-0.5 max-lg:[&>*]:shrink-0 max-lg:[&_.relative.inline-flex.rounded-full]:min-h-7 max-lg:[&_.relative.inline-flex.rounded-full]:min-w-0 max-lg:[&_.relative.inline-flex.rounded-full>button]:min-h-7 max-lg:[&_.relative.inline-flex.rounded-full>button]:px-2 max-lg:[&_.relative.inline-flex.rounded-full>button]:py-0 max-lg:[&_.relative.inline-flex.rounded-full>button]:text-3xs max-lg:[&_button]:h-7 max-lg:[&_button]:min-h-7 max-lg:[&_button]:min-w-0 max-lg:[&_button]:px-2 max-lg:[&_button]:text-3xs",children:[e.jsx(_e,{filters:[{id:"active",label:"Active",count:de.active},{id:"inactive",label:"Inactive",count:de.inactive}],activeFilters:I,onFilterChange:b,multiSelect:!0,defaultLabel:"All statuses"}),ce&&e.jsx(Q,{variant:"ghost",size:"sm",onClick:()=>{q(""),b([])},className:"h-7 px-2 text-2xs font-semibold uppercase tracking-wider text-content-tertiary hover:text-slate-900 dark:hover:text-slate-200","data-testid":E("button","sync-visits","clear-visit-type-filters"),children:"Clear all"})]})]}),v?e.jsx("div",{className:"flex items-center justify-center py-12 max-lg:py-6",children:e.jsx(mt,{className:"size-6 animate-spin text-content-tertiary max-lg:size-5"})}):ge.length===0?e.jsxs("div",{className:"p-8 text-center max-lg:p-4",children:[e.jsx("p",{className:"text-sm text-content-tertiary max-lg:text-xs",children:"No visit types match your filters."}),e.jsx(Q,{variant:"outline",className:"mt-3 max-lg:mt-2",onClick:()=>{q(""),b([])},style:{borderColor:i,color:i},children:"Clear filters"})]}):e.jsx("div",{className:"overflow-x-auto overflow-y-auto max-h-[560px] max-lg:max-h-[60dvh] max-lg:min-w-0",children:e.jsxs(Rt,{"aria-label":"Visit types","data-testid":E("table","sync-visits","visit-types"),children:[e.jsx(At,{children:e.jsxs(Ke,{className:"hover:bg-transparent dark:border-slate-700",children:[e.jsx(ue,{sortKey:"name",currentSortKey:me,currentSortDirection:J,onSort:le,className:"w-[18%] text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Visit Name"}),e.jsx(ue,{sortKey:"duration",currentSortKey:me,currentSortDirection:J,onSort:le,className:"w-[8%] text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Duration"}),e.jsx(ue,{sortKey:"description",currentSortKey:me,currentSortDirection:J,onSort:le,className:"w-[20%] text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Description"}),e.jsx(ue,{sortKey:"icon",currentSortKey:me,currentSortDirection:J,onSort:le,className:"w-[14%] text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Icon"}),e.jsx(ue,{sortKey:"status",currentSortKey:me,currentSortDirection:J,onSort:le,className:"w-[8%] text-xs py-2 dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Status"}),e.jsx(Oe,{className:"w-[6%] text-xs py-2 text-right dark:text-slate-300 sticky top-0 bg-surface-raised z-raised",children:"Actions"})]})}),e.jsx(Mt,{children:ge.map(t=>e.jsxs(Ke,{className:"dark:border-slate-700","data-testid":E("row","sync-visits-visit-type",t.id),children:[e.jsxs(ee,{className:"py-2",children:[e.jsx(we,{value:t.name||"",onChange:o=>B(x=>x.map(r=>r.id===t.id?{...r,name:o.target.value}:r)),className:"h-8 text-sm max-lg:h-7 max-lg:w-36",placeholder:"Visit name","aria-label":`Visit name for ${t.name||t.id}`,"data-testid":E("input","sync-visits","visit-type-name")}),e.jsx("div",{className:"text-2xs text-content-tertiary mt-1 truncate max-lg:mt-0.5 max-lg:text-3xs max-lg:max-w-36",children:e.jsx(Be,{text:t.name||"",highlight:R})})]}),e.jsx(ee,{className:"py-2",children:e.jsx(we,{type:"text",inputMode:"numeric",value:String(t.duration??30),onChange:o=>B(x=>x.map(r=>r.id===t.id?{...r,duration:o.target.value.replace(/[^\d]/g,"")}:r)),className:"h-8 w-16 text-sm max-lg:h-7 max-lg:w-12","aria-label":`Duration for ${t.name||t.id}`,"data-testid":E("input","sync-visits","visit-type-duration")})}),e.jsxs(ee,{className:"py-2",children:[e.jsx(we,{value:t.description||"",onChange:o=>B(x=>x.map(r=>r.id===t.id?{...r,description:o.target.value}:r)),className:"h-8 text-sm max-lg:h-7 max-lg:w-40",placeholder:"Brief description","aria-label":`Description for ${t.name||t.id}`,"data-testid":E("input","sync-visits","visit-type-description")}),e.jsx("div",{className:"text-2xs text-content-tertiary mt-1 truncate max-lg:mt-0.5 max-lg:text-3xs max-lg:max-w-40",children:e.jsx(Be,{text:t.description||"No description",highlight:R})})]}),e.jsx(ee,{className:"py-2",children:e.jsx(is,{value:Fe(t.icon),onChange:o=>B(x=>x.map(r=>r.id===t.id?{...r,icon:o}:r)),accentColor:i,triggerClassName:"h-8 text-sm max-lg:h-7 max-lg:w-28 max-lg:px-1.5"})}),e.jsx(ee,{className:"py-2",children:e.jsx(et,{variant:"outline",className:Pt("max-lg:px-1.5 max-lg:text-3xs max-lg:leading-tight",(t.status||"active")==="active"?"bg-green-50 text-green-700 border border-green-200 dark:bg-green-900/30 dark:text-green-400 dark:border-green-800":"bg-surface-sunken text-content-secondary border border-subtle"),children:t.status||"active"})}),e.jsx(ee,{className:"py-2 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1 max-lg:flex-nowrap max-lg:[&>*]:shrink-0",children:[e.jsx(Q,{size:"sm",variant:"outline",className:"h-7 text-xs max-lg:h-6 max-lg:px-1.5 max-lg:text-3xs",title:"Set per-client pricing",onClick:()=>S(t),disabled:p,"aria-label":`Set per-client pricing for ${t.name||t.id}`,"data-testid":E("button","sync-visits","open-client-pricing"),children:e.jsx(Ve,{className:"size-3"})}),e.jsx(Q,{size:"sm",variant:"outline",className:"h-7 text-xs max-lg:h-6 max-lg:px-1.5 max-lg:text-3xs",onClick:()=>h(t.id,{name:t.name,duration:t.duration,description:t.description,status:t.status||"active",icon:Fe(t.icon)}),disabled:p||W===t.id,style:{borderColor:i,color:i},"aria-label":`Save visit type ${t.name||t.id}`,"data-testid":E("button","sync-visits","save-visit-type"),children:W===t.id?e.jsx($e,{size:"xs"}):e.jsx(qt,{className:"size-3"})}),e.jsx(Q,{size:"sm",variant:"outline",className:"h-7 text-xs text-red-600 border-red-200 hover:bg-red-50 dark:border-red-800 dark:hover:bg-red-900/20 max-lg:h-6 max-lg:px-1.5 max-lg:text-3xs",onClick:()=>w(t.id),disabled:p||(t.status||"active")==="inactive","aria-label":`Archive visit type ${t.name||t.id}`,"data-testid":E("button","sync-visits","archive-visit-type"),children:e.jsx(Ms,{className:"size-3"})})]})})]},t.id))})]})})]}),e.jsx(ot,{open:ie,onOpenChange:C,title:`Client Pricing â ${(se==null?void 0:se.name)??""}
3`,description:"Set price and activation per client. When active, this visit type is available to the client and their patients can book it.",contentClassName:"max-w-3xl",contentTestId:E("dialog","sync-visits","client-pricing"),headerClassName:"max-[1024px]:pb-2",titleClassName:"max-[1024px]:truncate",bodyClassName:"max-[1024px]:px-2.5 max-[1024px]:py-2.5",footerClassName:"max-[1024px]:pt-2.5",mobileStickyFooter:!0,footer:e.jsx(Q,{variant:"outline",onClick:()=>C(!1),className:"rounded-full","data-testid":E("button","sync-visits","close-client-pricing"),children:"Done"}),children:e.jsx(Qs,{id:"sync-visit-client-pricing",title:"Client pricing",description:`${U.length} client${U.length===1?"":"s"}`,accentColor:i,columns:Y,rows:U,rowKey:"clientId",loading:ne,emptyMessage:"No clients found in this network.",tableLabel:"Client pricing",maxHeight:"min(60dvh, 36rem)",compactDensity:!0,actions:!ne&&U.length>0?e.jsx(gt,{feature:"visit-product-client-pricing",tenantSlug:s==null?void 0:s.businessName,view:{getRows:()=>U},columns:[{header:"Client",csvValue:t=>t.clientName||""},{header:"Price (USD)",csvValue:t=>t.customerPrice||""},{header:"Status",csvValue:t=>t.enabled?"active":"inactive"}],testId:E("button","sync-visits","export-client-pricing")}):null})}),e.jsx(ot,{open:H,onOpenChange:$,title:"Add visit type",description:"Create a new visit product. Set price and availability per client via the client (people) button on each row.",contentClassName:"max-w-lg",contentTestId:E("dialog","sync-visits","add-visit-type"),headerClassName:"max-[1024px]:pb-2",titleClassName:"max-[1024px]:truncate",bodyClassName:"max-[1024px]:px-2.5 max-[1024px]:py-2.5",footerClassName:"max-[1024px]:pt-2.5",mobileStickyFooter:!0,footer:e.jsxs(e.Fragment,{children:[e.jsx(Q,{variant:"outline",onClick:()=>$(!1),disabled:p,className:"rounded-full","data-testid":E("button","sync-visits","cancel-add-visit-type"),children:"Cancel"}),e.jsx(Q,{type:"submit",form:"visit-products-manager-form-2",disabled:p,style:{backgroundColor:i},"data-testid":E("button","sync-visits","confirm-add-visit-type"),className:"rounded-full text-white",children:p?e.jsxs(e.Fragment,{children:[e.jsx(mt,{className:"size-4 mr-2 animate-spin max-lg:mr-1 max-lg:size-3"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(kt,{className:"size-4 mr-2 max-lg:mr-1 max-lg:size-3"}),"Add visit type"]})})]}),children:e.jsx("form",{id:"visit-products-manager-form-2",className:ja,onSubmit:wa(N,{disabled:p}),children:e.jsxs(Ls,{className:"overflow-hidden bg-surface-raised p-0",bodyClassName:"divide-y divide-slate-200 dark:divide-slate-700",children:[e.jsxs("section",{className:"space-y-4 px-5 py-4 sm:px-6 max-lg:space-y-2.5 max-lg:px-3 max-lg:py-2.5",children:[e.jsxs("div",{className:"space-y-2 max-lg:space-y-1.5",children:[e.jsx(Qe,{className:"max-lg:text-xs",children:"Visit name"}),e.jsx(we,{value:j.name,onChange:t=>d(o=>({...o,name:t.target.value})),placeholder:"e.g. Initial Consultation","aria-label":"Visit name","data-testid":E("input","sync-visits","new-visit-name")})]}),e.jsxs("div",{className:"space-y-2 max-lg:space-y-1.5",children:[e.jsx(Qe,{className:"max-lg:text-xs",children:"Duration (minutes)"}),e.jsx(we,{value:j.duration,onChange:t=>d(o=>({...o,duration:t.target.value.replace(/[^\d]/g,"")})),placeholder:"30","aria-label":"Duration in minutes","data-testid":E("input","sync-visits","new-visit-duration")})]})]}),e.jsxs("section",{className:"space-y-4 px-5 py-4 sm:px-6 max-lg:space-y-2.5 max-lg:px-3 max-lg:py-2.5",children:[e.jsxs("div",{className:"space-y-2 max-lg:space-y-1.5",children:[e.jsx(Qe,{className:"max-lg:text-xs",children:"Description"}),e.jsx(gs,{value:j.description,onChange:t=>d(o=>({...o,description:t.target.value})),placeholder:"What this visit type is for",rows:2,"aria-label":"Visit description","data-testid":E("input","sync-visits","new-visit-description")})]}),e.jsxs("div",{className:"space-y-2 max-lg:space-y-1.5",children:[e.jsx(Qe,{className:"max-lg:text-xs",children:"Icon"}),e.jsx(is,{value:Fe(j.icon),onChange:t=>d(o=>({...o,icon:t})),accentColor:i,triggerClassName:"h-9 text-sm max-lg:h-8"})]})]})]})})})]})}const os=["#2563eb","#7c3aed","#db2777","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#4f46e5","#9333ea","#e11d48","#ef4444"];function Oa(s){return(s||"active").toString().trim().toLowerCase()||"active"}function Ua(s){return Oa(s==null?void 0:s.status)==="active"}function cs(s){return(s==null?void 0:s.displayName)||(s==null?void 0:s.fullName)||""}function Ba(s,u){return s.length!==u.length?!1:s.every((i,v)=>i===u[v])}function Zl({isDelegate:s=!1,showHeader:u=!0}){const{userDoc:i,providerNetwork:v}=ht(),F=(i==null?void 0:i.userType)||"",{branding:p}=We(),y=(p==null?void 0:p.accentColor)||ze,W=(i==null?void 0:i.providerNetworkId)||null,O=(v==null?void 0:v.timezone)||null,[V,B]=a.use
3State([]),[R,q]=a.useState([]),[I,b]=a.useState(null),[H,$]=a.useState(!1),[j,d]=a.useState(null),[ie,C]=a.useState(!1),[se,_]=a.useState([]),[U,G]=a.useState([]),[ne,ae]=a.useState(!1),[he,re]=a.useState(!1),[Z,A]=a.useState(null),[n,N]=a.useState(!1),h=a.useRef(null),w=a.useRef(null),S=a.useCallback(()=>{h.current&&(window.clearTimeout(h.current),h.current=null),d(null)},[]);a.useEffect(()=>()=>{h.current&&window.clearTimeout(h.current)},[]);const{providers:K,error:D}=Vt(W,"sync-visits-network-providers"),oe=a.useMemo(()=>K.filter(Ua).sort((r,P)=>cs(r).localeCompare(cs(P),void 0,{sensitivity:"base"})),[K]);a.useEffect(()=>{D&&(console.error("Error listening to providers:",D),te.error("Unable to load providers. Please try again."))},[D]),a.useEffect(()=>{if(!W){q([]),G([]),_([]),ae(!1);return}q(oe),G(oe),_(r=>{const P=new Set(oe.map(M=>M.id)),T=r.filter(M=>P.has(M));return T.length===r.length?r:T})},[W,oe]),a.useEffect(()=>{if(U.length===0){_([]);return}const r=new Set(U.map(P=>P.id));_(P=>{let T=P.filter(M=>r.has(M));return ne||(T=U.map(M=>M.id)),Ba(P,T)?P:T})},[U,ne]);const de=a.useMemo(()=>{const r={};return U.forEach((P,T)=>{r[P.id]=os[T%os.length]}),r},[U]),ce=a.useMemo(()=>({}),[]),ge=r=>{S(),d(r),C(!0)},me=a.useCallback(r=>{C(r),!r&&(h.current&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{d(null),h.current=null},200))},[]),J=a.useCallback(()=>{C(!1),h.current&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{d(null),h.current=null},200)},[]),{openVisitCharting:le}=Ca();Sa({onOutcome:r=>{r==="completed"&&te.success("Visit completed successfully")}});const Y=a.useCallback(r=>{r!=null&&r.id&&(N(!1),le({visitId:r.id,seed:r,intent:"chart"}))},[le]),t=r=>{b(r),$(!0)},o=()=>{A(null),re(!0)},x=r=>{!r||r.status==="Cancelled"||(N(!1),A(r),re(!0))};return e.jsxs("div",{className:"app-page-shell space-y-6 max-lg:space-y-3",children:[u?e.jsx(js,{children:e.jsx("header",{className:"flex min-w-0 flex-col gap-4 max-lg:gap-2 md:flex-row md:items-start md:justify-between",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2 max-lg:gap-1.5",children:[e.jsx(Us,{mode:"sync"}),e.jsx(ws,{className:"app-page-title max-lg:truncate max-lg:text-lg",children:"Visits"})]}),e.jsx("p",{className:"mt-1 text-sm text-content-secondary max-lg:mt-0.5 max-lg:text-xs",children:s?"Manage patient visits for your provider network without joining live visits":"Manage patient visits for your provider network"})]})})}):null,e.jsxs("section",{className:"grid gap-4 max-lg:gap-2 md:grid-cols-3",children:[e.jsx(wt,{label:"Total Visits",value:V.length,helper:"All time",icon:Ue,accentColor:"#3b82f6"}),e.jsx(wt,{label:"Providers Active",value:R.length,helper:"In network",icon:Ve,accentColor:"#a855f7"}),e.jsx(wt,{label:"Avg Duration",display:"30",helper:"Minutes per visit",icon:xs,accentColor:"#22c55e"})]}),e.jsxs(Bs,{defaultValue:"visits",children:[e.jsx("div",{className:"border-b border-subtle",children:e.jsxs(Hs,{showActiveIndicator:!1,className:"h-10 bg-transparent p-0 gap-6 max-lg:h-8 max-lg:w-full max-lg:justify-start max-lg:gap-2.5 max-lg:overflow-x-auto max-lg:[&>*]:shrink-0",style:{"--active-color":y},children:[e.jsxs(vt,{value:"visits",className:"data-[state=active]:border-b-2 data-[state=active]:border-[var(--active-color)] data-[state=active]:text-[var(--active-color)] data-[state=active]:bg-transparent rounded-none bg-transparent px-0 pb-3 data-[state=active]:shadow-none max-lg:px-0",children:[e.jsx(Ue,{className:"size-4 mr-2 max-lg:mr-1 max-lg:size-3"}),"All Visits"]}),e.jsxs(vt,{value:"providers",className:"data-[state=active]:border-b-2 data-[state=active]:border-[var(--active-color)] data-[state=active]:text-[var(--active-color)] data-[state=active]:bg-transparent rounded-none bg-transparent px-0 pb-3 data-[state=active]:shadow-none max-lg:px-0",children:[e.jsx(Ve,{className:"size-4 mr-2 max-lg:mr-1 max-lg:size-3"}),"Active Providers"]}),e.jsxs(vt,{value:"visit-types",className:"data-[state=active]:border-b-2 data-[state=active]:border-[var(--active-color)] data-[state=active]:text-[var(--active-color)] data-[state=active]:bg-transparent roun
3ded-none bg-transparent px-0 pb-3 data-[state=active]:shadow-none max-lg:px-0",children:[e.jsx(bs,{className:"size-4 mr-2 max-lg:mr-1 max-lg:size-3"}),"Visit Types"]})]})}),e.jsx(Nt,{value:"visits",className:"mt-6 space-y-6 max-lg:space-y-3",children:e.jsx(za,{onReassign:ge,onView:Y,onCreateVisit:o,onVisitsChange:B,onShowCalendar:()=>N(!0),calendarTriggerRef:w})}),e.jsx(Nt,{value:"providers",className:"mt-6",children:e.jsx(Ra,{onManageSchedule:t})}),e.jsx(Nt,{value:"visit-types",className:"mt-6",children:e.jsx($a,{})})]}),e.jsx(ot,{open:n,onOpenChange:r=>{N(r),r||requestAnimationFrame(()=>{var P;return(P=w.current)==null?void 0:P.focus()})},size:"full",title:"Network calendar",description:"Network availability and scheduled visits. Filter by provider to narrow the calendar.",contentTestId:"dialog-network-calendar",children:n&&e.jsxs("div",{className:"app-sidebar-layout-narrow min-w-0 items-start max-lg:gap-2",children:[e.jsx(Fa,{providers:U,selectedIds:se,onSelectionChange:r=>{ae(!0),_(r)},providerColors:de,providerStatuses:ce}),e.jsx(La,{fullWidth:!0,selectedProviderIds:se,providerColors:de,allProviders:U,providerNetworkId:W,networkTimezone:O,visitsOverride:V,onSelectVisit:Y,onRescheduleVisit:x})]})}),e.jsx(Pa,{open:H,onOpenChange:$,provider:I}),e.jsx(Ws,{open:ie,onOpenChange:me,visit:j,providers:R,onSuccess:J}),e.jsx(ka,{open:he,onClose:()=>{re(!1),A(null)},onSuccess:()=>{re(!1),A(null)},userType:F,userDoc:i,rescheduleVisit:Z,visitFlow:"sync"})]})}export{Zl 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.