1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MessageTemplatesDialog-B1HeT6bA.js","assets/react-vendor-CU6Sz31W.js","assets/MessageTemplatesManager-BesVHpQc.js","assets/index-DEXJEDAi.js","assets/firebase-w6DYUbFN.js","assets/payment-icons-Daq1K3F1.js","assets/index-ClGd-I0y.css","assets/table-CxPdvV_9.js","assets/text-highlight-BFqqfcjs.js","assets/calendar-RV2oTCrW.js","assets/addWeeks-1hrFjz19.js","assets/DataTableCard-BluwWKn_.js","assets/index-BSuGcRaZ.js","assets/arrow-up-D6DFVL4j.js","assets/arrow-down-BjUlbB4f.js","assets/pill-filter-CtZSNPVl.js","assets/date-picker-filter-Qp1kqu9t.js","assets/clear-filters-button-DmPemFGr.js","assets/ExportCsvAction-BJr9eiP6.js","assets/modal-option-cards-Dksohkou.js","assets/patient-name-link-BAfQKbEs.js","assets/useTemplateVariableInsertion-DRs-_PWy.js","assets/prescriptionMessageTemplateVariables-AMxKc8BX.js","assets/pencil-CpqYHolO.js","assets/ProtocolPresetsDialog-C7ciBSDM.js","assets/formularyCopySummary-EXlTfaRl.js","assets/catalogHelpers-CytjTu8E.js","assets/labBiomarkerRequirementModel-Bqa1eFIF.js","assets/pen-D_kczL5M.js","assets/BulkActionDialogs-BucQojJJ.js","assets/combobox-D0C_yDo2.js","assets/ellipsis-tooltip-CfKm8VFV.js","assets/CatalogStateExclusionsPanel-eJPBk-Pg.js","assets/collapsible-JRJGT2Lx.js","assets/catalogStateExclusions-C6BtORvT.js","assets/catalogCategoryVisibility-PKrVnYt-.js","assets/entityExportApi-B54AEfOG.js","assets/rawTableExport-DjSsUxyR.js","assets/SubscriptionsManager-BDbX__WY.js","assets/cells-Db2ZEFlu.js","assets/ellipsis-vertical-C-dQ6Kzj.js","assets/productSubscriptionRule-Btb3VTHz.js","assets/CatalogSelectionList-D9FsL1Nv.js","assets/LabAdjudicationUnavailableNotice-Caxh_Djm.js","assets/ProductInlineEditPopovers-B7oRL8nE.js","assets/message-square-text-CBK4eOxL.js","assets/useRealtimeRows-CgXDiBPc.js","assets/localTableUtils-D6jRZlmf.js","assets/useTableSort-KpNOL2n3.js","assets/useLocalStorageState-BlY8ICA4.js","assets/clinicalRulesWindows-XIF-DYAK.js","assets/labRecencyWindow-BLArGdSC.js","assets/providerNetworkFormsFirestore-CtlDVuXc.js","assets/formChangeLogs-Yl91HkEm.js","assets/labBiomarkerApi-Ck21Kuon.js","assets/RoutePageHeader-9W0v4VlT.js","assets/RoutePageHeaderContent-FkxdZGox.js","assets/BulkImportDialogs-QLGbC4Z7.js","assets/modal-form-CqN5DZuv.js","assets/CategoryDialogs-DABqNubf.js","assets/CategoryFormDialog-bVZylz8q.js","assets/RequirementControls-Wb_UaVb6.js","assets/labDisplayUtils-D6xhR45u.js","assets/FormularyDefaultsDialog-C0hXQMV-.js","assets/ProductsPageProductMedicationsSheet-Dl84wnBq.js","assets/useProviderNetworkFormularyCustomNames-DLzu7zBJ.js","assets/formularyVariants-BV7CaEYS.js","assets/formularyRules-DurNzATt.js","assets/formularyMappings-C8mJfsp2.js","assets/providerOperations-ELdKx_YD.js","assets/networkLicensurePolicy-Ct3PZM4V.js","assets/useFormularyTypesenseSearch-b2YherGX.js","assets/collectExportPages-B1mgoF_8.js","assets/useClientFormularyPairingPrices-BjCy1Qoq.js","assets/formularySearchSeed-DFztyQr8.js","assets/searchMatchPosition-D039Jv6R.js","assets/ClientFormularyMedicationsTable-DGS5GEg6.js","assets/editor-D8UbQKN1.js","assets/use-unsaved-changes-B6nL5Xdd.js","assets/useFormularySendTiming-PW-jkqj4.js","assets/formularySendSchedules-hEX-RQcj.js","assets/formularySeed-CU64n7sL.js","assets/KnowledgeBaseDialogs-BiCLnIEn.js","assets/CatalogItemAdminFormPreviewModal-BQ14I7dT.js","assets/ProductDialog-DSQ6JXo_.js","assets/ClinicalRuleCards-DDP8Y6Vb.js","assets/IntakeFormViewModal-BaQ61xI7.js","assets/form-type-badge-C6n28ItU.js","assets/ProductDialog-zaML8eXK.css","assets/TemplateCatalogDialog-DMlu-k1A.js"])))=>i.map(i=>d[i]); 2import{a$ as wn,ae as as,af as rs,i as G,j as ae,ag as os,bN as Sn,gB as Hr,ad as nc,t as y,bO as Cn,bP as kn,bQ as Pn,e as ye,te as Zt,ce as es,S as ic,h as lc,y as cc,cf as Us,az as ts,ex as dc,tf as Wo,ci as uc,bg as Aa,C as Nn,dd as In,gN as mc,bR as gc,cd as pc,cr as fc,I as yc,cc as bc,d as hc,ax as xc,c5 as Xe,cW as Tr,e5 as vc,as as se,au as Ta,G as wc,f2 as Sc,al as Cc,u as kc,b as Pc,be as Yo,aE as Nc,tg as Ic,f$ as Go,jY as Jo,jb as jc,bJ as Lc,th as Bc,ti as A
2c,it as Tc,g9 as Jt,em as Xo}from"./index-DEXJEDAi.js";import{j as t,r as s,e as Rc}from"./react-vendor-CU6Sz31W.js";import{r as Dc}from"./index-BSuGcRaZ.js";import{g as $r}from"./catalogCategoryVisibility-PKrVnYt-.js";import{r as Fc}from"./entityExportApi-B54AEfOG.js";import{f as Ec}from"./rawTableExport-DjSsUxyR.js";import{M as _c}from"./modal-option-cards-Dksohkou.js";import{E as Mc,H as Xt}from"./ExportCsvAction-BJr9eiP6.js";import{P as Ra}from"./pill-filter-CtZSNPVl.js";import{d as fe,a as Ur,b as qc,T as Oc,c as Vc}from"./table-CxPdvV_9.js";import{C as $c,u as Qo}from"./DataTableCard-BluwWKn_.js";import"./calendar-RV2oTCrW.js";import"./patient-name-link-BAfQKbEs.js";import{T as Uc}from"./text-highlight-BFqqfcjs.js";import{L as zc,S as Kc}from"./SubscriptionsManager-BDbX__WY.js";import{D as Hc,M as Rr,a as Dr}from"./cells-Db2ZEFlu.js";import{e as Wc,h as jn,g as Ce,c as Ln,i as Zo,j as en,k as tn,l as Yc,n as Gc,o as Jc,p as Xc,q as Qc,r as Zc,s as ed,m as Ae,b as qs,a as Os,f as Fr,t as td,u as sn,v as Er,w as sd,x as Vs,y as ka,D as ad,d as Ee,M as Qt,z as Pa,C as an}from"./catalogHelpers-CytjTu8E.js";import{C as Hs,a as zr}from"./CatalogSelectionList-D9FsL1Nv.js";import{h as Fa,a as rd,i as zs,j as rn}from"./labBiomarkerRequirementModel-Bqa1eFIF.js";import{r as od,L as nd}from"./LabAdjudicationUnavailableNotice-Caxh_Djm.js";import{P as id}from"./ProductInlineEditPopovers-B7oRL8nE.js";import{A as ld}from"./arrow-up-D6DFVL4j.js";import{A as cd}from"./arrow-down-BjUlbB4f.js";import{M as dd}from"./message-square-text-CBK4eOxL.js";import{u as ud}from"./useRealtimeRows-CgXDiBPc.js";import{s as md}from"./localTableUtils-D6jRZlmf.js";import{u as _r}from"./useTableSort-KpNOL2n3.js";import{u as ee}from"./useLocalStorageState-BlY8ICA4.js";import{s as Kr,t as gd,j as Bn,d as Ea,f as on,e as Ks,c as Da,q as pd,w as fd,m as yd}from"./firebase-w6DYUbFN.js";import{n as _a}from"./clinicalRulesWindows-XIF-DYAK.js";import{n as ss}from"./labRecencyWindow-BLArGdSC.js";import{u as nn}from"./providerNetworkFormsFirestore-CtlDVuXc.js";import{requestLabBiomarkerAction as bd}from"./labBiomarkerApi-Ck21Kuon.js";import{R as hd}from"./RoutePageHeader-9W0v4VlT.js";/** 3 * @license lucide-react v0.475.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const xd=[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]],vd=wn("FolderTree",xd);/** 8 * @license lucide-react v0.475.0 - ISC 9 * 10 * This source code is licensed under the ISC license. 11 * See the LICENSE file in the root directory of this source tree. 12 */const wd=[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]],Sd=wn("LayoutTemplate",wd),Wr=s.createContext(null);function Cd({value:r,children:o}){return t.jsx(Wr.Provider,{value:r,children:o})}function Ma(){const r=s.useContext(Wr);if(!r)throw new Error("useProductsProviderNetworkView must be used within ProductsProviderNetworkViewProvider");return r}function Uu(){return s.useContext(Wr)}function kd(r){const[o,d]=s.useState({}),n=s.useRef(null),c=Object.fromEntries(Object.entries(r).map(([g,x])=>[g,o[g]??x])),u=s.useCallback((g,x)=>{d(w=>({...w,[g]:Math.max(g==="checkbox"?36:56,Math.min(800,x))}))},[]);s.useEffect(()=>{const g=()=>{n.current&&(document.body.style.cursor=n.current.cursor,document.body.style.userSelect=n.current.userSelect,n.current=null)},x=w=>{n.current&&u(n.current.key,n.current.width+w.clientX-n.current.x)};return document.addEventListener("pointermove",x),document.addEventListener("pointerup",g),document.addEventListener("pointercancel",g),()=>{g(),document.removeEventListener("pointermove",x),document.removeEventListener("pointerup",g),document.removeEventListener("pointercancel",g)}},[u]);const h=s.useCallback((g,x,w)=>{g.preventDefault(),g.stopPropagation(),n.current={key:x,width:w,x:g.clientX,cursor:document.body.style.cursor,userSelect:document.body.style.userSelect},document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return{widths:c,startResize:h,setWidth:u}}const Na={checkbox:40,status:64,name:240,type:100,categories:150,syncVisit:110,labs:88,clients:100,forms:110,formulary:120,documents:110,actions:90},Ia={manage:Na,readonly:Object.fromEntries(Object.entries(Na).filter(([r])=>!["checkbox","formulary","actions"].includes(r))),businessManage:Object.fromEntries(Object.entries(Na).filter(([r])=>!["syncVisit","labs","clients"].includes(r))),businessReadonly:Object.fromEntries(Object.entries(Na).filter(([r])=>!["checkbox","formulary","actions","syncVisit","labs","clients"].includes(r)))}
12,Pd="sticky top-0 z-raised bg-surface-raised text-xs dark:text-slate-300";function Yr(r,o=!0,d=!1){if(!o)return r?Ia.businessManage:Ia.businessReadonly;const n=r?Ia.manage:Ia.readonly;return d?{...n,legitScript:56}:n}function ke(r,o,d=!0,n=null){const c=(n||Yr(r,d))[o];return c?{width:c,maxWidth:c}:void 0}function ln(r,o=!0,d=null){const n=d||Yr(r,o);return t.jsxs("colgroup",{children:[r?t.jsx("col",{style:{width:n.checkbox}}):null,t.jsx("col",{style:{width:n.status}}),n.legitScript?t.jsx("col",{style:{width:n.legitScript}}):null,t.jsx("col",{style:{width:n.name}}),t.jsx("col",{style:{width:n.type}}),t.jsx("col",{style:{width:n.categories}}),o?t.jsx("col",{style:{width:n.syncVisit}}):null,o?t.jsx("col",{style:{width:n.labs}}):null,o?t.jsx("col",{style:{width:n.clients}}):null,t.jsx("col",{style:{width:n.forms}}),r?t.jsx("col",{style:{width:n.formulary}}):null,t.jsx("col",{style:{width:n.documents}}),r?t.jsx("col",{style:{width:n.actions}}):null]})}function Nd(r,o){return o.id}function cn({label:r,onClick:o,children:d}){return t.jsxs(Cn,{children:[t.jsx(kn,{asChild:!0,children:t.jsx(G,{type:"button",variant:"ghost",size:"icon",className:"size-7 shrink-0 text-content-tertiary max-lg:size-6","aria-label":r,onClick:o,children:d})}),t.jsx(Pn,{children:r})]})}function Id({product:r,readOnly:o=!1,triggerClassName:d,formCount:n}){const{formPairingSavingIds:c,formsDialogProduct:u,formsDialogRows:h,openAssociatedFormsDialog:g,providerNetworkFormsLoaded:x,providerNetworkFormsLoading:w,setFormsDialogProduct:L,setViewingForm:S,toggleFormPairing:U}=Ma(),[f,B]=s.useState(!1),q=s.useMemo(()=>h.filter(A=>Wc(A,r)).map(A=>A.id),[h,r]),X=o?h.filter(A=>q.includes(A.id)):h;return t.jsxs(as,{open:f,onOpenChange:A=>{B(A),A?g(r):(u==null?void 0:u.id)===r.id&&L(null)},children:[t.jsx(rs,{asChild:!0,children:t.jsx(G,{type:"button",variant:"ghost",size:"sm",className:d,"aria-label":`${o?"View":"Manage"} forms for ${r.name||"catalog item"}`,"data-testid":ae("button","products","row-forms-trigger"),children:t.jsx("span",{className:"text-metric text-sm text-content-primary max-lg:text-2xs",children:jn(Number.isFinite(n)?n:q.length,"form",{loaded:Number.isFinite(n)||x})})})}),t.jsxs(os,{className:"w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-subtle bg-surface-raised p-0 shadow-lg",align:"center",sideOffset:8,accessibleLabel:`Forms for ${r.name||"catalog item"}`,"data-testid":ae("dialog","products","row-forms"),children:[t.jsx("div",{className:"border-b border-subtle px-3 py-2.5",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("p",{className:"text-sm font-semibold text-content-primary",children:"Forms"}),t.jsxs("span",{className:"text-xs text-content-tertiary",children:[q.length," selected"]})]})}),t.jsx(Sn,{delayDuration:150,children:t.jsx("div",{className:"p-3",children:t.jsx(Hs,{label:"Forms",items:X,selectedIds:q,savingIds:c,loading:w&&!x,disabled:o,emptyLabel:"No active forms available.",onToggle:o?void 0:(A,re)=>void U(A,re),renderAction:A=>t.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[t.jsx(cn,{label:"Preview form",onClick:()=>{B(!1),L(null),S(A)},children:t.jsx(Hr,{className:"size-3.5","aria-hidden":!0})}),t.jsx(cn,{label:"Copy form ID",onClick:async()=>{try{await navigator.clipboard.writeText(String(A.id)),y.success("Form ID copied")}catch{y.error("Could not copy form ID")}},children:t.jsx(nc,{className:"size-3.5","aria-hidden":!0})})]})})})})]})]})}function jd({product:r,readOnly:o}){const{knowledgeBaseItems:d,knowledgeBaseItemsLoading:n,loadKnowledgeBaseItems:c,handleProductRowDocumentsSave:u,setViewingKnowledgeBaseItem:h}=Ma(),[g,x]=s.useState(r.knowledgeBaseItemIds||[]),w=JSON.stringify(r.knowledgeBaseItemIds||[]);s.useEffect(()=>x(JSON.parse(w)),[w,r.id]);const[L,S]=s.useState(!1),U=d.filter(f=>!o||g.includes(f.id)).map(f=>({...f,name:Ce(f)}));return t.jsxs(as,{onOpenChange:f=>{f&&c()},children:[t.jsx(rs,{asChild:!0,children:t.jsx(G,{type:"button",variant:"ghost",className:"h-auto w-full justify-start rounded-none py-2","aria-label":`Documents for ${r.name}`,children:t.jsx(zr,{items:U,selectedIds:g,emptyLabel:n?"Loadingâ¦":"No documents",tone:"slate"})})}),t.jsxs(os,{className:"w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-subtle p-0 shadow-lg",align:"center",sideOffset:8,accessibleLabel:`Documents for ${r.name}`,children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-3 py-2.5",children:[t.jsx("p",{className:"text-sm font-semibold text-content-primary",children:"Documents"}),t.jsxs("span",{className:"text-xs text-content-tertiary",children:[g.length," selected"]})]}),t.jsx("div",{className:"p-3",children:t.jsx(Hs,{label:"Documents",items:U,selectedIds:g,loading:n,disabled:o||L,emptyLabel:"No documents available.",onToggle:async(f,B)=>{const q=B?[...g,f.id]:g.filter(X=>X!==f.id);S(!0);try{await u(r.id,q)&&x(q)}finally{S(!1)}},renderAction:f=>t.jsx(G,{type:"button",variant:"ghost",size:"icon","aria-label":`View ${f.name}`,onClick:()=>h(f),children:t.jsx(Hr,{className:"size-4"})})})})]})]})}function Ld({product:r,canManageCatalog:o=!1,accentColor:d,triggerClassName:n}){const{loadMasterLabs:c,masterLabs:u,masterLabsError:h,masterLabsLoaded:g,masterLabsLoading:x,openEditProductDialog:w,providerNetworkId:L}=Ma(),[S,U]=s.useState(!1),[f,B]=s.useState(null),[q,X]=s.useState(!1),A=s.useMemo(()=>Fa(r),[r]),re=s.useMemo(()=>rd(u,A.requiredLabTests,A.suggestedLabProductIds).filter(m=>m.selected),[u,A.requiredLabTests,A.suggestedLabProductIds]);s.useEffect(()=>{if(!S||A.requiredLabTests.length===0){B(null),X(!1);return}let m=!1;return B(null),X(!1),(async()=>{const oe=await od(re,{requiredTests:A.requiredLabTests,providerNetworkId:L,networkProductId:r==null?void 0:r.id});m||(B(oe.rows),X(oe.adjudicationUnavailable))})(),()=>{m=!0}},[re,S,r==null?void 0:r.id,L,A.requiredLabTests]);const z=f||re,O=(r==null?void 0:r.requiresLabs)===!0,v=(r==null?void 0:r.type)!=="lab"&&(r==null?void 0:r.type)!=="treatment",p=ye(Zt,"inline-flex justify-center hover:bg-muted",n);return!O&&o?t.jsx(G,{type:"button",variant:"ghost",className:p,"aria-label":`Edit ${(r==null?void 0:r.name)||"catalog item"} to require labs`,"data-testid":ae("button","products","row-labs-trigger"),onClick:()=>w(r),children:t.jsx("span",{className:"text-3xs font-semibold text-muted-foreground",children:"Not required"})}):t.jsxs(as,{open:S,onOpenChange:m=>{U(m),m&&O&&(c==null||c())},children:[t.jsx(rs,{asChild:!0,children:t.jsx(G,{type:"button",variant:"ghost",className:p,"aria-label":`${O?"Review":"View"} lab requirements for ${(r==null?void 0:r.name)||"catalog item"}`,"data-testid":ae("button","products","row-labs-trigger"),children:O?t.jsx(es,{variant:"outline",children:"Required"}):t.jsx("span",{className:"text-3xs font-semibold text-muted-foreground",children:"Not required"})})}),t.jsxs(os,{className:"w-80 overflow-hidden rounded-xl border border-border bg-popover p-0 shadow-lg",align:"center",side:"bottom",sideOffset:8,accessibleLabel:`Lab requirements for ${(r==null?void 0:r.name)||"catalog item"}`,"data-testid":ae("dialog","products","row-labs"),children:[v?O?t.jsxs("div",{className:"divide-y divide-border",children:[t.jsxs("section",{className:"px-4 py-3",children:[t.jsx("h4",{className:"text-xs font-semibold text-foreground",children:"Minimum biomarkers"}),t.jsx("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:A.requiredLabTests.length>0?A.requiredLabTests.map(m=>m.name).join(", "):"No minimum biomarkers are defined."})]}),t.jsxs("section",{className:"px-4 py-3",children:[t.jsx("h4",{className:"text-xs font-semibold text-foreground",children:"Suggested labs"}),x&&!g?t.jsxs("div",{className:"mt-2 flex items-center gap-2 text-xs text-muted-foreground",role:"status",children:[t.jsx(ic,{size:"sm",active:!0,label:"Loading suggested labs"}
12),"Loading suggested labsâ¦"]}):h&&z.length===0?t.jsxs("div",{className:"mt-2 space-y-2",children:[t.jsx("p",{className:"text-xs text-[var(--status-danger-text)]",children:h}),t.jsx(G,{type:"button",variant:"outline",size:"sm",onClick:()=>void(c==null?void 0:c()),children:"Try again"})]}):z.length===0?t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"No labs are suggested."}):t.jsx("ul",{className:"mt-2 space-y-2",children:z.map(m=>{var oe;return t.jsxs("li",{className:"text-xs",children:[t.jsx("span",{className:"font-medium text-foreground",children:m.product.name||m.product.displayName||m.id}),m.qualified?t.jsxs("span",{className:"mt-0.5 flex items-center gap-1 text-[var(--status-success-text)]",children:[t.jsx(lc,{className:"size-3.5","aria-hidden":"true"}),"Qualifies"]}):t.jsxs("span",{className:"mt-0.5 block leading-relaxed text-[var(--status-danger-text)]",children:[t.jsxs("span",{className:"flex items-start gap-1",children:[t.jsx(cc,{className:"mt-0.5 size-3.5 shrink-0","aria-hidden":"true"}),"Missing ",m.missing.map(de=>de.name).join(", ")||"biomarker data"]}),((oe=m.nonguaranteedMatches)==null?void 0:oe.length)>0?t.jsxs("span",{className:"mt-0.5 block pl-5 text-muted-foreground",children:["Only conditionally listed: ",m.nonguaranteedMatches.map(de=>de.name).join(", ")]}):null]})]},m.id)})}),q?t.jsx(nd,{}):null]})]}):t.jsx("p",{className:"px-4 py-5 text-sm text-muted-foreground",children:"This protocol does not require lab results."}):t.jsx("p",{className:"px-4 py-5 text-sm text-muted-foreground",children:"Lab requirements are not available for this item type."}),o?t.jsx("div",{className:"border-t border-border px-4 py-3",children:t.jsx(G,{type:"button",className:"w-full text-primary-foreground",style:d?{backgroundColor:d}:void 0,onClick:()=>{U(!1),w(r)},children:"Edit protocol"})}):null]})]})}function Bd({product:r,overlay:o,canManageCatalog:d,onOpenStorefront:n}){const c=!!o&&(o.status||"active")!=="inactive",u=c&&o.showPatient!==!1,h=o==null?void 0:o.customerPrice,g=h!=null&&h!=="",x=o?u?"Visible":c?"Hidden":"Unlisted":"Not listed",w=u?"green":c?"amber":"slate",L=t.jsxs("span",{className:"inline-flex flex-col items-center gap-0.5",children:[t.jsx("span",{className:"text-metric text-xs text-content-primary max-lg:text-2xs",children:g?uc(h):"â"}),t.jsx(es,{variant:"outline",className:Us(w,"max-lg:px-1.5"),children:x})]});return!d||typeof n!="function"?t.jsx("span",{className:"inline-flex w-full justify-center px-2 py-1",children:L}):t.jsx(G,{type:"button",variant:"ghost","data-row-click-ignore":!0,className:ye(Zt,"inline-flex h-auto w-full justify-center rounded-none py-1.5 font-medium hover:bg-surface-sunken","max-lg:px-2 max-lg:py-1 max-lg:text-2xs"),"aria-label":`Edit storefront settings for ${r.name||"catalog item"}`,"data-testid":ae("button","products","row-storefront-trigger"),onClick:()=>n(r),children:L})}const Ad=s.memo(function({product:o,columnWidths:d,canManageCatalog:n,isClinicalReadOnlyRole:c=!1,isSelected:u,isSavingCategories:h,productSearch:g,accentColor:x,productFormCountById:w,productFormularyCountById:L,productActiveClientCountById:S={},productClientAssignmentIdsById:U={},productActiveClientCountsLoaded:f=!0,providerNetworkClientOptions:B=[],clientProductAssignmentSavingKey:q="",assignableNetworkCategories:X,onToggleSelection:A,onSaveCategories:re,onSaveName:z,onOpenEditProduct:O,onOpenStatusDialog:v,onActivateProduct:p,productStatusSaving:m=!1,productStatusSavingId:oe=null,onOpenFormularyDialog:de,onSaveSyncVisit:ue,onSaveLegitScript:F,canEditLegitScript:_=!1,onToggleClientAssignment:k,onClientsPopoverOpenChange:be,clientProductAssignmentsLoading:me=!1,getProductActions:pt,showProviderNetworkColumns:V=!0,storefront:Me=null,onOpenStorefront:T=null}){var He;const[I,M]=s.useState(!1),[H,ce]=s.useState(o.categories||[]),he=$r(o.categories||[],X),ve=he.map(W=>W.id),we=$r(H,X).length,[qe,Qe]=s.useState(!1),[ns,Et]=s.useState(!1),[is,ft]=s.useState(!1),[yt,Oe]=s.useState(null);s.useEffect(()=>Oe(null),[o.id,o.requiresSyncVisit]),s.useEffect(()=>ce(o.categories||[]),[o.categories]),s.useEffect(()=>Qe(!1),[o.id]);const Re=yt??o.requiresSyncVisit===!0,Ze=w[o.id],bt=Number.isFinite(Ze),et=L[o.id],ht=Number.isFinite(et),De=S[o.id],Ve=Number.isFinite(De),Ne=U[o.id]||[],ls=new Set(Ne),ge=c?B.filter(W=>ls.has(W.id)):B,tt=o.type==="product",pe=(o.status||"active")==="active",cs=m&&oe===o.id,$e=ke(n,"categories",V,d),ne=ke(n,"checkbox",V,d),xt=ke(n,"name",V,d),vt=ke(n,"type",V,d),Ue=ke(n,"status",V,d),_t=ke(n,"syncVisit",V,d),ze=ke(n,"labs",V,d),st=ke(n,"clients",V,d),at=ke(n,"forms",V,d),rt=ke(n,"formulary",V,d),Ke=ke(n,"documents",V,d),Mt=ke(n,"actions",V,d),ot=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"min-w-0 truncate font-medium text-content-primary",children:t.jsx(Uc,{text:o.name||"Untitled product",highlight:g})}),o.sourceProductId&&t.jsx(es,{variant:"outline",className:Us("teal","max-lg:shrink-0 max-lg:px-1.5"),children:"Adopted"}),Array.isArray(o.__excludedStates)&&o.__excludedStates.length>0?t.jsxs(es,{variant:"outline",className:Us("amber","max-lg:shrink-0 max-lg:px-1.5"),title:o.__excludedStates.join(", "),children:[o.__excludedStates.length," excluded"]}):null]});return t.jsxs(t.Fragment,{children:[n&&t.jsx(fe,{className:"cursor-pointer px-2 py-2 text-center select-none max-lg:py-1",style:ne,onClick:()=>A(o.id),"aria-label":`Select row ${o.name||"product"}`,children:t.jsx(ts,{checked:u,onClick:W=>W.stopPropagation(),onCheckedChange:()=>A(o.id),"aria-label":`Select ${o.name||"product"}`,"data-testid":ae("row","products","select")})}),t.jsx(fe,{className:"px-2 py-2 text-center max-lg:py-1",style:Ue,children:n?t.jsx(dc,{checked:pe,disabled:cs,"data-row-click-ignore":!0,onCheckedChange:W=>
12{if(W){p==null||p(o);return}v(o)},"aria-label":`${o.name||"catalog item"} ${pe?"active":"inactive"}`,"data-testid":ae("switch","products",`row-status-${o.id}`)}):t.jsxs(Cn,{children:[t.jsx(kn,{asChild:!0,children:t.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center","aria-label":`${o.status||"active"} status`,children:t.jsx("span",{className:ye("h-2.5 w-2.5 rounded-full",pe?"bg-emerald-500":"bg-red-500")})})}),t.jsx(Pn,{children:o.status||"active"})]})}),d!=null&&d.legitScript?t.jsx(fe,{className:"p-2 text-center",style:{width:d.legitScript,maxWidth:d.legitScript},children:["product","protocol"].includes(o.type)?t.jsx(zc,{approved:o.legitScriptApproved===!0,canEdit:_,productName:o.name,onChange:W=>F(o.id,W)}):t.jsx("span",{"aria-label":"Not applicable",children:"â"})}):null,t.jsx(fe,{className:"p-0 align-middle",style:xt,children:n&&typeof z=="function"?t.jsx(id,{open:qe,onOpenChange:Qe,initialValue:o.name||"",accentColor:x,saving:ns,onSave:async W=>{Et(!0);try{await z(o.id,W)&&Qe(!1)}finally{Et(!1)}},trigger:t.jsx(G,{type:"button",variant:"ghost","data-row-click-ignore":!0,className:"flex size-full min-w-0 items-center justify-start gap-2 rounded-none p-2 text-left hover:bg-muted max-lg:gap-1 max-lg:py-1","aria-label":`Edit name for ${o.name||"catalog item"}`,children:ot})}):t.jsx("div",{className:"flex items-center gap-2 p-2 max-lg:gap-1 max-lg:py-1",children:ot})}),t.jsx(fe,{className:"py-2 max-lg:py-1",style:vt,children:t.jsx(es,{variant:"outline",className:Us(o.type==="protocol"?"purple":"blue","max-lg:px-1.5"),children:Ln(o.type)})}),t.jsx(fe,{className:"p-0 align-middle",style:$e,children:n?t.jsxs(as,{open:I,onOpenChange:M,children:[t.jsx(rs,{asChild:!0,children:t.jsx(G,{type:"button",variant:"ghost",className:"h-auto w-full justify-start rounded-none py-2","aria-label":`Edit categories for ${o.name}`,children:t.jsx(zr,{items:he,selectedIds:ve,emptyLabel:"No categories",tone:"slate"})})}),t.jsxs(os,{accessibleLabel:`Categories for ${o.name}`,className:"w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-subtle p-0 shadow-lg",align:"center",sideOffset:8,children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-3 py-2.5",children:[t.jsx("p",{className:"text-sm font-semibold text-content-primary",children:"Categories"}),t.jsxs("span",{className:"text-xs text-content-tertiary",children:[we," selected"]})]}),t.jsx("div",{className:"p-3",children:t.jsx(Hs,{label:"Categories",items:X,selectedIds:H,disabled:h,emptyLabel:"No categories available.",onToggle:async(W,wt)=>{const We=H,St=wt?[...new Set([...We,W.id])]:We.filter(J=>J!==W.id);ce(St),await re(o.id,St)||ce(We)}})})]})]}):t.jsxs(as,{children:[t.jsx(rs,{asChild:!0,children:t.jsx(G,{type:"button",variant:"ghost",className:"h-auto w-full justify-start rounded-none py-2","aria-label":`Categories for ${o.name}`,children:t.jsx(zr,{items:he,selectedIds:ve,emptyLabel:"No categories",tone:"slate"})})}),t.jsxs(os,{accessibleLabel:"Categories",className:"w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-subtle p-0 shadow-lg",align:"center",sideOffset:8,children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-3 py-2.5",children:[t.jsx("p",{className:"text-sm font-semibold text-content-primary",children:"Categories"}),t.jsxs("span",{className:"text-xs text-content-tertiary",children:[ve.length," selected"]})]}),t.jsx("div",{className:"p-3",children:t.jsx(Hs,{label:"Categories",items:he,selectedIds:ve,disabled:!0,emptyLabel:"No categories assigned."})})]})]})}),V?t.jsx(fe,{className:"py-2 text-center max-lg:py-1",style:_t,children:n&&typeof O=="function"&&!Re?t.jsx(G,{type:"button",variant:"ghost",size:"sm","aria-label":`Edit ${o.name||"catalog item"} to require a sync visit`,onClick:()=>O(o),children:"No"}):n?t.jsx(G,{type:"button",variant:"ghost",size:"sm",disabled:is,"aria-label":`Require sync visit for ${o.name}`,"aria-pressed":Re,onClick:async()=>{ft(!0);try{await ue(o.id,!Re)&&Oe(!Re)}finally{ft(!1)}},children:Re?"Yes":"No"}):t.jsx("span",{className:"text-sm text-foreground",children:Re?"Yes":"No"})}):null,V?t.jsx(fe,{className:"py-2 text-center max-lg:py-1",style:ze,children:c?o.requiresLabs===!0?t.jsx(es,{variant:"outline",className:Us("green","max-lg:px-1.5"),children:"Yes"}):t.jsx("span",{className:"text-[10px] font-semibold text-slate-500 dark:text-slate-400",children:"No"}):t.jsx(Ld,{product:o,canManageCatalog:n,accentColor:x,triggerClassName:"max-lg:px-2 max-lg:py-1"})}):null,V?t.jsx(fe,{className:"p-0 align-middle text-center text-sm font-medium text-slate-700 max-lg:text-2xs dark:text-slate-200",style:st,children:Me?t.jsx(Bd,{product:o,overlay:((He=Me.overlayByProductId)==null?void 0:He[o.id])||null,canManageCatalog:n,onOpenStorefront:T}):t.jsxs(as,{onOpenChange:W=>{W&&(be==null||be(o))},children:[t.jsx(rs,{asChild:!0,children:t.jsx("button",{type:"button",className:ye(Zt,"inline-flex justify-center hover:bg-slate-50 dark:hover:bg-slate-700/40","max-lg:px-2 max-lg:py-1 max-lg:text-2xs"),"aria-label":`View client assignments for ${o.name||"catalog item"}`,"data-testid":ae("button","products","row-clients-trigger"),children:t.jsx("span",{className:"text-metric text-sm text-content-primary max-lg:text-2xs",children:jn(f?Ne.length:De,"client",{loaded:f||Ve})})})}),t.jsxs(os,{className:"w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-subtle p-0 shadow-lg dark:bg-slate-900",align:"center",sideOffset:8,accessibleLabel:"Client protocol assignments","data-testid":ae("dialog","products","row-clients"),children:[t.jsxs("div",{className:"border-b border-subtle px-3 py-2 max-lg:px-2 max-lg:py-1.5",children:[t.jsx("p",{className:"text-sm font-semibold text-content-primary max-lg:text-xs",children:"Clients"}),t.jsx("p",{className:"text-xs text-content-tertiary max-lg:text-3xs max-lg:leading-tight",children:f?`${Ne.length} assigned`:me?"Loading assignmentsâ¦":"Open to load assignments"})]}),t.jsx("div",{className:"p-3",children:t.jsx(Hs,{label:"Clients",items:ge,selectedIds:Ne,s
12avingIds:q.startsWith(`${o.id}::`)?[q.split("::")[1]]:[],loading:me&&!f,disabled:!n,emptyLabel:c?"No clients are assigned to this item.":"No clients are linked to this provider network.",onToggle:(W,wt)=>k==null?void 0:k(o,W.id,wt)})})]})]})}):null,t.jsx(fe,{className:ye("p-0 align-middle",Wo("purple",{hasValue:bt&&Ze>0,interactive:!0})),style:at,children:t.jsx(Id,{product:o,readOnly:!n,formCount:Ze,triggerClassName:ye(Zt,"inline-flex max-w-full items-center","max-lg:px-2 max-lg:py-1 max-lg:text-2xs")})}),n&&t.jsx(fe,{className:ye("p-0 align-middle",Wo("cyan",{hasValue:tt&&ht&&et>0,interactive:tt})),style:rt,children:tt?t.jsx("button",{type:"button",className:ye(Zt,"inline-flex max-w-full items-center","max-lg:px-2 max-lg:py-1 max-lg:text-2xs"),onClick:()=>de(o),"aria-label":`Manage formulary defaults for ${o.name||"catalog item"}`,"data-testid":ae("button","products","row-formulary-trigger"),children:t.jsx("span",{className:"truncate",children:ht?`${et} mapped`:"Loadingâ¦"})}):t.jsx("span",{className:ye(Zt,"inline-flex items-center font-normal opacity-70","max-lg:px-2 max-lg:py-1 max-lg:text-2xs"),children:"â"})}),t.jsx(fe,{className:"p-0 align-middle",style:Ke,children:t.jsx(jd,{product:o,readOnly:!n})}),n&&t.jsx(fe,{className:"py-2 text-center max-lg:py-1",style:Mt,children:t.jsx(Hc,{actions:pt(o),label:`Open actions for ${o.name||"catalog item"}`,testId:ae("menu","products",`row-${o.id}`)})})]})});function dn({canManageCatalog:r,networkSortKey:o,networkSortDirection:d,handleNetworkSort:n,allVisibleNetworkProductsSelected:c,someVisibleNetworkProductsSelected:u,toggleAllVisibleNetworkProducts:h,showProviderNetworkColumns:g=!0,clientsColumnLabel:x="Clients",columnWidths:w,onResizeStart:L,onColumnWidthChange:S}){const U=[...r?[{id:"checkbox",label:"Selection"}]:[],{id:"status",label:"Status",sort:"status"},...w.legitScript?[{id:"legitScript",label:"LS"}]:[],{id:"name",label:"Name",sort:"name"},{id:"type",label:"Type",sort:"type"},{id:"categories",label:"Categories",sort:"categories.0"},...g?[{id:"syncVisit",label:"Sync visit?",sort:"requiresSyncVisit"},{id:"labs",label:"Labs?",sort:"requiresLabs"},{id:"clients",label:x,sort:"__activeClientCount"}]:[],{id:"forms",label:"Forms",sort:"__formCount"},...r?[{id:"formulary",label:"Formulary",sort:"__formularyCount"}]:[],{id:"documents",label:"Documents",sort:"knowledgeBaseItemIds.length"},...r?[{id:"actions",label:"Actions"}]:[]];return t.jsx(Ur,{children:U.map(f=>t.jsxs(qc,{className:`${Pd} relative h-9 px-2`,style:ke(r,f.id,g,w),title:f.id==="legitScript"?"LegitScript approval":void 0,"aria-label":f.id==="legitScript"?"LegitScript approval":void 0,"aria-sort":f.sort?o===f.sort?d==="asc"?"ascending":"descending":"none":void 0,children:[f.id==="checkbox"?t.jsx(ts,{checked:c?!0:u?"indeterminate":!1,onCheckedChange:B=>h(B===!0),"aria-label":"Select all visible products"}):f.sort?t.jsxs(G,{type:"button",variant:"ghost",className:"h-8 w-full min-w-0 justify-start gap-1 rounded-none px-0 text-xs",onClick:()=>n(f.sort),"aria-label":`Sort by ${f.label}`,children:[t.jsx("span",{className:"truncate",children:f.label}),o===f.sort&&(d==="asc"?t.jsx(ld,{className:"size-3 shrink-0"}):t.jsx(cd,{className:"size-3 shrink-0"}))]}):f.label,t.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":`Resize ${f.label} column`,"aria-valuenow":w[f.id],"aria-valuemin":f.id==="checkbox"?36:56,"aria-valuemax":800,tabIndex:0,className:"absolute right-0 top-0 h-full w-1.5 cursor-col-resize touch-none border-r border-border hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onPointerDown:B=>L(B,f.id,w[f.id]),onKeyDown:B=>{["ArrowLeft","ArrowRight"].includes(B.key)&&(B.preventDefault(),S(f.id,w[f.id]+(B.key==="ArrowRight"?20:-20)))}})]},f.id))})}const An={current:{}},Tn=s.forwardRef(function(o,d){const{item:n,children:c,...u}=o;delete u.context;const h=An.current,x=((n&&typeof h.getProductActions=="function"?h.getProductActions(n):[])||[]).filter(Boolean);return t.jsx("tr",{ref:d,...u,className:ye("border-b border-subtle transition-colors dark:hover:bg-slate-700/40",u.className),onContextMenu:x.length&&n?w=>{var L;w.target.closest("[data-row-click-ignore]")||(L=h.openContextMenu)==null||L.call(h,w,n,x)}:void 0,children:c})});Tn.displayName="NetworkCatalogVirtuosoRow";const Td=s.lazy(()=>Xe(()=>import("./MessageTemplatesDialog-B1HeT6bA.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])).then(r=>({default:r.MessageTemplatesDialog}
12))),Rd=s.lazy(()=>Xe(()=>import("./ProtocolPresetsDialog-C7ciBSDM.js"),__vite__mapDeps([24,1,3,4,5,6,25,26,27,28])).then(r=>({default:r.ProtocolPresetsDialog})));function ja({label:r,value:o,positiveLabel:d,negativeLabel:n,positiveCount:c,negativeCount:u,onChange:h}){return t.jsx(Ra,{filters:[{id:"yes",label:d,count:c},{id:"no",label:n,count:u}],activeFilters:o==="any"?[]:[o],onFilterChange:g=>h(g[0]||"any"),multiSelect:!1,defaultLabel:r})}function Dd(r,o,d){return r.map(n=>t.jsx("button",{type:"button",role:"menuitem",onClick:c=>{var u;c.stopPropagation(),(u=n.onSelect)==null||u.call(n,o,c),d()},disabled:n.disabled,className:ye("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 transition-colors hover:bg-accent focus:bg-accent disabled:pointer-events-none disabled:opacity-50","max-lg:py-1 max-lg:text-xs",n.danger&&"text-red-600 focus:text-red-600 dark:text-red-400 dark:focus:text-red-400",n.className),children:t.jsx("span",{children:n.label})},n.id||n.label))}function Fd(){const r=Ma(),{accentColor:o,allVisibleNetworkProductsSelected:d,assignableNetworkCategories:n,catalogOwnerId:c,catalogScope:u,bulkCategorySaving:h,bulkDeleteSaving:g,bulkExcludedStatesSaving:x,bulkKnowledgeBaseSaving:w,bulkStatusSaving:L,canManageCatalog:S,catalogItemLabel:U,catalogItemLabelPlural:f,catalogLabelTitle:B,catalogScrollParent:q,exportTenantSlug:X,exportUserType:A,fetchAllNetworkProducts:re,filteredCount:z,filteredNetworkProducts:O,getNetworkProductActions:v,handleBulkProductStatus:p,handleNetworkSort:m,handleProductRowCategoriesSave:oe,handleProductRowNameSave:de,handleProductRowSyncVisitSave:ue,handleProductRowLegitScriptSave:F,legitScriptEnabled:_,hasMore:k,isMobileOrTablet:be,isBusinessCatalog:me,knowledgeBaseLabelById:pt,loading:V,loadingMore:Me,loadMore:T,networkCatalogContextMenu:I,networkCatalogViewportHeight:M,networkCatalogViewportRef:H,networkCategoryNameById:ce,networkProducts:he,networkProductCategoryFilterOptions:ve,networkSortDirection:we,networkSortKey:qe,openCreateProductDialog:Qe,openFormularyDialog:ns,openManageCategoriesDialog:Et,openNetworkCatalogContextMenu:is,openProductStatusDialog:ft,handleActivateProduct:yt,productStatusSaving:Oe,productStatusSavingId:Re,openTemplatesDialog:Ze,clientProductAssignmentSavingKey:bt,handleClientProductAssignmentToggle:et,createOptions:ht,catalogToolbarExtras:De,storefront:Ve,openEditProductDialog:Ne,productActiveClientCountById:ls,productClientAssignmentIdsById:ge,productActiveClientCountsLoaded:tt,clientProductAssignmentsLoading:pe,ensureClientProductAssignmentsLoaded:cs,productCategoryFilters:$e,productFilterCounts:ne,productFormCountById:xt,productFormsFilter:vt,productFormularyFilter:Ue,productFormularyCountById:_t,productLabsFilter:ze,productSearch:st,productStatusFilters:at,productSyncVisitFilter:rt,productTypeFilters:Ke,providerNetworkClientOptions:Mt,rowCategorySavingProductId:ot,selectedNetworkProductIds:He,setBulkCategoryDialogOpen:W,setBulkCategoryIds:wt,setBulkDeleteDialogOpen:We,setBulkExcludedStates:St,setBulkExcludedStatesDialogOpen:J,setBulkImportOpen:qa,setBulkKnowledgeBaseDialogOpen:Ie,setBulkKnowledgeBaseIds:ds,setNetworkCatalogContextMenu:Ws,setProductCategoryFilters:Ys,setProductFormsFilter:qt,setProductFormularyFilter:Ct,setProductLabsFilter:Gs,setProductSearch:kt,setProductStatusFilters:nt,setProductSyncVisitFilter:it,setProductTypeFilters:lt,setSelectedNetworkProductIds:Pt,shouldFillCatalogViewport:Ot,someVisibleNetworkProductsSelected:Vt,sortedNetworkProducts:je,toggleAllVisibleNetworkProducts:us,toggleNetworkProductSelection:Js,totalCount:$t,usesProtocolLabels:Xs}=r;An.current={getProductActions:v,openContextMenu:is};const[Ut,Qs]=s.useState(!1),[zt,ms]=s.useState(!1),Nt=s.useRef(null),[Zs,gs]=s.useState(!1),ea=S&&u==="provider_network"&&!!c,Pe=!me&&Aa(r.userType,["Provider","Provider Network Admin","Provider Delegate"]),K=!me,{widths:Se,startResize:ps,setWidth:It}=kd(Yr(S,K,_)),ta=Object.values(Se).reduce((N,j)=>N+j,0),fs=Aa(r.userType,["Provider","Provider Delegate"])||!!Ve&&!S,ys=Object.keys(Se).length,bs=s.useMemo(()=>{const N=[{header:"Name",csvValue:j=>j.name||"Untitled product"},{header:"Type",csvValue:j=>Ln(j.type)},{header:"Categories",csvValue:j=>$r(j.categories||[],n).map(Ye=>
12Ye.name||"Category")},{header:"Status",csvValue:j=>j.status||"active"}];return K&&N.push({header:"Sync visit?",csvValue:j=>j.requiresSyncVisit===!0?"Yes":"No"},{header:"Labs?",csvValue:j=>j.requiresLabs===!0?"Yes":"No"},{header:"Clients",csvValue:j=>Number.isFinite(j.clientAssignmentCount)?j.clientAssignmentCount:0}),S&&N.push({header:"Forms",csvValue:j=>Number.isFinite(j.formCount)?j.formCount:0},{header:"Formulary",csvValue:j=>Number.isFinite(j.formularyCount)?j.formularyCount:0}),N.push({header:"Documents",csvValue:j=>Array.isArray(j.knowledgeBaseItemIds)?j.knowledgeBaseItemIds.length:0}),N},[S,n,K]),Oa=s.useMemo(()=>({getRows:me?()=>je:async()=>{const{rows:N,truncated:j}=await re();return{rows:N,truncated:j}}}),[re,me,je]),Kt=s.useMemo(()=>{const N=[{header:"Name",key:"name"},{header:"Type",key:"type"},{header:"Categories",key:"categories"},{header:"Status",key:"status"}];return K&&N.push({header:"Sync visit?",key:"requiresSyncVisit"},{header:"Labs?",key:"requiresLabs"},{header:"Clients",key:"clientAssignmentCount"}),S&&N.push({header:"Forms",key:"formCount"},{header:"Formulary",key:"formularyCount"}),N.push({header:"Documents",key:"knowledgeBaseItemCount"}),N},[S,K]),Va=s.useMemo(()=>me?null:{mode:"server",onExport:async()=>{const{rowCount:N,truncated:j}=await Fc({userType:A,entity:"products",columns:Kt,tenantSlug:X}),Ye=Number(N||0).toLocaleString();j?y.warning(`Exported ${Ye} ${f} (capped). Narrow the data set for a complete export.`):y.success(`Exported ${Ye} ${U}${N===1?"":"s"}.`)}},[Kt,U,f,X,A,me]),sa=s.useMemo(()=>({Table:({context:N,...j})=>t.jsxs("table",{...j,className:ye("w-full caption-bottom text-sm table-fixed",K?"max-lg:min-w-[1180px]":"max-lg:min-w-[880px]","max-lg:text-2xs"),style:{tableLayout:"fixed",width:N.tableWidth,minWidth:"100%"},"aria-label":"Network catalog products","data-testid":ae("table","products","network-catalog"),children:[ln(S,K,N.columnWidths),j.children]}),TableRow:Tn,Footer:()=>Me?t.jsx("div",{className:"py-3 text-center text-xs text-content-tertiary max-lg:py-2 max-lg:text-2xs",children:"Loading more..."}):null}),[S,Me,K]),$a=s.useCallback(()=>t.jsx(dn,{columnWidths:Se,onResizeStart:ps,onColumnWidthChange:It,canManageCatalog:S,networkSortKey:qe,networkSortDirection:we,handleNetworkSort:m,allVisibleNetworkProductsSelected:d,someVisibleNetworkProductsSelected:Vt,toggleAllVisibleNetworkProducts:us,showProviderNetworkColumns:K,clientsColumnLabel:Ve?"Storefront":"Clients"}),[Se,ps,It,d,S,m,we,qe,Ve,K,Vt,us]);return t.jsxs(t.Fragment,{children:[t.jsxs(Nn,{className:"flex flex-col overflow-hidden rounded-xl border border-subtle dark:bg-slate-800 max-lg:block",children:[t.jsxs("div",{className:"shrink-0 border-b border-subtle bg-surface-sunken p-3 max-lg:p-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 max-lg:flex-nowrap max-lg:gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2 max-lg:min-w-0 max-lg:flex-1",children:[t.jsx("div",{className:"rounded-lg p-1.5 text-white max-lg:shrink-0 max-lg:p-1",style:{backgroundColor:o},children:t.jsx(In,{className:"size-4 max-lg:size-3"})}),t.jsxs("div",{className:"max-lg:min-w-0 max-lg:flex-1",children:[t.jsx("h2",{className:"text-sm font-semibold text-content-primary max-lg:truncate max-lg:text-xs",children:Xs?"Protocols":`${B} Catalog`}),t.jsxs("p",{className:"text-xs text-content-tertiary max-lg:text-3xs max-lg:leading-tight",children:[typeof z=="number"?z:(O==null?void 0:O.length)??0," of ",typeof $t=="number"?$t:(he==null?void 0:he.length)??0]})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 max-lg:max-w-[60%] max-lg:shrink-0 max-lg:flex-nowrap max-lg:justify-end max-lg:gap-1 max-lg:overflow-x-auto max-lg:[&>*]:shrink-0 max-lg:[&_button]:h-6 max-lg:[&_button]:min-h-6 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:[&_[role=button]]:h-6 max-lg:[&_[role=button]]:min-h-6 max-lg:[&_[role=button]]:min-w-0 max-lg:[&_[role=button]]:px-2 max-lg:[&_[role=button]]:text-3xs max-lg:[&_svg]:h-3 max-lg:[&_svg]:w-3",children:[t.jsx(Mc,{feature:f,tenantSlug:X,columns:bs,view:Oa,rawExport:me?{getRows:()=>je}:{resolveRows:N=>Ec({rows:N,collectionPath:["ProviderNetworks",c,"Products"]})},allData:Va,hoverRevealTrigger:!0}),t.jsx(Xt,{icon:t.jsx(Sd,{className:"size-3.5"}),label:"Templates",onClick:Ze}),t.jsx(Xt,{icon:t.jsx(vd,{className:"size-3.5"}),label:"Categories",onClick:Et}
12),ea?t.jsx(Kc,{ref:Nt,scope:{type:"provider_network",id:c},products:he,accentColor:o,showTriggerButton:!1,enableClinicalPolicies:!0}):null,Pe&&t.jsx(Xt,{icon:t.jsx(dd,{className:"size-3.5"}),label:"Message Templates",onClick:()=>Qs(!0),"data-testid":ae("button","products","message-templates")}),S&&!me?t.jsx(Xt,{icon:t.jsx(mc,{className:"size-3.5","aria-hidden":!0}),label:"Presets",onClick:()=>ms(!0),"data-testid":ae("button","products","protocol-presets")}):null,S&&t.jsx(Xt,{icon:t.jsx(gc,{className:"size-3.5"}),label:"Bulk Import",onClick:()=>qa(!0)}),De,S&&t.jsx(Xt,{variant:"default",icon:t.jsx(pc,{className:"size-3.5"}),label:"Create",className:"border-transparent text-white",style:{backgroundColor:o},onClick:()=>gs(!0)})]})]}),t.jsxs("div",{className:"mt-3 space-y-2 max-lg:mt-2 max-lg:space-y-1.5",children:[t.jsxs("div",{className:"relative w-full",children:[t.jsx(fc,{className:"absolute left-2 top-1/2 size-3 -translate-y-1/2 text-slate-400"}),t.jsx(yc,{value:st,onChange:N=>kt(N.target.value),placeholder:"Search productsâ¦","aria-label":"Search network catalog products","data-testid":ae("input","products","network-search"),dense:!0,className:"pl-7 h-8 text-xs max-lg:h-7 max-lg:py-1 dark:bg-slate-700 dark:border-slate-600"})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 max-lg:flex-nowrap max-lg:items-center 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:[t.jsx(Ra,{filters:[{id:"active",label:"Active",count:ne.status.active},{id:"inactive",label:"Inactive",count:ne.status.inactive}],activeFilters:at,onFilterChange:nt,multiSelect:!0,defaultLabel:"All statuses"}),t.jsx(Ra,{filters:[{id:"product",label:"Products",count:ne.type.product},{id:"protocol",label:"Protocols",count:ne.type.protocol},{id:"treatment",label:"Treatments",count:ne.type.treatment}],activeFilters:Ke,onFilterChange:lt,multiSelect:!0,defaultLabel:"All types"}),t.jsx(Ra,{filters:ve,activeFilters:$e,onFilterChange:Ys,multiSelect:!0,defaultLabel:"All categories",searchable:!0}),t.jsx(ja,{label:"Has Forms",value:vt,positiveLabel:"Has intake",negativeLabel:"No intake",positiveCount:ne.forms.yes,negativeCount:ne.forms.no,onChange:qt}),t.jsx(ja,{label:"Has Formulary",value:Ue,positiveLabel:"Has formulary",negativeLabel:"No formulary",positiveCount:ne.formulary.yes,negativeCount:ne.formulary.no,onChange:Ct}),t.jsx(ja,{label:"Requires Labs",value:ze,positiveLabel:"Requires labs",negativeLabel:"Does not require labs",positiveCount:ne.labs.yes,negativeCount:ne.labs.no,onChange:Gs}),t.jsx(ja,{label:"Telehealth Visit",value:rt,positiveLabel:"Telehealth visit required",negativeLabel:"No telehealth visit required",positiveCount:ne.syncVisit.yes,negativeCount:ne.syncVisit.no,onChange:it}),(st||at.length>0||Ke.length>0||$e.length>0||vt!=="any"||Ue!=="any"||ze!=="any"||rt!=="any")&&t.jsx(G,{variant:"ghost",size:"sm",onClick:()=>{kt(""),nt(["active"]),lt([]),Ys([]),qt("any"),Ct("any"),Gs("any"),it("any")},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"})]}),S&&He.length>0&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border bg-white p-2 max-lg:flex-nowrap max-lg:gap-1 max-lg:overflow-x-auto max-lg:[&>*]:shrink-0 max-lg:[&_button]:h-6 max-lg:[&_button]:min-h-6 max-lg:[&_button]:px-2 max-lg:[&_button]:text-3xs max-lg:[&_svg]:h-3 max-lg:[&_svg]:w-3 dark:border-slate-600 dark:bg-slate-900",style:{borderColor:o},children:[t.jsxs("span",{className:"text-sm font-medium text-slate-800 max-lg:text-2xs dark:text-slate-100",children:[He.length," selected"]}),t.jsx(G,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>p("active"),disabled:L||h||w||g||x,children:"Activate"}),t.jsx(G,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>p("inactive"),disabled:L||h||w||g||x,children:"Deactivate"}),t.jsx(G,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>{wt([]),W(!0)},disabled:L||h||w||g||x,children:"Add Category"}),t.jsx(G,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>{ds([]),Ie(!0)},disabled:L||h||w||g||x,children:"Link Knowledge Base"}),t.jsx(G,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>{St([]),J(!0)},disabled:L||h||w||g||x,children:"Excluded States"}),t.jsxs(G,{size:"sm",variant:"outline",className:"h-7 text-xs text-red-600 hover:text-red-700",onClick:()=>We(!0),disabled:L||h||w||g||x,children:[t.jsx(bc,{className:"mr-1 size-3.5"}),"Delete"]}),t.jsx(G,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>Pt([]),children:"Clear selection"})]})]})]}),t.jsx("div",{ref:H,className:ye("min-w-0 overflow-x-auto",Ot&&"min-h-0 flex-1"),children:V||je.length===0?t.jsx("div",{className:ye(Ot&&"overflow-y-auto"),style:Ot?{height:M,maxHeight:M}:void 0,children:t.jsxs("table",{className:ye("w-full caption-bottom text-sm",K?"max-lg:min-w-[1180px]":"max-lg:min-w-[880px]","max-lg:text-2xs"),style:{tableLayout:"fixed",width:ta,minWidth:"100%"},"aria-label":"Network catalog products","data-testid":ae("table","products","network-catalog"),children:[ln(S,K,Se),t.jsx(Oc,{children:t.jsx(dn,{columnWidths:Se,onResizeStart:ps,onColumnWidthChange:It,canManageCatalog:S,networkSortKey:qe,networkSortDirection:we,handleNetworkSort:m,allVisibleNetworkProductsSelected:d,someVisibleNetworkProductsSelected:Vt,toggleAllVisibleNetworkProducts:us,showProviderNetworkColumns:K,clientsColumnLabel:Ve?"Storefront":"Clients"})}),t.jsx(Vc,{children:V?t.jsx(Ur,{className:"dark:border-slate-700",children:t.jsxs(fe,{colSpan:ys,className:"py-10 text-center text-sm text-content-tertiary max-lg:py-5 max-lg:text-xs",children:[t.jsx(hc,{className:"mx-auto mb-2 size-5 animate-spin max-lg:mb-1.5 max-lg:size-4"}
12),"Loading catalog..."]})}):t.jsx(Ur,{className:"dark:border-slate-700",children:t.jsx(fe,{colSpan:ys,className:"py-10 text-center text-sm text-content-tertiary max-lg:py-5 max-lg:text-xs",children:st||at.length>0||Ke.length>0||$e.length>0||vt!=="any"||Ue!=="any"||ze!=="any"||rt!=="any"?"No catalog items match your current search or filters.":"No catalog items found."})})})]})}):t.jsx(Sn,{delayDuration:200,children:t.jsx(Dc,{context:{columnWidths:Se,tableWidth:ta},data:je,endReached:k?T:void 0,...be&&q?{customScrollParent:q}:{},style:Ot?{height:M,width:"100%"}:{width:"100%"},computeItemKey:Nd,components:sa,fixedHeaderContent:$a,itemContent:(N,j)=>t.jsx(Ad,{columnWidths:Se,onSaveLegitScript:F,canEditLegitScript:S&&Aa(r.userType,["Provider Network Admin"]),product:j,canManageCatalog:S,isClinicalReadOnlyRole:fs,isSelected:He.includes(j.id),isSavingCategories:ot===j.id,productSearch:st,accentColor:o,knowledgeBaseLabelById:pt,productFormCountById:xt,productFormularyCountById:_t,productActiveClientCountById:ls,productClientAssignmentIdsById:ge,productActiveClientCountsLoaded:tt,clientProductAssignmentsLoading:pe,providerNetworkClientOptions:Mt,clientProductAssignmentSavingKey:bt,onToggleClientAssignment:et,onClientsPopoverOpenChange:()=>{cs()},storefront:Ve,onOpenStorefront:Ye=>Ne(Ye,{initialTab:"storefront"}),showProviderNetworkColumns:K,networkCategoryNameById:ce,assignableNetworkCategories:n,onToggleSelection:Js,onSaveCategories:oe,onSaveName:de,onOpenEditProduct:Ne,onOpenStatusDialog:ft,onActivateProduct:yt,productStatusSaving:Oe,productStatusSavingId:Re,onOpenFormularyDialog:ns,onSaveSyncVisit:ue,getProductActions:v})})})})]}),t.jsx($c,{open:!!I,x:(I==null?void 0:I.x)??0,y:(I==null?void 0:I.y)??0,onOpenChange:N=>{N||Ws(null)},children:I?Dd(I.actions,I.product,()=>Ws(null)):null}),Ut?t.jsx(s.Suspense,{fallback:null,children:t.jsx(Td,{open:Ut,onOpenChange:Qs,accentColor:o,canManage:Pe})}):null,zt?t.jsx(s.Suspense,{fallback:null,children:t.jsx(Rd,{open:zt,onOpenChange:ms,providerNetworkId:c,clients:Mt,accentColor:o})}):null,S?t.jsx(xc,{open:Zs,onOpenChange:gs,title:"What would you like to create?",description:"Choose the clinical catalog item you want to add.",contentClassName:"max-w-2xl",contentTestId:ae("dialog","products","network-create-type"),children:t.jsx(_c,{accentColor:o,columns:ht.length>3?3:void 0,options:ht.map(N=>({id:N.id,icon:N.icon,title:N.title,description:N.description,onSelect:()=>{if(gs(!1),typeof N.onSelect=="function"){N.onSelect();return}Qe(N.type,N.kind)},testId:ae("button","products",`network-create-${N.id}`)}))})}):null]})}const Rn={status:{},type:{},categories:{},requiresSyncVisit:{},requiresLabs:{},hasFormularyMappings:{},hasForms:{},showPatient:{}},$s=[],un="Unable to load products. Please try again.",mn=15e3,Mr={loading:!1,loadingMore:!1,loaded:!1,products:[],filteredCount:0,totalCount:0,returnedCount:0,page:1,perPage:50,hasMore:!1,filterCounts:Rn,error:""},Ed={name:"nameSort",displayName:"displayNameSort",status:"statusSort",type:"type","categories.0":"categoryCount",requiresSyncVisit:"requiresSyncVisitSort",requiresLabs:"requiresLabsSort",__activeClientCount:"clientAssignmentCount",__formCount:"formCount",__formularyCount:"formularyCount","knowledgeBaseItemIds.length":"knowledgeBaseItemCount",createdAt:"createdAt",updatedAt:"updatedAt"};function _d(r){return r&&Ed[r]||"nameSort"}function gn(r={}){return{products:Array.isArray(r==null?void 0:r.products)?r.products:[],filteredCount:Number((r==null?void 0:r.filteredCount)||0),totalCount:Number((r==null?void 0:r.totalCount)||0),returnedCount:Number((r==null?void 0:r.returnedCount)||0),page:Number((r==null?void 0:r.page)||1),perPage:Number((r==null?void 0:r.perPage)||50),hasMore:(r==null?void 0:r.hasMore)===!0,filterCounts:(r==null?void 0:r.filterCounts)||Rn}}function Md(r,o=250){const[d,n]=s.useState(r);return s.useEffect(()=>{const c=window.setTimeout(()=>{n(r)},o);return()=>{window.clearTimeout(c)}},[o,r]),d}function qd(r={}){const{enabled:o=!0,searchTerm:d="",statusFilters:n=$s,typeFilters:c=$s,scopeTypeFilters:u=$s,categoryFilters:h=$s,requiresSyncVisit:g,requiresLabs:x,hasFormularyMappings:w,hasForms:L,showPatient:S,providerNetworkFilters:U=$s,initialSortKey:f="name",initialSortDirection:B="asc",perPage:q=50,refreshIntervalMs:X=6e4,searchDebounceMs:A=150}=r,re=Md(d,A),[z,O]=s.useState(f),[v,p]=s.useState(B),[m,oe]=s.useState(!1),[de,ue]=s.useState(0),[F,_]=s.useState({...Mr,perPage:q,loading:!!o}),k=s.useRef(0),be=s.useMemo(()=>{const T={entity:"products",query:re,statusFilters:n,typeFilters:c,scopeTypeFilters:u,categoryFilters:h,providerNetworkFilters:U,sortField:_d(z),sortDirection:v,prioritizeSort:m,perPage:q};return g!==void 0&&(T.requiresSyncVisit=g),x!==void 0&&(T.requiresLabs=x),w!==void 0&&(T.hasFormularyMappings=w),L!==void 0&&(T.hasForms=L),S!==void 0&&(T.showPatient=S),T},[h,re,L,w,q,U,m,x,g,S,v,z,u,n,c]);s.useEffect(()=>{let T=!1;if(!o){_(Mr);return}const I=k.current+1;return k.current=I,_(M=>({...M,loading:!0,loadingMore:!1,loaded:M.loaded,error:""})),Tr({...be,page:1,includeFacets:!0},{timeoutMs:mn,timeoutMessage:"Products search timed out. Please try again."}).then(M=>
12{if(T||k.current!==I)return;const H=gn(M);s.startTransition(()=>{_({...Mr,...H,loading:!1,loadingMore:!1,loaded:!0,error:""})})}).catch(M=>{T||k.current!==I||_(H=>({...H,loading:!1,loadingMore:!1,loaded:!0,error:(M==null?void 0:M.message)||un}))}),()=>{T=!0}},[o,be,de]),s.useEffect(()=>{const T=Number(X),I=Number.isFinite(T)&&T>0;if(!o||!I||typeof window>"u"||typeof document>"u")return;const M=()=>{document.visibilityState==="visible"&&ue(ce=>ce+1)},H=window.setInterval(M,T);return window.addEventListener("focus",M),document.addEventListener("visibilitychange",M),()=>{window.clearInterval(H),window.removeEventListener("focus",M),document.removeEventListener("visibilitychange",M)}},[o,X]);const me=s.useCallback(async()=>{if(!o||F.loading||F.loadingMore||!F.hasMore)return;const T=k.current,I=Number(F.page||1)+1;_(M=>({...M,loadingMore:!0,error:""}));try{const M=await Tr({...be,page:I,includeFacets:!1},{timeoutMs:mn,timeoutMessage:"Products search timed out. Please try again."});if(k.current!==T)return;const H=gn(M);s.startTransition(()=>{_(ce=>{const he=new Set(ce.products.map(we=>we.id)),ve=H.products.filter(we=>he.has(we.id)?!1:(he.add(we.id),!0));return{...ce,products:[...ce.products,...ve],filteredCount:H.filteredCount||ce.filteredCount,returnedCount:ce.returnedCount+ve.length,page:H.page||ce.page,perPage:H.perPage||ce.perPage,hasMore:H.hasMore,loading:!1,loadingMore:!1,loaded:!0,error:""}})})}
12catch(M){if(k.current!==T)return;_(H=>({...H,loadingMore:!1,error:(M==null?void 0:M.message)||un}))}},[o,be,F.hasMore,F.loading,F.loadingMore,F.page]);function pt(T){if(oe(!0),z===T){p(I=>I==="asc"?"desc":"asc");return}O(T),p("asc")}function V(){ue(T=>T+1)}const Me=s.useCallback(()=>o?vc({searchFn:Tr,requestBody:be,pickRows:T=>Array.isArray(T==null?void 0:T.products)?T.products:[],getCount:T=>Number((T==null?void 0:T.filteredCount)||0)}):Promise.resolve({rows:[],truncated:!1,total:0}),[o,be]);return{rows:F.products,products:F.products,filteredCount:F.filteredCount,totalCount:F.totalCount,filterCounts:F.filterCounts,loading:F.loading&&!F.loaded,searching:F.loading&&F.loaded,loadingMore:F.loadingMore,error:F.error,sortKey:z,sortDirection:v,handleSort:pt,refresh:V,fetchAllRows:Me,hasMore:F.hasMore,loadMore:me,source:"typesense"}}function Dn({businessId:r,providerNetworkId:o,productId:d}){return r?Ea(se,"Businesses",r,"Products",d):Ea(se,"ProviderNetworks",o,"Products",d)}function Fn({businessId:r,providerNetworkId:o}){if(r)return{businessId:r,providerNetworkId:null};if(o)return{businessId:null,providerNetworkId:o};throw new Error("Business or provider network is required")}function qr(r,o){const d=new Set((o||[]).map(n=>n.id).filter(Boolean));return(Array.isArray(r)?r:[]).filter(n=>d.has(n))}function Od({clientId:r,providerNetworkId:o,product:d,userId:n,existingClientProduct:c}){const u={clientId:r,providerNetworkId:o,productId:d.id,type:d.type||"product",status:"inactive",showPatient:!1,updatedAt:Kr(),updatedBy:n};return(!c||c.storageModel!=="scoped")&&(u.customerPrice=(c==null?void 0:c.customerPrice)??null,u.displayCategoryIds=(c==null?void 0:c.displayCategoryIds)||[],u.reviewNetworkLabel=(c==null?void 0:c.reviewNetworkLabel)||"",u.createdAt=Kr(),u.createdBy=n),u}const pn=450;function En(r={}){var d;const o=(d=Ta.currentUser)==null?void 0:d.uid;return{...r,updatedAt:Kr(),...o?{updatedBy:o}:{}}}async function _e(r,o,d){const n=Fn(r),c=Dn({...n,productId:o});await gd(c,En(d))}async function Or(r,o){const d=Fn(r),n=Array.isArray(o)?o.filter(c=>(c==null?void 0:c.productId)&&c.fields):[];if(n.length!==0)for(let c=0;c<n.length;c+=pn){const u=n.slice(c,c+pn),h=Bn(se);for(const{productId:g,fields:x}of u){const w=Dn({...d,productId:g});h.update(w,En(x))}await h.commit()}}const Vd=[{id:"product",type:"product",kind:"",icon:In,title:"Product",description:"A commercial item that can include clinical requirements and formulary mappings."},{id:"protocol",type:"protocol",kind:"",icon:wc,title:"Protocol",description:"A clinical protocol with rules, forms, and visit requirements."},{id:"treatment",type:"treatment",kind:"",icon:Sc,title:"Treatment",description:"A clearance-only treatment with forms and an optional telehealth visit."}];function gt(r=[]){return Array.from(new Set(r.map(o=>String(o||"").trim()).filter(Boolean)))}function $d(r={}){return gt([r.id,r.productId,r.sourceProductId])}function fn(r={}){return gt(Array.isArray(r.categories)?r.categories:[])}function yn({form:r,product:o,products:d=[],shouldPair:n}){const c=(r==null?void 0:r.associations)||{},u=$d(o),h=new Set(u),g=String((o==null?void 0:o.id)||"").trim(),x=gt([...Array.isArray(c.productIds)?c.productIds:[],c.productId]),w=gt(c.categoryIds);if(n&&c.applyToAll===!0)return{...c,applyToAll:!0,productIds:[],categoryIds:[]};if(n)return{applyToAll:c.applyToAll===!0,productIds:gt([...x,g]),categoryIds:w,clientIds:gt(c.clientIds),audienceType:c.audienceType||null};const L=new Set(fn(o)),S=c.applyToAll===!0||w.some(f=>L.has(f)),U=S?d.filter(f=>c.applyToAll===!0||fn(f).some(B=>w.includes(B))).map(f=>f.id):[];return{applyToAll:!1,productIds:gt([...x,...U]).filter(f=>!h.has(f)),categoryIds:S?[]:w,clientIds:gt(c.clientIds),audienceType:c.audienceType||null}}function Ud(r,{ownerField:o,ownerId:d,catalogScope:n}){return Array.isArray(r)?r.map(c=>({...c,[o]:d,catalogScope:n})):[]}const zd=["active","inactive"],Vr=new Map,Kd=["Formulary"],bn=400,te="gen-health.products.filters.provider-network.v1",La=["any","yes","no"],Ba=r=>typeof r=="string",Te=r=>Array.isArray(r)&&r.every(o=>
12typeof o=="string");function Hd(r){return Array.isArray(r)?r:Array.isArray(r==null?void 0:r.windows)?r.windows:[]}function Wd(r){const o=Hd(r);return _a(r).map((d,n)=>{const c=o.find(g=>(g==null?void 0:g.id)&&g.id===d.id)||o[n]||{},u={...d};delete u.approvedLabProductIds;const h=d.labs===!0?Fa(c):{requiredLabTests:[],requiredLabTestIds:[],suggestedLabProductIds:[]};return{...u,labRecencyUnit:ss(c.labRecencyUnit),...h}})}function Yd(r=[]){const o=Array.isArray(r)?r:[];return _a(o).map((d,n)=>{const c=o[n]||{},u={...d};delete u.approvedLabProductIds;const h=zs({...c,requiresLabs:d.labs===!0});return{...u,...ss(c.labRecencyUnit)==="minutes"?{labRecencyUnit:"minutes"}:{},...h}})}async function hn(r=[]){await Promise.all(r.map(({jobId:o,selectedBiomarkers:d})=>bd({action:"applyExtraction",jobId:o,selectedBiomarkers:d})))}function xn(r,o){return`${r||""}|${o||""}`}const vn=8;function Gd(r,o,d){const n=new Set,c=[];return o.forEach(u=>{const h=typeof u.data=="function"?u.data()||{}:u.data||{};if(h.providerNetworkId!==d)return;const g=String(h.productId||u.id||"").trim(),x=String(h.sourceProductId||"").trim();g&&n.add(g),x&&n.add(x),g&&u.id===g&&!x&&c.push([`${r}::${g}`,{id:u.id,...h,productId:g,storageModel:h.storageModel||"scoped"}])}),{assignedProductIds:n,assignmentEntries:c}}function Jd(r,o,d){const n=new Map,c=new Map;r.forEach(g=>{const x=o.get(g)||[],{assignedProductIds:w,assignmentEntries:L}=Gd(g,x,d);L.forEach(([S,U])=>c.set(S,U)),w.forEach(S=>{n.has(S)||n.set(S,new Set),n.get(S).add(g)})});const u={},h={};return n.forEach((g,x)=>{u[x]=g.size,h[x]=Array.from(g)}),{productActiveClientCountById:u,productClientAssignmentIdsById:h,clientProductAssignmentByClientAndProduct:Object.fromEntries(c.entries())}}async function Xd(r,o){const d=Ea(se,"Clients",r,"Products",o);return[...(await Promise.all(Kd.map(c=>Da(Ks(d,c))))).flatMap(c=>c.docs.map(u=>u.ref)),d]}async function Qd(r=[]){for(let o=0;o<r.length;o+=bn){const d=Bn(se);r.slice(o,o+bn).forEach(n=>d.delete(n)),await d.commit()}}async function Zd(r,o){const d=await Xd(r,o);await Qd(d)}function eu({embedded:r=!1,showHeader:o=!0,providerNetworkId:d=null,businessId:n=null,brandingOverride:c=null,userTypeOverride:u=null,readOnlyOverride:h=null,createOptions:g=null,storefrontClientId:x=null,catalogLabel:w=null,usesProtocolLabels:L=null,catalogToolbarExtras:S=null}){const{branding:U}=Cc(),{userDoc:f,providerNetwork:B,businessData:q,isReadOnly:X,userType:A,availableClients:re=[]}=kc(),z=c||U,O=n||(f==null?void 0:f.businessId)||(q==null?void 0:q.id)||null,v=d||(f==null?void 0:f.providerNetworkId)||(B==null?void 0:B.id)||null,p=!!O,m=p?O:v,oe=p?"businessId":"providerNetworkId",de=p?"business":"provider_network",ue=!!x&&!p,F=w||(p?"business":"provider network"),_=s.useMemo(()=>p?{businessId:O}:{providerNetworkId:v},[p,O,v]),k=s.useMemo(()=>p?{businessId:O,providerNetworkId:null}:{businessId:null,providerNetworkId:v},[p,O,v]),be=s.useMemo(()=>v?[v]:[],[v]),me=(z==null?void 0:z.accentColor)||(q==null?void 0:q.accentColor)||(B==null?void 0:B.accentColor)||Pc,pt=z!=null&&z.headerFont?`"${z.headerFont}", "GT Super Display", serif`:void 0,V=u||A,Me=typeof h=="boolean"?h:X,T=String(V||"").trim().toLowerCase(),I=!Me&&(Yo(V,"Provider Network Admin")&&!p||T==="business admin"&&p),M=Array.isArray(g)&&g.length>0?g:Vd,{isMobileOrTablet:H}=Nc(),ce=Rc(),he=Ic(V,ce.pathname)?52:0,ve=!r&&!H,we=64+he,{ref:qe,height:Qe}=Qo({enabled:ve,fallbackHeight:520,bottomOffset:we}),{ref:ns,height:Et}=Qo({enabled:ve,fallbackHeight:520,bottomOffset:we}),[is,ft]=s.useState(null),yt=!p&&(ue||Aa(V,["Provider Network Admin","Provider","Provider Delegate"])),Oe=typeof L=="boolean"?L:yt,Re=s.useMemo(()=>yt?["product","protocol","treatment"]:[],[yt]),[Ze,bt]=s.useState(!0),[et,ht]=s.useState([]),[De,Ve]=s.useState([]),[Ne,ls]=s.useState([]),[ge,tt]=s.useState([]),[pe,cs]=s.useState([]),[$e,ne]=s.useState(!1),[xt,vt]=s.useState(!1),[Ue,_t]=s.useState(!1),[ze,st]=s.useState(!1),[at,rt]=s.useState(""),[Ke,Mt]=s.useState([]),[ot,He]=s.useState(!1),[W,wt]=s.useState(!1),[We,St]=s.useState(""),[J,qa]=s.useState([]),[Ie,ds]=s.useState([]),[Ws,Ys]=s.useState(0),[qt,Ct]=s.useState({}),[Gs,kt]=s.useState({}),[nt,it]=s.useState({}),[lt,Pt]=s.useState(!1),[Ot,Vt]=s.useState(!1),je=s.useRef(null),[us,Js]=s.useState(""),[$t,Xs]=s.useState(!1),[Ut,Qs]=s.useState(!1),[zt,ms]=s.useState(!1),[Nt,Zs]=s.useState(!1),[gs,ea]=s.useState(null),[Pe,K]=s.useState([]),[Se,ps]=ee(`${te}.productSearch`,"",{validate:Ba}),[It,ta]=ee(`${te}.masterSearch`,"",{validate:Ba}),[fs,ys]=ee(`${te}.categorySearch`,"",{validate:Ba}),[bs,Oa]=ee(`${te}.masterCategorySearch`,"",{validate:Ba}),[Kt,Va]=ee(`${te}.productStatusFilters`,["active"],{validate:Te}),[sa,$a]=ee(`${te}.productTypeFilters`,[],{validate:Te}),[N,j]=ee(`${te}.productCategoryFilters`,[],{validate:Te}),[Ye,_n]=ee(`${te}.productFormsFilter`,"any",{validate:e=>La.includes(e)}),[Gr,Mn]=ee(`${te}.productFormularyFilter`,"any",{validate:e=>La.includes(e)}),[Jr,qn]=ee(`${te}.productLabsFilter`,"any",{validate:e=>La.includes(e)}),[Xr,On]=ee(`${te}.productSyncVisitFilter`,"any",{validate:e=>La.includes(e)}),[aa,Vn]=ee(`${te}.masterStatusFilters`,[],{validate:Te}),[ra,$n]=ee(`${te}.masterTypeFilters`,[],{validate:Te}),[Ua,Un]=ee(`${te}.masterCategoryFilters`,[],{validate:Te}),[oa,zn]=ee(`${te}.masterAdoptionFilters`,[],{validate:Te}),[na,Kn]=ee(`${te}.categoryStatusFilters`,["active"],{validate:Te}),[ia,Hn]=ee(`${te}.categorySourceFilters`,[],{validate:Te}),[la,Wn]=ee(`${te}.masterCategoryStatusFilters`,[],{validate:Te}),[ca,Yn]=ee(`${te}.masterCategoryAdoptionFilters`,[],{validate:Te}),[Gn,Qr]=s.useState(!1),[Jn,Zr]=s.useState(!1),[Xn,da]=s.useState(null),[ua,ma]=s.useState(!1),[ie,eo]=s.useState(null),[P,za]=s.useState(Zo()),[Qn,to]=s.useState("basics"),[Zn,so]=s.useState(!1),[ei,ao]=s.useState(!1),[Ka,ga]=s.useState(!1),[Le,ro]=s.useState(null),[Z,Ha]=s.useState(en()),[Wa,Ya]=s.useState(!1),[ct,t
12i]=s.useState(null),[jt,Ga]=s.useState(null),[hs,oo]=s.useState(null),[si,no]=s.useState([]),[ai,io]=s.useState(!1),[ri,lo]=s.useState(null),[oi,co]=s.useState(null),[ni,ii]=s.useState(null),[Ht,Ja]=s.useState([]),[xs,uo]=s.useState(""),[li,mo]=s.useState(!1),[vs,go]=s.useState(""),[ci,Xa]=s.useState(!1),[dt,Qa]=s.useState(null),[di,pa]=s.useState(!1),[ui,fa]=s.useState(null),[mi,po]=s.useState(!1),[gi,fo]=s.useState(!1),[ws,yo]=s.useState([]),[pi,bo]=s.useState(!1),[fi,ho]=s.useState(!1),[Za,xo]=s.useState([]),[yi,vo]=s.useState(!1),[bi,wo]=s.useState(null),[er,So]=s.useState(!1),[Lt,ya]=s.useState([]),[hi,Co]=s.useState(!1),[xi,tr]=s.useState(!1),[vi,ko]=s.useState(!1),[wi,Si]=s.useState(!1),[Ss,sr]=s.useState("file"),[ba,Po]=s.useState(""),[Bt,ar]=s.useState(null),[No]=s.useState(!1),[,rr]=s.useState([]),[,or]=s.useState([]),[,nr]=s.useState(null),[ir,Io]=s.useState(null),[Ci,lr]=s.useState(null),[jo,Lo]=s.useState(!1),[ki,Pi]=s.useState(!1),[Cs,cr]=s.useState("file"),[ha,Bo]=s.useState(""),[At,dr]=s.useState(null),[Ao]=s.useState(!1),[,ur]=s.useState([]),[,mr]=s.useState([]),[,gr]=s.useState(null),[pr,To]=s.useState(null),[Ni,fr]=s.useState(null),[Ro,Do]=s.useState(!1),Ii=s.useCallback(()=>{sr("file"),Po(""),ar(null),rr([]),or([]),nr(null)},[]),ji=s.useCallback(()=>{cr("file"),Bo(""),dr(null),ur([]),mr([]),gr(null)},[]),xa=s.useCallback(async e=>new Promise((a,i)=>{const l=new FileReader;l.onload=()=>{const C=String(l.result||""),$=C.includes(",")?C.split(",")[1]:C;a($)},l.onerror=()=>i(new Error("Failed to read file")),l.readAsDataURL(e)}),[]);s.useEffect(()=>{var a;const e=(a=Ta.currentUser)==null?void 0:a.uid;if(!e||!ir){lr(null);return}return Go(on(Jo(e,ir),i=>{lr(i.exists()?{id:i.id,...i.data()}:null)}),"products.provider-network.bulk-import-job")},[ir]),s.useEffect(()=>{var a;const e=(a=Ta.currentUser)==null?void 0:a.uid;if(!e||!pr){fr(null);return}return Go(on(Jo(e,pr),i=>{fr(i.exists()?{id:i.id,...i.data()}:null)}),"products.provider-network.bulk-category-job")},[pr]);function va(e){if(e==="yes")return!0;if(e==="no")return!1}const wa=qd({enabled:!!m&&!p,searchTerm:Se,statusFilters:Kt.length?Kt:zd,typeFilters:sa,scopeTypeFilters:Re,categoryFilters:N,providerNetworkFilters:be,hasForms:va(Ye),hasFormularyMappings:va(Gr),requiresLabs:va(Jr),requiresSyncVisit:va(Xr)}),{rows:ks,filteredCount:Li,totalCount:Bi,filterCounts:b,loading:Ai,loadingMore:Ti,hasMore:Ri,loadMore:Di,refresh:Fo,fetchAllRows:Fi}=wa,Ei=s.useDeferredValue(ks),Eo=ud(Ei,()=>Ks(se,"ProviderNetworks",v,"Products")),E=s.useMemo(()=>p?et:Ud(Eo,{ownerField:"providerNetworkId",ownerId:v,catalogScope:"provider_network"}),[p,Eo,et,v]),_o=s.useMemo(()=>E.reduce((e,a)=>(Number.isFinite(a.clientAssignmentCount)&&(e[a.id]=a.clientAssignmentCount),e),{}),[E]),Mo=s.useMemo(()=>E.reduce((e,a)=>(Number.isFinite(a.formCount)&&(e[a.id]=a.formCount),e),{}),[E]),yr=s.useMemo(()=>E.reduce((e,a)=>(Number.isFinite(a.formularyCount)&&(e[a.id]=a.formularyCount),e),{}),[E]),Fe=s.useCallback(async({silent:e=!1}={})=>{if(!m){bt(!1);return}e||bt(!0);try{if(p){const[a,i]=await Promise.all([jc(se,O,{includeInactive:!0}),Lc(se,O,{includeInactive:!0})]);ht((Array.isArray(a==null?void 0:a.products)?a.products:a||[]).filter(l=>tn(l,{ownerField:oe,ownerId:m,catalogScope:de})).filter(l=>l.type!=="lab"&&l.type!=="visit")),tt(i||[])}else{const a=await Bc(se,v,{includeInactive:!0});tt(a||[])}}catch(a){console.error("Error loading scoped catalog:",a),y.error(a.message||"Unable to load catalog data. Please try again.")}finally{bt(!1)}},[oe,m,de,p,O,v]),R=s.useCallback(()=>{p?Fe({silent:!0}):Fo()},[p,Fe,Fo]),qo=s.useCallback(async()=>{if(!(!m||$e||xt)){ne(!0);try{const[e,a]=await Promise.all([p?Yc(se,O):Gc(se),Ac(se,{includeInactive:!0})]);Ve((e||[]).filter(i=>i.type!=="lab"&&i.type!=="visit")),cs(a||[]),vt(!0)}catch(e){console.error("Error loading template catalog:",e),y.error(e.message||"Unable to load templates.")}finally{ne(!1)}}},[m,p,O,xt,$e]),Tt=s.useCallback(async()=>{if(Ue||ze&&!at)return Ne;_t(!0),rt("");try{const e=!p&&v?await Jc(se,{providerNetworkId:v}):await Xc(se,"lab",{statuses:["active"]});return ls(e),st(!0),e}catch(e){return console.error("Error loading master labs:",e),rt(e.message||"Unable to load lab options."),y.error(e.message||"Unable to load lab options."),[]}finally{_t(!1)}},[p,Ne,ze,Ue,v]),_i=s.useCallback(async()=>
12{if(p||!v)return[];if(ot||W&&!We)return Ke;He(!0),St("");try{const e=await Qc(se,{providerNetworkId:v});return Mt(e),e}catch(e){return console.error("Error loading biomarker reference protocols:",e),St(e.message||"Unable to load protocol biomarkers."),[]}finally{wt(!0),He(!1)}},[Ke,We,W,ot,p,v]),Ps=s.useCallback(async()=>{if(!m||$t||Ut)return J;Xs(!0);try{const a=(await Da(pd(Ks(se,"Documents"),fd(oe,"==",m)))).docs.map(i=>Tc({id:i.id,...i.data()})).filter(i=>i.documentType==="knowledge_base"&&(i.status||"active")==="active").sort((i,l)=>Ce(i).localeCompare(Ce(l)));return qa(a),Qs(!0),a}catch(e){return console.error("Error loading knowledge base items:",e),y.error(e.message||"Unable to load knowledge base items."),[]}finally{Xs(!1)}},[oe,m,J,Ut,$t]),Ns=s.useCallback(async()=>{if(p||!v||zt||Nt)return Ie;ms(!0);try{const a=(await Da(Ks(se,"ProviderNetworks",v,"Forms"))).docs.map(i=>({id:i.id,...i.data()})).sort((i,l)=>(i.name||"").localeCompare(l.name||""));return ds(a),Zs(!0),a}catch(e){return console.error("Error loading provider network forms:",e),y.error(e.message||"Unable to load forms."),Zs(!0),[]}finally{ms(!1)}},[p,Ie,Nt,zt,v]);s.useEffect(()=>{Fe()},[Fe]),s.useEffect(()=>{!Wa&&!jt&&!er||Ps()},[er,Wa,jt,Ps]),s.useEffect(()=>{hs&&Ns()},[hs,Ns]),s.useEffect(()=>{p||!v||ks.length===0||Ns()},[p,Ns,ks.length,v]),s.useEffect(()=>{p||!m||ks.length===0||Ps()},[m,p,Ps,ks.length]),s.useEffect(()=>{(ua&&P.requiresLabs===!0||ua&&(P.clinicalRulesWindows||[]).some(e=>(e==null?void 0:e.labs)===!0)||Ka&&Z.requiresLabs===!0)&&Tt()},[Ka,Z.requiresLabs,Tt,ua,P.clinicalRulesWindows,P.requiresLabs]),s.useEffect(()=>{K(e=>e.filter(a=>E.some(i=>i.id===a)))},[E]);const Is=s.useMemo(()=>new Set(E.map(e=>e.sourceProductId).filter(Boolean)),[E]),js=s.useMemo(()=>new Set(ge.map(e=>e.sourceCategoryId).filter(Boolean)),[ge]),Mi=s.useMemo(()=>ge.reduce((e,a)=>(e[a.id]=a.name||"Category",e),{}),[ge]),br=s.useMemo(()=>ge.filter(e=>(e.status||"active")==="active"),[ge]),qi=Oe?"protocol":"product",Oi=Oe?"protocols":"products",Vi=p?"Business":ue?F.charAt(0).toUpperCase()+F.slice(1):"Network",Ge=P.type==="treatment"?"treatment":P.type==="protocol"?"protocol":"product",$i=ie?`Edit ${Ge}`:`Create ${Ge}`,Ui=ie?`Close edit ${Ge}`:`Close create ${Ge}`,zi=ie?`Update how this ${Ge} appears to your team and downstream clients.`:`Create a ${Ge} that belongs directly to your ${F}.`,Ki=s.useMemo(()=>pe.reduce((e,a)=>((a.status||"active")==="active"&&(e[a.id]=a.name||"Category"),e),{}),[pe]),Hi=s.useMemo(()=>{const e=new Map;return J.forEach(a=>{(a==null?void 0:a.id)!=null&&e.set(a.id,Ce(a))}),e},[J]),hr=s.useMemo(()=>{const e={...Mo};return E.forEach(a=>{Number.isFinite(e[a.id])||(e[a.id]=Number.isFinite(a.formCount)?a.formCount:0)}),Nt?E.reduce((a,i)=>(a[i.id]=Ie.filter(l=>Zc(l,i)).length,a),e):e},[E,Mo,Ie,Nt]),xr=s.useMemo(()=>lt?qt:{..._o,...qt},[_o,qt,lt]),Ls=s.useMemo(()=>(re||[]).map(e=>String((e==null?void 0:e.id)||"").trim()).filter(Boolean),[re]),Sa=s.useCallback(async(e=[],{merge:a=!1}={})=>{if(p||!v||e.length===0)return;const i=new Map;for(let C=0;C<e.length;C+=vn){const $=e.slice(C,C+vn);await Promise.all($.map(async D=>{try{const Y=await Da(Ks(se,"Clients",D,"Products"));i.set(D,Y.docs)}catch(Y){console.error("Error loading client product assignments:",Y),i.set(D,[])}}))}const l=Jd(e,i,v);if(a){it(C=>({...C,...l.clientProductAssignmentByClientAndProduct}));return}Ct(l.productActiveClientCountById),kt(l.productClientAssignmentIdsById),it(l.clientProductAssignmentByClientAndProduct),Pt(!0)},[p,v]),vr=s.useCallback(async()=>{if(p||!v||lt)return;if(Ls.length===0){Pt(!0);return}if(je.current){await je.current;return}Vt(!0);const e=Sa(Ls).finally(()=>{je.current=null,Vt(!1)});je.current=e,await e},[p,Sa,Ls,lt,v]);s.useEffect(()=>{if(je.current=null,p||!v){Ct({}),kt({}),it({}),Pt(!0);return}Ct({}),kt({}),it({}),Pt(Ls.length===0),ue&&x&&Sa([x],{merge:!0})},[p,ue,Sa,Ls,v,x]);const Wi=s.useMemo(()=>{if(!ue||!x)return{};const e=`${x}::`,a={};return Object.entries(nt).forEach(([i,l])=>{i.startsWith(e)&&(a[i.slice(e.length)]=l)}),a},[nt,ue,x]),Yi=s.useMemo(()=>(re||[]).map(e=>{var a;return{id:String((e==null?void 0:e.id)||"").trim(),name:(e==null?void 0:e.displayName)||(e==null?void 0:e.name)||(e==null?void 0:e.companyName)||"Client",relationship:String((e==null?void 0:e.primaryProvi
12derNetworkId)||(e==null?void 0:e.providerNetworkId)||((a=e==null?void 0:e.providerNetworkIds)==null?void 0:a[0])||"").trim()===v?"primary":"additional"}}).filter(e=>e.id).sort((e,a)=>e.name.localeCompare(a.name)),[re,v]),Gi=s.useCallback(async(e,a,i)=>{if(!I||p||!v||!(e!=null&&e.id)||!a)return;const l=Ta.currentUser;if(!l){y.error("Not authenticated");return}const C=`${e.id}::${a}`,$=nt[`${a}::${e.id}`]||null;try{if(Js(C),i){const D=Od({clientId:a,providerNetworkId:v,product:e,userId:l.uid,existingClientProduct:$});await yd(Ea(se,"Clients",a,"Products",e.id),D,{merge:!0})}else await Zd(a,e.id);kt(D=>{const Y=new Set(D[e.id]||[]);return i?Y.add(a):Y.delete(a),{...D,[e.id]:Array.from(Y)}}),Ct(D=>{const Y=(D[e.id]||0)+(i?1:-1);return{...D,[e.id]:Math.max(0,Y)}}),it(D=>{const Y=`${a}::${e.id}`;if(!i){if(!D[Y])return D;const Rt={...D};return delete Rt[Y],Rt}return D}),Pt(!0),y.success(i?"Protocol enabled for client":"Protocol disabled for client")}catch(D){console.error("Error updating client protocol assignment:",D),y.error(D.message||"Unable to update client protocol assignment.")}finally{Js("")}},[I,nt,p,v]),wr=s.useMemo(()=>E.filter(e=>e.type==="product").map(e=>e.id).filter(Boolean),[E]),Ji=s.useMemo(()=>wr.join("|"),[wr]),Sr=s.useMemo(()=>{if(!v)return yr;const e={...yr};return E.forEach(a=>{a.type==="product"&&(Number.isFinite(e[a.id])||(e[a.id]=Number.isFinite(a.formularyCount)?a.formularyCount:0))}),wr.forEach(a=>{const i=xn(v,a);Vr.has(i)&&(e[a]=Vr.get(i))}),e},[E,Ji,Ws,yr,v]),Xi=s.useMemo(()=>Ie.filter(e=>ed(e)&&["intake","consent"].includes(String(e.formType||"").trim().toLowerCase())).sort((e,a)=>(e.name||"").localeCompare(a.name||"")),[Ie]),Qi=s.useMemo(()=>{if(!jt)return[];const e=Array.isArray(jt.knowledgeBaseItemIds)?jt.knowledgeBaseItemIds:[],a=new Set(e);return J.filter(i=>a.has(i.id)).sort((i,l)=>Ce(i).localeCompare(Ce(l)))},[J,jt]),Zi=s.useCallback(async(e,a,i=null)=>{var $;const l=i||hs;if(!v||!(l!=null&&l.id)||!(e!=null&&e.id)||a&&(($=e.associations)==null?void 0:$.applyToAll)===!0)return;const C=yn({form:e,product:l,products:E,shouldPair:a});no(D=>Ae(D,[e.id]));try{await nn({providerNetworkId:v,formId:e.id,associations:C}),ds(D=>D.map(Y=>Y.id===e.id?{...Y,associations:C}:Y)),y.success(a?"Form paired":"Form unpaired")}catch(D){console.error("Error updating product form pairing:",D),y.error(D.message||"Unable to update form pairing.")}finally{no(D=>D.filter(Y=>Y!==e.id))}},[E,hs,v]),el=s.useMemo(()=>[{id:"document",header:"Document",minWidth:240,renderCell:e=>t.jsx(Rr,{primary:Ce(e),secondary:qs(e)})},{id:"type",header:"Type",minWidth:120,renderCell:e=>t.jsx(Dr,{tone:"cyan",children:Os(e)})},{id:"updated",header:"Last updated",minWidth:120,hideOnLg:!0,renderCell:e=>t.jsx("span",{className:"text-xs text-content-tertiary max-lg:text-2xs",children:Fr(e)})},{id:"view",header:"View",minWidth:100,align:"right",renderCell:e=>t.jsxs(G,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs max-lg:h-6 max-lg:px-2 max-lg:text-3xs","data-row-click-ignore":!0,onClick:a=>{a.stopPropagation(),Ga(null),co(e)},children:[t.jsx(Hr,{className:"mr-1 size-3.5 max-lg:size-3"}),"View"]})}],[]),Bs=s.useMemo(()=>{const e=xs.trim().toLowerCase();return e?J.filter(a=>{const i=Ce(a).toLowerCase(),l=qs(a).toLowerCase(),C=Os(a).toLowerCase();return i.includes(e)||l.includes(e)||C.includes(e)}):J},[J,xs]),As=s.useMemo(()=>{const e=vs.trim().toLowerCase();return e?J.filter(a=>{const i=Ce(a).toLowerCase(),l=qs(a).toLowerCase(),C=Os(a).toLowerCase();return i.includes(e)||l.includes(e)||C.includes(e)}):J},[J,vs]),Cr=s.useCallback(e=>{Ja(a=>a.includes(e)?a.filter(i=>i!==e):[...a,e])},[]),kr=s.useCallback(e=>{ya(a=>a.includes(e)?a.filter(i=>i!==e):[...a,e])},[]),Oo=s.useCallback(e=>{const a=Bs.map(l=>l.id),i=new Set(a);Ja(l=>e===!0?Ae(l,a):l.filter(C=>!i.has(C)))},[Bs]),Vo=s.useCallback(e=>{const a=As.map(l=>l.id),i=new Set(a);ya(l=>e===!0?Ae(l,a):l.filter(C=>!i.has(C)))},[As]),tl=s.useMemo(()=>{const e=Bs.map(l=>l.id),a=e.filter(l=>Ht.includes(l)).length,i=e.length>0&&a===e.length?!0:a>0?"indeterminate":!1;return[{id:"selected",header:"",minWidth:44,align:"center",renderHeader:()=>t.jsx("div",{className:"flex justify-center",children:t.jsx(ts,{checked:i,onCheckedChange:Oo,onClick:l=>l.stopPropagation(),"aria-label":"Select visible knowledge base items",disabled:e.length===0})}),renderCell:l=>t.jsx("div",{className:"flex justify-center",children:t.jsx(ts,{checked:Ht.includes(l.id),onCheckedChange:()=>
12Cr(l.id),onClick:C=>C.stopPropagation(),"aria-label":`Select ${Ce(l)}`})})},{id:"document",header:"Document",minWidth:240,renderCell:l=>t.jsx(Rr,{primary:Ce(l),secondary:qs(l),highlight:xs})},{id:"type",header:"Type",minWidth:120,renderCell:l=>t.jsx(Dr,{tone:"slate",children:Os(l)})},{id:"updated",header:"Updated",minWidth:120,hideOnLg:!0,renderCell:l=>t.jsx("span",{className:"text-xs text-content-tertiary max-lg:text-2xs",children:Fr(l)})}]},[Bs,xs,Ht,Oo,Cr]),sl=s.useMemo(()=>{const e=As.map(l=>l.id),a=e.filter(l=>Lt.includes(l)).length,i=e.length>0&&a===e.length?!0:a>0?"indeterminate":!1;return[{id:"selected",header:"",minWidth:44,align:"center",renderHeader:()=>t.jsx("div",{className:"flex justify-center",children:t.jsx(ts,{checked:i,onCheckedChange:Vo,onClick:l=>l.stopPropagation(),"aria-label":"Select visible knowledge base items",disabled:e.length===0})}),renderCell:l=>t.jsx("div",{className:"flex justify-center",children:t.jsx(ts,{checked:Lt.includes(l.id),onCheckedChange:()=>kr(l.id),onClick:C=>C.stopPropagation(),"aria-label":`Select ${Ce(l)}`})})},{id:"document",header:"Document",minWidth:240,renderCell:l=>t.jsx(Rr,{primary:Ce(l),secondary:qs(l),highlight:vs})},{id:"type",header:"Type",minWidth:120,renderCell:l=>t.jsx(Dr,{tone:"slate",children:Os(l)})},{id:"updated",header:"Updated",minWidth:120,hideOnLg:!0,renderCell:l=>t.jsx("span",{className:"text-xs text-content-tertiary max-lg:text-2xs",children:Fr(l)})}]},[Lt,vs,As,Vo,kr]),Ts=s.useMemo(()=>{var e,a,i,l,C,$,D,Y,Rt,Ca,Fs,Dt,Es,Ft,xe,_s,Wt,Yt,le,Gt,mt;return{status:{active:((e=b==null?void 0:b.status)==null?void 0:e.active)??0,inactive:((a=b==null?void 0:b.status)==null?void 0:a.inactive)??0},type:{product:((i=b==null?void 0:b.type)==null?void 0:i.product)??0,protocol:((l=b==null?void 0:b.type)==null?void 0:l.protocol)??0,treatment:((C=b==null?void 0:b.type)==null?void 0:C.treatment)??0},categories:(b==null?void 0:b.categories)??{},noCategories:0,forms:{yes:(($=b==null?void 0:b.hasForms)==null?void 0:$.true)??((D=b==null?void 0:b.hasForms)==null?void 0:D.true)??0,no:((Y=b==null?void 0:b.hasForms)==null?void 0:Y.false)??((Rt=b==null?void 0:b.hasForms)==null?void 0:Rt.false)??0},formulary:{yes:((Ca=b==null?void 0:b.hasFormularyMappings)==null?void 0:Ca.true)??((Fs=b==null?void 0:b.hasFormularyMappings)==null?void 0:Fs.true)??0,no:((Dt=b==null?void 0:b.hasFormularyMappings)==null?void 0:Dt.false)??((Es=b==null?void 0:b.hasFormularyMappings)==null?void 0:Es.false)??0},labs:{yes:((Ft=b==null?void 0:b.requiresLabs)==null?void 0:Ft.true)??((xe=b==null?void 0:b.requiresLabs)==null?void 0:xe.true)??0,no:((_s=b==null?void 0:b.requiresLabs)==null?void 0:_s.false)??((Wt=b==null?void 0:b.requiresLabs)==null?void 0:Wt.false)??0},syncVisit:{yes:((Yt=b==null?void 0:b.requiresSyncVisit)==null?void 0:Yt.true)??((le=b==null?void 0:b.requiresSyncVisit)==null?void 0:le.true)??0,no:((Gt=b==null?void 0:b.requiresSyncVisit)==null?void 0:Gt.false)??((mt=b==null?void 0:b.requiresSyncVisit)==null?void 0:mt.false)??0}}},[b]),Rs=s.useMemo(()=>{const e={status:{active:0,inactive:0},type:{product:0,protocol:0,treatment:0},adoption:{adopted:0,available:0},categories:{},noCategories:0};return De.forEach(a=>{const i=a.status==="inactive"?"inactive":"active",l=a.type==="protocol"||a.type==="treatment"?a.type:"product";e.status[i]+=1,e.type[l]+=1,Is.has(a.id)?e.adoption.adopted+=1:e.adoption.available+=1;const C=td(a);C.length===0?e.noCategories+=1:C.forEach($=>{e.categories[$]=(e.categories[$]||0)+1})}),e},[Is,De]),al=s.useMemo(()=>sn(br,Ts.categories,Ts.noCategories),[br,Ts.categories,Ts.noCategories]),rl=s.useMemo(()=>sn(pe.filter(e=>(e.status||"active")==="active"),Rs.categories,Rs.noCategories),[pe,Rs.categories,Rs.noCategories]),ol=s.useMemo(()=>{const e={status:{active:0,inactive:0},source:{custom:0,adopted:0}};return ge.forEach(a=>{const i=a.status==="inactive"?"inactive":"active";e.status[i]+=1,a.sourceCategoryId?e.source.adopted+=1:e.source.custom+=1}),e},[ge]),nl=s.useMemo(()=>{const e={status:{active:0,inactive:0},adoption:{adopted:0,available:0}};return pe.forEach(a=>{const i=a.status==="inactive"?"inactive":"active";e.status[i]+=1,js.has(a.id)?e.adoption.adopted+=1:e.adoption.available+=1}),e},[js,pe]),Ds=s.useMemo(()=>
12{if(!p)return E;const e=Se.trim().toLowerCase();return e?E.filter(a=>[a.id,a.productId,a.catalogEntryId,a.clientProductId,a.sourceProductId,a.clientId,a.businessId,a.providerNetworkId,a.name,a.description,a.displayName,a.displayDescription].some(i=>String(i||"").toLowerCase().includes(e))):E},[E,p,Se]),$o=s.useMemo(()=>{let e=Er(De,It,["id","productId","name","description","type"]).map(a=>({...a,adoptionState:Is.has(a.id)?"adopted":"available"}));return aa.length>0&&(e=e.filter(a=>aa.includes(a.status==="inactive"?"inactive":"active"))),ra.length>0&&(e=e.filter(a=>ra.includes(a.type==="protocol"||a.type==="treatment"?a.type:"product"))),e=sd(e,Ua),oa.length>0&&(e=e.filter(a=>oa.includes(a.adoptionState))),e},[Is,oa,Ua,De,It,aa,ra]),Uo=s.useMemo(()=>{let e=Er(ge,fs,["name","description","status"]);return p?(na.length>0&&(e=e.filter(a=>na.includes(a.status==="inactive"?"inactive":"active"))),ia.length>0&&(e=e.filter(a=>{const i=a.sourceCategoryId?"adopted":"custom";return ia.includes(i)})),e):e.filter(a=>!["inactive","archived"].includes(a.status))},[fs,ia,na,p,ge]),zo=s.useMemo(()=>{let e=Er(pe,bs,["name","description","status"]).map(a=>({...a,adoptionState:js.has(a.id)?"adopted":"available"}));return la.length>0&&(e=e.filter(a=>la.includes(a.status==="inactive"?"inactive":"active"))),ca.length>0&&(e=e.filter(a=>ca.includes(a.adoptionState))),e},[js,pe,ca,bs,la]),Pr=wa.sortKey,Nr=wa.sortDirection,il=wa.handleSort,Ko=s.useMemo(()=>({requiresSyncVisit:e=>e.requiresSyncVisit===!0?1:0,requiresLabs:e=>e.requiresLabs===!0?1:0,__activeClientCount:e=>xr[e.id]??0,__formCount:e=>hr[e.id]??0,__formularyCount:e=>Sr[e.id]??0}),[hr,Sr,xr]),Je=s.useMemo(()=>p?md(Ds,Pr,Nr,Ko):Ds,[Ds,p,Ko,Nr,Pr]),{sortedData:ll,sortKey:cl,sortDirection:dl,handleSort:ul}=_r($o,"name","asc"),{sortedData:ml,sortKey:gl,sortDirection:pl,handleSort:fl}=_r(Uo,"name","asc"),{sortedData:yl,sortKey:bl,sortDirection:hl,handleSort:xl}=_r(zo,"name","asc");s.useEffect(()=>{if(!H){ft(null);return}const e=qe.current;ft((e==null?void 0:e.closest(".app-shell-scroll-area"))??null)},[H,Ze,Qe,qe,E.length]);const Q=s.useMemo(()=>E.filter(e=>Pe.includes(e.id)&&tn(e,{ownerField:oe,ownerId:m,catalogScope:de})),[oe,m,de,E,Pe]),vl=s.useMemo(()=>Je.length>0&&Je.every(e=>Pe.includes(e.id)),[Pe,Je]),wl=s.useMemo(()=>Je.some(e=>Pe.includes(e.id)),[Pe,Je]),ut=s.useRef({productId:null,creationRequestId:null}),Sl=s.useCallback((e="product",a="")=>{ut.current={productId:null,creationRequestId:crypto.randomUUID()},eo(null),za(Zo(e,a)),to("basics"),ma(!0)},[]),Cl=s.useCallback(()=>{ao(!0)},[]),kl=s.useCallback(()=>{so(!0),qo()},[qo]),Ir=s.useCallback((e,{initialTab:a="basics"}={})=>{ut.current={productId:e.id,creationRequestId:null};const i=Fa(e);eo(e),za({name:e.name||"",description:e.description||"",productNotesDisclaimer:e.productNotesDisclaimer||"",type:e.type==="protocol"||e.type==="treatment"?e.type:"product",kind:typeof e.kind=="string"?e.kind:"",status:e.status||"active",categories:Array.isArray(e.categories)?e.categories:[],requiresSyncVisit:e.requiresSyncVisit===!0,requiresDeaPrescriber:e.requiresDeaPrescriber===!0,requiresLabs:e.requiresLabs===!0,labRecencyDays:ka(e.labRecencyDays),labRecencyUnit:ss(e.labRecencyUnit),approvedLabProductIds:Array.isArray(e.approvedLabProductIds)?e.approvedLabProductIds:[],...i,labBiomarkerExtractionJobId:"",excludedStates:Vs(e.excludedStates),knowledgeBaseItemIds:Array.isArray(e.knowledgeBaseItemIds)?e.knowledgeBaseItemIds:[],clinicalRulesWindows:p?_a(e.clinicalRules):Wd(e.clinicalRules)}),e.requiresLabs===!0&&Tt(),to(a||"basics"),ma(!0)},[p,Tt]),Pl=s.useCallback(()=>{ro(null),Ha(en()),ga(!0)},[]),Nl=s.useCallback(e=>{const a=Fa(e);ro(e),Ha({name:e.name||"",description:e.description||"",status:e.status||"active",requiresSyncVisit:e.requiresSyncVisit===!0,requiresLabs:e.requiresLabs===!0,labRecencyDays:ka(e.labRecencyDays),labRecencyUnit:ss(e.labRecencyUnit),approvedLabProductIds:Array.isArray(e.approvedLabProductIds)?e.approvedLabProductIds:[],...a,labBiomarkerExtractionJobId:"",excludedStates:Vs(e.excludedStates)}),e.requiresLabs===!0&&Tt(),ga(!0)},[Tt]),Il=s.useCallback(async({onSaved:e=null}={})=>{var a;if(!m){y.error(`${p?"Business":"Provider network"} is required`);return}if(!P.name.trim()){y.error("Product name is required");return}Qr(!0);try{const i=P.type==="treatment",l=P.type!=="lab"&&!i,C=!p,$=zs({...P,requiresLabs:l&&P.requiresLabs===!0}),D=l&&P.requiresLabs?Ae(P.approvedLabProductIds):[],Y=i?[]:C?Yd(P.clinicalRulesWindows):_a(P.clinicalRulesWindows),Rt=C?rn([{...P,requiresLabs:l&&P.requiresLabs===!0},...(Array.isArray(P.clinicalRulesWindows)?P.clinicalRulesWindows:[]).map(le=>({...le,requiresLabs:le.labs===!0}))]):[],Ca=(ie==null?void 0:ie.requiresLabs)===!0&&zs(ie).requiredLabTests.length===0;if(l&&P.requiresLabs&&C&&!Ca&&$.requiredLabTests.length===0){y.error("Add at least one minimum biomarker");return}if(l&&P.requiresLabs&&!C&&D.length===0){y.error("Select at least one supported lab product");return}const Fs=C?Y.findIndex(le=>le.labs===!0&&le.requiredLabTests.length===0):-1;
12if(Fs>=0){y.error(`Add at least one minimum biomarker to clinical rule ${Fs+1}`);return}const Dt=(ie==null?void 0:ie.id)||ut.current.productId;!Dt&&!ut.current.creationRequestId&&(ut.current.creationRequestId=crypto.randomUUID());const Es={action:Dt?"updateNetworkProduct":"createNetworkProduct",creationRequestId:ut.current.creationRequestId||void 0,..._,productId:Dt||void 0,name:P.name.trim(),description:P.description.trim(),productNotesDisclaimer:P.productNotesDisclaimer.trim(),type:P.type,status:P.status,categories:P.categories,requiresSyncVisit:P.requiresSyncVisit===!0,requiresDeaPrescriber:P.requiresDeaPrescriber===!0,requiresLabs:l?P.requiresLabs===!0:!1,labRecencyDays:l?ka(P.labRecencyDays):ad,...l&&ss(P.labRecencyUnit)==="minutes"?{labRecencyUnit:"minutes"}:{},...C?$:{requiredLabTestIds:[],requiredLabTests:[],approvedLabProductIds:D},excludedStates:Vs(P.excludedStates),knowledgeBaseItemIds:P.knowledgeBaseItemIds,clinicalRules:{windows:Y}},Ft=await Ee(Qt,Es),xe=Dt||(Ft==null?void 0:Ft.productId);if(!xe)throw new Error("Product save returned no identifier. Retry this
12save.");ut.current.productId=xe,Ft.replayed&&await Ee(Qt,{...Es,action:"updateNetworkProduct",productId:xe});const _s=Ae(P.pendingFormIds);if(!ie&&_s.length>0&&xe&&v){const le={id:xe,categories:P.categories},Gt=[];try{for(const mt of _s){const Be=Ie.find(Ar=>Ar.id===mt);if(!(Be!=null&&Be.id))throw new Error("A selected required form is unavailable. Choose it again.");if(((a=Be.associations)==null?void 0:a.applyToAll)===!0)continue;const Ms=yn({form:Be,product:le,products:E,shouldPair:!0});await nn({providerNetworkId:v,formId:Be.id,associations:Ms}),Gt.push({formId:Be.id,associations:Ms})}Gt.length>0&&ds(mt=>mt.map(Be=>{const Ms=Gt.find(Ar=>Ar.formId===Be.id);return Ms?{...Be,associations:Ms.associations}:Be}))}catch(mt){throw console.error("Error pairing forms with new product:",mt),new Error("Clinical details saved, but required forms could not be attached. Retry this save.")}}const Wt=!ie,Yt=typeof P.kind=="string"?P.kind.trim():"";if(xe&&Yt&&Yt!==((ie==null?void 0:ie.kind)||"")&&await _e(k,xe,{kind:Yt}),typeof e=="function"&&xe)try{await e({productId:xe,created:Wt})}catch(le){return console.error("Companion save after scoped product save:",le),y.error(`Clinical details were saved. Retry to finish the storefront settings.${le!=null&&le.message?` ${le.message}`:""}`),R(),{productId:xe,created:Wt,companionSaved:!1}}try{await hn(Rt)}catch(le){console.error("Record biomarker extraction review:",le),y.warning("Protocol saved, but the extraction review could not be recorded.")}return y.success(`${Ge[0].toUpperCase()}${Ge.slice(1)} ${ie?"updated":"created"}`),ma(!1),R(),{productId:xe,created:Wt,companionSaved:!0}}catch(i){console.error("Save scoped product:",i),y.error(ut.current.productId?`Clinical details were saved; finish this save by retrying. ${i.message||""}`:i.message||"Unable to save protocol. Please try again.");return}finally{Qr(!1)}},[m,_,E,ie,p,Ge,P,Ie,v,R,k]),Ho=s.useCallback(async e=>{if(m)try{await _e(k,e,{status:"inactive"}),y.success("Protocol archived"),R()}catch(a){console.error("Archive scoped product:",a),y.error(a.message||"Unable to archive protocol. Please try again.")}},[m,R,k]),jr=!p&&(f==null?void 0:f.providerNetworkId)===v&&(B==null?void 0:B.legitScriptEnabled)===!0,jl=s.useCallback(async(e,a)=>{if(!I||!jr||!Yo(A,"Provider Network Admin"))return!1;try{return await _e(k,e,{legitScriptApproved:a}),R(),!0}catch(i){return Jt.error(i.message||"Unable to update LegitScript approval. Please try again."),!1}},[I,jr,A,k,R]),Ll=s.useCallback(async(e,a)=>{if(!I||!m||!e)return!1;try{return await _e(k,e,{requiresSyncVisit:a===!0}),R(),!0}catch(i){return Jt.error(i.message||"Unable to update sync visit. Please try again."),!1}},[I,m,R,k]),Bl=s.useCallback(async(e,a)=>{if(!I||!m||!e)return!1;try{const i=qr(a,J);return await _e(k,e,{knowledgeBaseItemIds:i}),R(),!0}catch(i){return Jt.error(i.message||"Unable to update documents. Please try again."),!1}},[I,m,J,R,k]),Al=s.useCallback(async(e,a)=>{if(!I||!m||!e)return!1;const i=String(a||"").trim();if(!i)return Jt.error("Enter a product name"),!1;const l=E.find(C=>C.id===e);if(((l==null?void 0:l.name)||"").trim()===i)return!0;try{return await _e(k,e,{name:i}),R(),Jt.success("Name updated"),!0}catch(C){return Jt.error(C.message||"Unable to update name. Please try again."),!1}},[I,m,E,R,k]),Tl=s.useCallback(async(e,a)=>{if(!I||!m||!e)return!1;const i=E.find($=>$.id===e),l=Array.isArray(i==null?void 0:i.categories)?i.categories:[],C=Ae(a);if(l.length===C.length&&l.every($=>C.includes($)))return!0;wo(e);try{return await _e(k,e,{categories:C}),R(),!0}catch($){return console.error("Update row categories:",$),y.error($.message||"Unable to update categories. Please try again."),!1}finally{wo(null)}},[I,m,E,R,k]),Rl=s.useCallback(async e=>{if(m){da(e);try{await Ee(Qt,{action:"adoptMasterProduct",..._,masterProductId:e}),y.success(`Master product added to your ${F} catalog`),R()}catch(a){console.error("Adopt master product:",a),y.error(a.message||"Unable to adopt master product. Please try again.")}finally{da(null)}}},[F,m,_,R]),Dl=s.useCallback(async()=>{if(!m){y.error(`${p?"Business":"Provider network"} is required`);return}if(!Z.name.trim()){y.error("Category name is required");return}Zr(!0);
12try{const e=!p,a=zs(Z),i=e?rn(Z):[],l=Z.requiresLabs?Ae(Z.approvedLabProductIds):[],C=(Le==null?void 0:Le.requiresLabs)===!0&&zs(Le).requiredLabTests.length===0;if(Z.requiresLabs&&e&&!C&&a.requiredLabTests.length===0){y.error("Add at least one minimum biomarker");return}if(Z.requiresLabs&&!e&&l.length===0){y.error("Select at least one supported lab product");return}await Ee(Pa,{action:Le?"updateNetworkCategory":"createNetworkCategory",..._,categoryId:Le==null?void 0:Le.id,name:Z.name.trim(),description:Z.description.trim(),status:Z.status,requiresSyncVisit:Z.requiresSyncVisit===!0,requiresLabs:Z.requiresLabs===!0,labRecencyDays:ka(Z.labRecencyDays),...ss(Z.labRecencyUnit)==="minutes"?{labRecencyUnit:"minutes"}:{},...e?a:{requiredLabTestIds:[],requiredLabTests:[],approvedLabProductIds:l},excludedStates:Vs(Z.excludedStates)});try{await hn(i)}catch($){console.error("Record category biomarker extraction review:",$),y.warning("Category saved, but the extraction review could not be recorded.")}y.success(Le?"Category updated":"Category created"),ga(!1),await Fe({silent:!0})}catch(e){console.error("Save scoped category:",e),y.error(e.message||"Unable to save category. Please try again.")}finally{Zr(!1)}},[m,_,Z,Le,p,Fe]),Fl=s.useCallback(async e=>{if(m)try{await Ee(Pa,{action:"archiveNetworkCategory",..._,categoryId:e}),y.success("Category archived"),await Fe({silent:!0})}catch(a){console.error("Archive scoped category:",a),y.error(a.message||"Unable to archive category. Please try again.")}},[m,_,Fe]),El=s.useCallback(async e=>{if(m){da(e);try{await Ee(Pa,{action:"adoptMasterCategory",..._,masterCategoryId:e}),y.success(`Master category added to your ${F}`),await Fe({silent:!0})}catch(a){console.error("Adopt master category:",a),y.error(a.message||"Unable to adopt master category. Please try again.")}finally{da(null)}}},[F,m,_,Fe]),Lr=s.useCallback(e=>{ti(e),Ja(Array.isArray(e.knowledgeBaseItemIds)?e.knowledgeBaseItemIds:[]),uo(""),Ya(!0)},[]),_l=s.useCallback(e=>{oo(e)},[]),Ml=s.useCallback(e=>{Ga(e)},[]),Br=s.useCallback(e=>{lo(e),io(!0)},[]),ql=s.useCallback((e,a)=>{if(!v||!e)return;const i=xn(v,e);Vr.set(i,Number.isFinite(a)?a:0),Ys(l=>l+1)},[v]),Ol=s.useCallback(e=>{Qa(e),Xa(!0),vr()},[vr]),Vl=s.useCallback(async e=>{if(!(!m||!(e!=null&&e.id)||(e.status||"active")!=="inactive")){pa(!0),fa(e.id);try{await _e(k,e.id,{status:"active"}),y.success("Protocol activated"),R()}catch(a){console.error("Activate protocol status:",a),y.error(a.message||"Unable to activate protocol. Please try again.")}finally{pa(!1),fa(null)}}},[m,R,k]),$l=s.useCallback(e=>[{id:"edit",label:"Edit product",onSelect:()=>Ir(e)},!p&&e.type==="product"&&{id:"formulary",label:"Manage formulary defaults",onSelect:()=>Br(e)},{id:"knowledge-base",label:"Manage knowledge base links",onSelect:()=>Lr(e)},!p&&["product","protocol"].includes(e.type||"product")&&e.itemType!=="package"&&{id:"delete",label:"Delete protocol",danger:!0,onSelect:()=>{K([e.id]),tr(!0)}},{id:"archive",label:"Archive product",danger:!0,onSelect:()=>Ho(e.id)}].filter(Boolean),[Ho,p,Ir,Br,Lr]),Ul=s.useCallback((e,a,i)=>{const l=(i||[]).filter(Boolean);l.length!==0&&(e.preventDefault(),e.stopPropagation(),ea({actions:l,product:a,x:Math.max(8,Math.min(e.clientX,window.innerWidth-208)),y:Math.max(8,Math.min(e.clientY,window.innerHeight-48-l.length*36))}))},[]),zl=s.useCallback(async()=>{if(!m||!(dt!=null&&dt.id))return;const e=dt.status==="inactive"?"active":"inactive";pa(!0),fa(dt.id);try{await _e(k,dt.id,{status:e}),y.success(e==="active"?"Protocol activated":"Protocol deactivated"),Xa(!1),Qa(null),R()}catch(a){console.error("Update protocol status:",a),y.error(a.message||"Unable to update status. Please try again.")}finally{pa(!1),fa(null)}},[m,dt,R,k]),Kl=s.useCallback(e=>{K(a=>a.includes(e)?a.filter(i=>i!==e):[...a,e])},[]),Hl=s.useCallback(e=>{K(a=>{if(e)return Ae(a,Je.map(l=>l.id));const i=new Set(Je.map(l=>l.id));return a.filter(l=>!i.has(l))})},[Je]),Wl=s.useCallback(async()=>{if(!m||!(ct!=null&&ct.id))return;const e=qr(Ht,J);mo(!0);try{await _e(k,ct.id,{knowledgeBaseItemIds:e}),y.success("Knowledge base links updated"),Ya(!1),R()}catch(a){console.error("Save knowledge base links:",a),y.error(a.message||"Unable to update knowledge base links. Please try again.")}finally{mo(!1)}}
12,[m,J,ct==null?void 0:ct.id,R,k,Ht]),Yl=s.useCallback(async e=>{if(!(!m||Q.length===0)){po(!0);try{await Or(k,Q.map(a=>({productId:a.id,fields:{status:e}}))),y.success(`${Q.length} protocol${Q.length===1?"":"s"} updated to ${e}`),K([]),R()}catch(a){console.error("Bulk update product status:",a),y.error(a.message||"Unable to update selected protocols. Please try again.")}finally{po(!1)}}},[m,R,k,Q]),Gl=s.useCallback(async()=>{if(!m||Q.length===0||ws.length===0){y.error("Choose at least one category");return}bo(!0);try{await Or(k,Q.map(e=>({productId:e.id,fields:{categories:Ae(e.categories||[],ws)}}))),y.success(`Added categor${ws.length===1?"y":"ies"} to ${Q.length} protocol${Q.length===1?"":"s"}`),fo(!1),yo([]),K([]),R()}catch(e){console.error("Bulk add product categories:",e),y.error(e.message||"Unable to add categories to selected protocols. Please try again.")}finally{bo(!1)}},[ws,m,R,k,Q]),Jl=s.useCallback(async()=>{const e=Ae(Pe);if(!m||e.length===0){y.error("Select at least one protocol");return}const a=Vs(Za);vo(!0);try{await Ee(Qt,{action:"bulkUpdateNetworkProductExcludedStates",..._,productIds:e,excludedStates:a}),y.success(`Updated excluded states for ${e.length} protocol${e.length===1?"":"s"}`),ho(!1),xo([]),K([]),R()}catch(i){console.error("Bulk update excluded states:",i),y.error(i.message||"Unable to update excluded states. Please try again.")}finally{vo(!1)}},[Za,m,_,R,Pe]),Xl=s.useCallback(async()=>{if(!m||Q.length===0||Lt.length===0){y.error("Choose at least one knowledge base item");return}const e=qr(Lt,J);if(e.length===0){y.error("No valid knowledge base items selected");return}Co(!0);try{await Or(k,Q.map(a=>({productId:a.id,fields:{knowledgeBaseItemIds:Ae(a.knowledgeBaseItemIds||[],e)}}))),y.success(`Linked knowledge base item${e.length===1?"":"s"} to ${Q.length} protocol${Q.length===1?"":"s"}`),So(!1),ya([]),go(""),K([]),R()}catch(a){console.error("Bulk add knowledge base links:",a),y.error(a.message||"Unable to link knowledge base items to selected protocols. Please try again.")}finally{Co(!1)}},[Lt,m,J,R,k,Q]),Ql=s.useCallback(async()=>{if(!(!m||Q.length===0)){ko(!0);try{await Ee(Qt,{action:"bulkDeleteNetworkProducts",..._,productIds:Q.map(e=>e.id)}),y.success(`Deleted ${Q.length} protocol${Q.length===1?"":"s"}`),tr(!1),K([]),R()}catch(e){console.error("Bulk delete products:",e),y.error(e.message||"Unable to delete selected protocols. Please try again.")}finally{ko(!1)}}},[m,_,R,Q]),Zl=s.useCallback(async e=>{e&&(sr("file"),ar(e),rr([]),or([]),nr(null))},[]),ec=s.useCallback(async()=>{var e;if(m){if(Ss==="paste"&&!ba.trim()){y.error("Paste spreadsheet content first");return}if(Ss==="file"&&!Bt){y.error("Choose a spreadsheet file first");return}Lo(!0);try{const a=await Ee(Qt,{action:"queueNetworkCatalogImport",..._,...Ss==="paste"?{spreadsheetText:ba}:{fileName:Bt==null?void 0:Bt.name,fileContentBase64:await xa(Bt)}});Io(((e=a==null?void 0:a.data)==null?void 0:e.jobId)||null),y.success("Bulk catalog upload queued. Items will appear as processing finishes.")}catch(a){console.error("Bulk import scoped products:",a),y.error(a.message||"Unable to import protocols. Please try again.")}finally{Lo(!1)}}},[Bt,ba,Ss,m,_,xa]),tc=s.useCallback(async e=>{e&&(cr("file"),dr(e),ur([]),mr([]),gr(null))},[]),sc=s.useCallback(async()=>{var e;if(m){if(Cs==="paste"&&!ha.trim()){y.error("Paste spreadsheet content first");return}if(Cs==="file"&&!At){y.error("Choose a spreadsheet file first");return}Do(!0);try{const a=await Ee(Pa,{action:"queueNetworkCategoryImport",..._,...Cs==="paste"?{spreadsheetText:ha}:{fileName:At==null?void 0:At.name,fileContentBase64:await xa(At)}});To(((e=a==null?void 0:a.data)==null?void 0:e.jobId)||null),y.success("Bulk category upload queued. Categories will appear as processing finishes.")}catch(a){console.error("Bulk import scoped categories:",a),y.error(a.message||"Unable to import categories. Please try again.")}finally{Do(!1)}}},[At,ha,Cs,m,_,xa]),ac=Xo({accept:an,maxFiles:1,multiple:!1,disabled:!I||No||jo,onDrop:async(e,a)=>{if(a.length>0){y.error("Use a CSV, TSV, TXT, XLSX, or XLS file");return}await Zl(e[0])}}),rc=Xo({accept:an,maxFiles:1,multiple:!1,disabled:!I||Ao||Ro,onDrop:async(e,a)=>{if(a.length>0){y.error("Use a CSV, TSV, TXT, XLSX, or XLS file");return}await tc(e[0])}}),oc={accentColor:me,adoptingId:Xn,allVisibleNetworkProductsSelected:vl,assignableNetworkCategories:br,bulkCategoryDialogOpen:gi,bulkCategoryDropzone:rc,bulkCategoryIds:ws,bulkCategoryImportFile:At,bulkCategoryImportOpen:ki,bulkCategoryImportText:ha,bulkCategoryInputMode:Cs,bulkCategoryJob:Ni,bulkCategorySaving:pi,refreshCatalogProducts:R,bulkDeleteDialogOpen:xi,bulkDeleteSaving:vi,bulkExcludedStates:Za,bulkExcludedStatesDialogOpen:fi,bulkExcludedStatesSaving:yi,bulkImportFile:Bt,bulkImportJob:Ci,bulkImportOpen:wi,bulkImportText:ba,bulkInputMode:Ss,bulkKnowledgeBaseDialogOpen:er,bulkKnowledgeBaseIds:Lt,bulkKnowledgeBasePickerColumns:sl,bulkKnowledgeBaseSaving:hi,bulkKnowledgeBaseSearch:vs,bulkProductDropzone:ac,bulkStatusSaving:mi,biomarkerReferenceProducts:Ke,biomarkerReferenceProductsError:We,biomarkerReferenceProductsLoaded:W,biomarkerReferenceProductsLoading:ot,canManageCatalog:I,catalogItemLabel:qi,catalogItemLabelPlural
12:Oi,catalogLabel:F,catalogLabelTitle:Vi,catalogScrollParent:is,categoryDialogOpen:Ka,categoryFilterCounts:ol,categoryForm:Z,categorySearch:fs,categorySortDirection:pl,categorySortKey:gl,categorySourceFilters:ia,categoryStatusFilters:na,editingCategory:Le,editingProduct:ie,embedded:r,exportTenantSlug:z==null?void 0:z.businessName,exportUserType:f==null?void 0:f.userType,fetchAllNetworkProducts:Fi,filteredBulkKnowledgeBasePickerItems:As,filteredCategories:Uo,filteredKnowledgeBasePickerItems:Bs,filteredMasterCategories:zo,filteredMasterProducts:$o,filteredCount:p?Ds.length:Li,filteredNetworkProducts:Ds,formularyDialogOpen:ai,formularyProduct:ri,formsDialogProduct:hs,formsDialogRows:Xi,formPairingSavingIds:si,getNetworkProductActions:$l,handleAdoptMasterCategory:El,handleAdoptMasterProduct:Rl,handleApplyBulkCategories:Gl,handleApplyBulkExcludedStates:Jl,handleApplyBulkKnowledgeBase:Xl,handleArchiveCategory:Fl,handleBulkCategoryImport:sc,handleBulkDeleteProducts:Ql,handleBulkImport:ec,handleBulkProductStatus:Yl,handleCategorySort:fl,handleConfirmProductStatusToggle:zl,handleMasterCategorySort:xl,handleMasterSort:ul,handleNetworkSort:il,handleProductRowCategoriesSave:Tl,handleProductRowNameSave:Al,handleProductRowSyncVisitSave:Ll,handleProductRowLegitScriptSave:jl,legitScriptEnabled:jr,handleProductRowDocumentsSave:Bl,loadKnowledgeBaseItems:Ps,handleSaveCategory:Dl,handleSaveKnowledgeBaseLinks:Wl,handleSaveProduct:Il,headingFontFamily:pt,importing:jo,importingCategories:Ro,isMobileOrTablet:H,isBusinessCatalog:p,catalogOwnerId:m,catalogScope:de,knowledgeBaseDialogOpen:Wa,knowledgeBaseItems:J,knowledgeBaseItemsLoaded:Ut,knowledgeBaseItemsLoading:$t,knowledgeBaseLabelById:Hi,knowledgeBaseListProduct:jt,knowledgeBaseListRows:Qi,knowledgeBasePickerColumns:tl,knowledgeBaseProduct:ct,knowledgeBaseSaving:li,knowledgeBaseSearch:xs,linkedKnowledgeBaseColumns:el,linkedMasterCategoryIds:js,linkedMasterProductIds:Is,hasMore:Ri,loadMasterLabs:Tt,loadBiomarkerReferenceProducts:_i,loading:p?Ze:Ai,loadingMore:Ti,loadMore:Di,manageCategoriesOpen:ei,masterAdoptionFilters:oa,masterCatalogViewportHeight:Et,masterCatalogViewportRef:ns,masterCategories:pe,masterCategoryAdoptionFilters:ca,masterCategoryFilterCounts:nl,masterCategoryFilters:Ua,masterCategoryNameById:Ki,masterCategorySearch:bs,masterCategorySortDirection:hl,masterCategorySortKey:bl,masterCategoryStatusFilters:la,masterLabs:Ne,masterLabsError:at,masterLabsLoaded:ze,masterLabsLoading:Ue,masterProductCategoryFilterOptions:rl,masterProductFilterCounts:Rs,masterProducts:De,masterSearch:It,masterSortDirection:dl,masterSortKey:cl,masterStatusFilters:aa,masterTypeFilters:ra,networkCatalogContextMenu:gs,networkCatalogViewportHeight:Qe,networkCatalogViewportRef:qe,networkCategories:ge,networkCategoryNameById:Mi,networkProductCategoryFilterOptions:al,networkProducts:E,networkSortDirection:Nr,networkSortKey:Pr,openAssociatedFormsDialog:_l,openCreateCategoryDialog:Pl,openCreateProductDialog:Sl,openEditCategoryDialog:Nl,openEditProductDialog:Ir,openFormularyDialog:Br,openKnowledgeBaseDialog:Lr,openKnowledgeBaseListDialog:Ml,openManageCategoriesDialog:Cl,openNetworkCatalogContextMenu:Ul,openProductStatusDialog:Ol,handleActivateProduct:Vl,openTemplatesDialog:kl,parsingBulkCategories:Ao,parsingBulkImport:No,productCategoryFilters:N,productDialogCloseLabel:Ui,productDialogDescription:zi,productDialogOpen:ua,productDialogTitle:$i,productFilterCounts:Ts,productActiveClientCountById:xr,productClientAssignmentIdsById:Gs,productActiveClientCountsLoaded:lt,clientProductAssignmentsLoading:Ot,ensureClientProductAssignmentsLoaded:vr,providerNetworkClientOptions:Yi,clientProductAssignmentSavingKey:us,clientProductAssignmentByClientAndProduct:nt,handleClientProductAssignmentToggle:Gi,createOptions:M,catalogToolbarExtras:S,isStorefrontCatalog:ue,storefront:ue?{clientId:x,overlayByProductId:Wi}:null,productDialogInitialTab:Qn,productForm:P,productFormCountById:hr,productFormsFilter:Ye,productFormularyFilter:Gr,productFormularyCountById:Sr,productLabsFilter:Jr,productSearch:Se,productStatusDialogOpen:ci,productStatusFilters:Kt,productStatusSaving:di,productStatusSavingId:ui,productStatusTarget:dt,productSyncVisitFilter:Xr,productTypeFilters:sa,loadProviderNetworkForms:Ns,providerNetworkForms:Ie,providerNetworkFormsLoaded:Nt,providerNetworkFormsLoading:zt,providerNetworkId:v,resetBulkCategoryDialog:ji,resetBulkProductDialog:Ii,rowCategorySavingProductId:bi,savingCategory:Jn,savingProduct:Gn,scopedFirestoreContext:k,selectedKnowledgeBaseIds:Ht,selectedNetworkProductIds:Pe,selectionIncludesProtocols:Q.some(e=>["product","protocol"].includes(e.type||"product")),setBulkCategoryDialogOpen:fo,setBulkCategoryIds:yo,setBulkCategoryImportFile:dr,setBulkCategoryImportOpen:Pi,setBulkCategoryImportText:Bo,setBulkCategoryInputMode:cr,setBulkCategoryJob:fr,setBulkCategoryJobId:To,setBulkCategorySearch:ys,setBulkCategorySource:gr,setBulkCategoryWarnings:ur,setBulkDeleteDialogOpen:tr,setBulkExcludedStates:xo,setBulkExcludedStatesDialogOpen:ho,setBulkImportFile:ar,setBulkImportJob:lr,setBulkImportJobId:Io,setBulkImportOpen:Si,setBulkImportSource:nr,setBulkImportText:Po,setBulkImportWarnings:rr,setBulkInputMode:sr,setBulkKnowledgeBaseDialogOpen:So,setBulkKnowledgeBaseIds:ya,setBulkKnowledgeBaseSearch:go,setBulkParsedCategories:mr,setBulkParsedProducts:or,setCategoryDialogOpen:ga,setCategoryForm:Ha,setCategorySearch:ys,setCategorySourceFilters:Hn,setCategoryStatusFilters:Kn,setFormularyDialogOpen:io,setFormularyProduct:lo,setFormsDialogProduct:oo,updateProductFormularyCount:ql,toggleFormPairing:Zi,setKnowledgeBaseDialogOpen:Ya,setKnowledgeBaseListProduct:Ga,setKnowledgeBaseSearch:uo,setManageCategoriesOpe
12n:ao,setMasterAdoptionFilters:zn,setMasterCategoryAdoptionFilters:Yn,setMasterCategoryFilters:Un,setMasterCategorySearch:Oa,setMasterCategoryStatusFilters:Wn,setMasterSearch:ta,setMasterStatusFilters:Vn,setMasterTypeFilters:$n,setNetworkCatalogContextMenu:ea,setProductCategoryFilters:j,setProductDialogOpen:ma,setProductForm:za,setProductFormsFilter:_n,setProductFormularyFilter:Mn,setProductLabsFilter:qn,setProductSearch:ps,setProductStatusDialogOpen:Xa,setProductStatusFilters:Va,setProductStatusTarget:Qa,setProductSyncVisitFilter:On,setProductTypeFilters:$a,setSelectedNetworkProductIds:K,setTemplatesOpen:so,setViewingForm:ii,setViewingKnowledgeBaseItem:co,shouldFillCatalogViewport:ve,showHeader:o,someVisibleNetworkProductsSelected:wl,sortedCategories:ml,sortedMasterCategories:yl,sortedMasterProducts:ll,sortedNetworkProducts:Je,templateCatalogLoaded:xt,templateCatalogLoading:$e,templatesOpen:Zn,toggleAllVisibleNetworkProducts:Hl,toggleBulkKnowledgeBaseSelection:kr,toggleKnowledgeBaseSelection:Cr,toggleNetworkProductSelection:Kl,userType:V,totalCount:Bi,usesProtocolLabels:Oe,viewingForm:ni,viewingKnowledgeBaseItem:oi};return{catalogOwnerId:m,usesProtocolLabels:Oe,viewContext:oc}}const tu=s.lazy(()=>Xe(()=>import("./BulkActionDialogs-BucQojJJ.js"),__vite__mapDeps([29,1,3,4,5,6,30,31,26,27,32,33,34,12,35,36,37,19,18,15,7,11,13,14,16,9,10,17,20,8,38,39,40,41,23,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56])).then(r=>({default:r.BulkActionDialogs}))),su=s.lazy(()=>Xe(()=>import("./BulkImportDialogs-QLGbC4Z7.js"),__vite__mapDeps([57,1,3,4,5,6,58,12,35,36,37,19,18,15,7,11,13,14,16,9,10,17,20,8,38,39,40,41,23,26,27,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56])).then(r=>({default:r.BulkImportDialogs}))),au=s.lazy(()=>Xe(()=>import("./CategoryDialogs-DABqNubf.js"),__vite__mapDeps([59,1,3,4,5,6,9,10,11,12,7,13,14,15,16,17,18,19,20,8,60,32,33,34,61,62,54,43,51,27,35,36,37,38,39,40,41,23,26,42,44,45,46,47,48,49,50,52,53,55,56])).then(r=>({default:r.CategoryDialogs}))),ru=s.lazy(()=>Xe(()=>import("./FormularyDefaultsDialog-C0hXQMV-.js"),__vite__mapDeps([63,1,3,4,5,6,64,12,15,8,65,66,67,68,69,70,71,72,73,74,75,76,35,44,42,11,7,13,14,16,9,10,17,18,19,31,48,77,78,79,80,23,81,36,37,20,38,39,40,41,26,27,43,45,46,47,49,50,51,52,53,54,55,56])).then(r=>({default:r.FormularyDefaultsDialog}))),ou=s.lazy(()=>Xe(()=>import("./KnowledgeBaseDialogs-BiCLnIEn.js"),__vite__mapDeps([82,1,3,4,5,6,9,10,11,12,7,13,14,15,16,17,18,19,20,8,83,26,27,35,36,37,38,39,40,41,23,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56])).then(r=>({default:r.KnowledgeBaseDialogs}))),nu=s.lazy(()=>Xe(()=>import("./ProductDialog-DSQ6JXo_.js"),__vite__mapDeps([84,1,3,4,5,6,26,27,33,50,85,17,15,42,86,87,61,62,54,43,51,58,78,32,34,12,35,36,37,19,18,7,11,13,14,16,9,10,20,8,38,39,40,41,23,44,45,46,47,48,49,52,53,55,56,88])).then(r=>({default:r.ProductDialog}
12))),iu=s.lazy(()=>Xe(()=>import("./TemplateCatalogDialog-DMlu-k1A.js"),__vite__mapDeps([89,1,3,4,5,6,15,11,12,7,13,14,16,9,10,17,18,19,8,20,26,27,35,36,37,38,39,40,41,23,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56])).then(r=>({default:r.TemplateCatalogDialog})));function lu(r){const{renderProductDialog:o=nu,...d}=r,{catalogOwnerId:n,usesProtocolLabels:c,viewContext:u}=eu(d),{embedded:h,showHeader:g,canManageCatalog:x,catalogLabel:w,userType:L}=u,S=u.productDialogOpen,U=u.formularyDialogOpen,f=u.templatesOpen,B=u.manageCategoriesOpen||u.categoryDialogOpen,q=!!(u.knowledgeBaseDialogOpen||u.knowledgeBaseListProduct||u.bulkKnowledgeBaseDialogOpen||u.viewingForm||u.viewingKnowledgeBaseItem),X=!!(u.productStatusDialogOpen||u.bulkCategoryDialogOpen||u.bulkExcludedStatesDialogOpen||u.bulkDeleteDialogOpen),A=u.bulkImportOpen||u.bulkCategoryImportOpen;return n?t.jsx(Cd,{value:u,children:t.jsxs("div",{className:h?"space-y-4 max-lg:space-y-2.5":"app-page-shell space-y-6 max-lg:space-y-3",children:[g&&!h?t.jsx(hd,{title:c?"Protocols":"Products",description:x?`Manage your ${w} catalog, review reusable templates, and link knowledge base references for review workflows.`:`Browse your ${w} catalog and templates in read-only mode as a ${L||"provider delegate"}.`}):null,t.jsx("div",{className:"space-y-6 max-lg:space-y-3",children:t.jsx(Fd,{})}),t.jsxs(s.Suspense,{fallback:null,children:[U?t.jsx(ru,{}):null,f?t.jsx(iu,{}):null,S?t.jsx(o,{}):null,B?t.jsx(au,{}):null,q?t.jsx(ou,{}):null,X?t.jsx(tu,{}):null,A?t.jsx(su,{}):null]})]})}):t.jsxs(Nn,{className:"rounded-2xl border border-subtle p-8 max-lg:p-3 dark:bg-slate-800",children:[t.jsx("h2",{className:"font-display text-xl font-semibold text-content-primary max-lg:text-base",children:c?"Protocols":"Products"}),t.jsx("p",{className:"mt-2 text-sm text-content-secondary max-lg:mt-1.5 max-lg:text-xs",children:"Your account is not linked to a business or provider network yet, so the catalog cannot be managed."})]})}const zu=Object.freeze(Object.defineProperty({__proto__:null,default:lu},Symbol.toStringTag,{value:"Module"}));export{vd as F,zu as P,Uu as a,Ma as u};
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.