1import{r as s,j as t}from"./react-vendor-CU6Sz31W.js";import{u as J,al as fe,b as me,bo as ue,aD as pe,be as X,j0 as Y,t as Q,j as S,i as q,cd as he,E as Ce,hS as be,b8 as ge,fU as xe,ce as F,cf as ye,eC as ve,bN as we,bO as je,bP as Ae,bQ as Ne,dW as Se,ax as Fe}from"./index-DEXJEDAi.js";import"./calendar-RV2oTCrW.js";import{a as Te}from"./DataTableCard-BluwWKn_.js";import"./ExportCsvAction-BJr9eiP6.js";import{a as ke}from"./localTableUtils-D6jRZlmf.js";import"./patient-name-link-BAfQKbEs.js";import"./text-highlight-BFqqfcjs.js";import{C as Pe}from"./CreateClientModal-gabmBBMQ.js";import{R as G}from"./RoutePageHeader-9W0v4VlT.js";import"./firebase-w6DYUbFN.js";import"./payment-icons-Daq1K3F1.js";import"./addWeeks-1hrFjz19.js";import"./index-BSuGcRaZ.js";import"./table-CxPdvV_9.js";import"./arrow-up-D6DFVL4j.js";import"./arrow-down-BjUlbB4f.js";import"./pill-filter-CtZSNPVl.js";import"./date-picker-filter-Qp1kqu9t.js";import"./clear-filters-button-DmPemFGr.js";import"./modal-option-cards-Dksohkou.js";import"./automatedSetupDefaults-CX0qJHtc.js";import"./BrandAssetUploader-BMswDsUm.js";import"./UserInviteBatchForm-BuWuM86p.js";import"./EmailBadgeEditor-BloV_8im.js";import"./RoutePageHeaderContent-FkxdZGox.js";function Le({dialog:l}){var z,H;const{userDoc:d,clientData:n,userType:T,isReadOnly:Z}=J(),{branding:p}=fe(),h=(p==null?void 0:p.accentColor)||me,c=ue(),[C,k]=pe(),[f,P]=s.useState([]),[L,b]=s.useState(!0),[m,ee]=s.useState([]),[R,B]=s.useState(""),[te,ie]=s.useState(0),[g,M]=s.useState(""),[x,E]=s.useState([]),[y,I]=s.useState([]),[v,K]=s.useState([]),[w,O]=s.useState([]),[j,ae]=s.useState("name"),[A,se]=s.useState("asc"),U=d==null?void 0:d.clientId,ne=C.get("client"),o=s.useMemo(()=>{var i,r;const e=(r=(i=n==null?void 0:n.platformBilling)==null?void 0:i.config)==null?void 0:r.affiliatedClientLimit,a=Number(e);return e==null||e===""||!Number.isFinite(a)?null:Math.max(0,Math.floor(a))},[(H=(z=n==null?void 0:n.platformBilling)==null?void 0:z.config)==null?void 0:H.affiliatedClientLimit]),u=o!==null&&f.length>=o,N=X(T,"Client Admin")&&Y(n)&&!!U;s.useEffect(()=>{if(!N){P([]),b(!1);return}let e=!1;async function a(){b(!0),B("");try{const i=await ge("manageClient",{action:"listAffiliatedClients"});e||(P(i.data.clients),ee(i.data.networks))}catch(i){e||B(i.message||"Unable to load affiliated clients. Retry to continue.")}finally{e||b(!1)}}return a(),window.addEventListener("focus",a),()=>{e=!0,window.removeEventListener("focus",a)}},[N,U,te,ne,l==null?void 0:l.open]);const _=e=>({gfe_only:"Review Only",gfe_prescribe:"Review + Prescribe",affiliate:"Affiliate"})[e]||e||"â",le=s.useMemo(()=>f.map(e=>({...e,networkName:(e.providerNetworkIds||[]).map(a=>{var i;return((i=m.find(r=>r.id===a))==null?void 0:i.name)||a}).join(", ")})),[f,m]),W=ke(le,{searchTerm:g,searchFields:["name","displayName","networkName"],sortKey:j,sortDirection:A,filters:[{id:"status",activeValues:x},{id:"model",activeValues:y},{id:"network",activeValues:v,predicate:(e,a)=>a.some(i=>e.providerNetworkIds.includes(i))},{id:"patients",activeValues:w,predicate:(e,a)=>a.includes(e.patientCount>0?"has-patients":"no-patients")}]}),D=!!(g||x.length||y.length||v.length||w.length),V=u?`This account has reached its affiliated-client limit of ${o}. Ask your primary provider network admin to raise the limit.`:null,re=s.useCallback(()=>{if(u){Q.error(`This account has reached its affiliated-client limit of ${o}`);return}if(!(l!=null&&l.openWith)){Q.error("Unable to open create dialog");return}l.openWith(t.jsx(Pe,{parentClientMode:!0}),{title:"Create affiliated client",description:"Create an affiliated client under this parent",size:"2xl",contentTestId:S("dialog","affiliated-clients","create-child-client")})},[o,l,u]),oe=s.useCallback((e,a="administrator")=>{var r;if((r=c==null?void 0:c.openProfileModal)!=null&&r.call(c,"client",e,a))return;const i=new URLSearchParams(C);i.set("client",e),i.set("client_tab",a),k(i)},[c,C,k]),ce=[{id:"name",header:"Client",sortKey:"name",minWidth:180,renderCell:e=>t.jsx("span",{className:"text-sm font-medium text-foreground",children:e.name||"Untitled client"})},{id:"networkName",header:"Network",sortKey:"networkName",minWidth:160,renderCell:e=>t.jsx("div",{className:"flex flex-wrap gap-1",children:e.providerNetworkIds.map(a=>{const i=m.find(r=>r.id===a);return t.jsx(xe,{primaryColor:(i==null?void 0:i.accentColor)||h,children:(i==null?void 0:i.name)||a},a)})})}
1,{id:"model",header:"Model",sortKey:"model",minWidth:140,renderCell:e=>t.jsx(F,{className:ye("indigo"),children:_(e.model)})},{id:"patientCount",header:"Patients",sortKey:"patientCount",align:"center",renderCell:e=>t.jsx(F,{variant:"secondary",className:"tabular-nums",children:e.patientCount})},{id:"status",header:"Status",sortKey:"status",renderCell:e=>t.jsx(F,{className:ve(e.status),children:e.status==="inactive"?"Inactive":"Active"})}],$=t.jsxs(q,{type:"button",size:"sm",className:"h-8 text-xs text-white",style:{backgroundColor:h},disabled:Z||u,onClick:re,"data-testid":S("button","affiliated-clients","create-child-client"),children:[t.jsx(he,{className:"mr-1 size-3"}),"Add"]}),de=V?t.jsx(we,{delayDuration:150,children:t.jsxs(je,{children:[t.jsx(Ae,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:$})}),t.jsx(Ne,{side:"top",className:"max-w-xs text-xs",children:V})]})}):$;return N?t.jsx(t.Fragment,{children:R?t.jsx(Ce,{reason:"error",title:"Affiliated clients unavailable",description:R,action:t.jsx(q,{variant:"outline",onClick:()=>ie(e=>e+1),children:"Retry"})}):t.jsx(Te,{id:"child-clients",title:"Affiliated clients",description:o===null?"Create and manage affiliated clients. Platform charges for children bill to this parent.":`${f.length} of ${o} affiliated clients used. Platform charges bill to this parent.`,icon:be,accentColor:h,actions:de,loading:L,columns:ce,rows:W.sortedRows,search:{value:g,onChange:M,placeholder:"Search clients or networksâ¦"},filters:[{id:"status",defaultLabel:"All statuses",filters:[{id:"active",label:"Active"},{id:"inactive",label:"Inactive"}],activeFilters:x,onFilterChange:E},{id:"model",defaultLabel:"All models",filters:["gfe_only","gfe_prescribe"].map(e=>({id:e,label:_(e)})),activeFilters:y,onFilterChange:I},{id:"network",defaultLabel:"All networks",filters:m.map(e=>({id:e.id,label:e.name})),activeFilters:v,onFilterChange:K},{id:"patients",defaultLabel:"All patient counts",filters:[{id:"has-patients",label:"Has patients"},{id:"no-patients",label:"No patients"}],activeFilters:w,onFilterChange:O}],hasActiveFilters:D,onClearFilters:()=>{M(""),E([]),I([]),K([]),O([])},sortKey:j,sortDirection:A,onSort:e=>{se(e===j&&A==="asc"?"desc":"asc"),ae(e)},filteredCount:W.filteredCount,totalCount:f.length,rowClick:e=>oe(e.id),csvExport:{feature:"affiliated-clients",disabled:L},rowKey:"id",tableLabel:"Affiliated clients",tableTestId:S("table","affiliated-clients","child-clients"),emptyMessage:D?"No affiliated clients match these filters.":"No affiliated clients yet. Add one to get started."})}):null}function st(){const{userType:l,clientData:d}=J(),n=Se();return X(l,"Client Admin")&&Y(d)?t.jsxs("main",{className:"app-page-shell space-y-4 sm:space-y-8","data-testid":"page-affiliated-clients",children:[t.jsx(G,{title:"Affiliated clients",description:"Manage your affiliated clients, provider networks, and account settings."}),t.jsx(Le,{dialog:n}),t.jsx(Fe,{accessibleTitle:"Affiliated client details",open:n.open,onOpenChange:n.onOpenChange,...n.dialogProps,children:n.content})]}):t.jsx("main",{className:"app-page-shell space-y-4 sm:space-y-8","data-testid":"page-affiliated-clients-denied",children:t.jsx(G,{title:"Affiliated clients",description:"Affiliated clients are not enabled for this account."})})}export{st 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.