1import{r as i,j as t}from"./react-vendor-CU6Sz31W.js";import{f2 as gr,e as Gs,cf as xr,j as E,ax as na,i as A,a0 as Zt,ae as ut,af as mt,ag as pt,cr as Mr,I as ke,az as Ae,S as Ve,ce as qt,qK as Bi,t as g,i7 as Oi,at as zi,cd as Dr,c6 as Ri,et as _i,eu as Ki,ev as hr,gi as fr,nK as Gt,U as Vi,fG as Te,c7 as Ys,c8 as Js,c9 as Xs,ca as Zs,nT as Yt,cb as Qs,g9 as Wi,bN as ea,bO as ta,bP as sa,aY as $r,bQ as aa,ii as Hi,u as qi,al as Gi,be as zs,bg as Rs,rw as Yi,b as Ji,as as Bt,fK as Xi,nU as ye,aS as br,nO as Ce,bX as Ot,gN as Zi,bR as yr,jM as Cr,gB as Qi,lT as en,aL as tn,nV as vr,eq as sn,c_ as _s,c$ as Ks,d0 as Vs,d2 as Ws,ex as kr,d5 as an,jb as rn,cO as nn,au as jr}from"./index-DEXJEDAi.js";import{a as on,b as ln}from"./clientViewHelpers-DdlucuaE.js";import{H as zt}from"./ExportCsvAction-BJr9eiP6.js";import{T as cn}from"./text-highlight-BFqqfcjs.js";import{b as dn,a as un}from"./DataTableCard-BluwWKn_.js";import"./patient-name-link-BAfQKbEs.js";import{I as mn,D as pn}from"./cells-Db2ZEFlu.js";import{f as gn,q as xn,w as hn,e as wr,g as fn,d as bn,c as yn}from"./firebase-w6DYUbFN.js";import{s as Cn}from"./rawTableExport-DjSsUxyR.js";import{P as vn}from"./PlatformFeeSetupBanner-BiCbPzB-.js";import{c as xe}from"./manageLabApi-BUlVz8vT.js";import{f as kn}from"./labsData-CkdRlz2Q.js";import jn from"./SendProductToPatientModal-B_zcqAFo.js";import{A as wn}from"./AssociatedProductsField-9aZuux92.js";import{u as Nn}from"./useTableSort-KpNOL2n3.js";import{b as Sn,C as Ln}from"./ClientProductCouponsManager-B7-aMQgR.js";import Pn from"./ClientCategoriesManagerDialog-D_NihaRA.js";import{u as In}from"./clientFormsFirestore-DBRoH-Ls.js";import{P as An,c as En,b as Tn}from"./ProductInlineEditPopovers-B7oRL8nE.js";import{b as re,c as xt,d as Ur,a as dt,g as Re,e as de,h as Hs,i as Fn,j as Mn}from"./labDisplayUtils-D6xhR45u.js";import{g as gt,L as Dn}from"./LabForm-sUCZJmQL.js";import{L as $n}from"./LabBilledPriceCell-DGN56oB0.js";import{L as Un}from"./LabStorefrontCard-Bvq8l8dZ.js";import{n as Rt,a as Nr}from"./catalogStateExclusions-C6BtORvT.js";import{M as Bn}from"./modal-option-cards-Dksohkou.js";import{p as ra,f as On,L as Ee,a as zn,g as Sr,s as Lr,i as _t,b as Pr,c as Kt,d as ve,e as Ir,r as Rn}from"./labCheckoutLinks-DPo524I1.js";import{s as _n,i as Kn}from"./labIntegrationDefinitions-DsxE_lJg.js";import{L as Vn}from"./lab-markers-popover-Dp7gAQYc.js";import{M as Wn,o as Hn}from"./modal-form-CqN5DZuv.js";import{C as qn}from"./CatalogStateExclusionsPanel-eJPBk-Pg.js";import{C as Gn}from"./CatalogItemFormsTab-DGZAm4cd.js";import{B as Jt}from"./beaker-DG-PilI_.js";import{S as Yn}from"./sliders-horizontal-Bt65nPrH.js";import"./payment-icons-Daq1K3F1.js";import"./link-2-a8lhpkQ6.js";import"./index-BSuGcRaZ.js";import"./table-CxPdvV_9.js";import"./arrow-up-D6DFVL4j.js";import"./arrow-down-BjUlbB4f.js";import"./pill-filter-CtZSNPVl.js";import"./date-picker-filter-Qp1kqu9t.js";import"./calendar-RV2oTCrW.js";import"./addWeeks-1hrFjz19.js";import"./clear-filters-button-DmPemFGr.js";import"./ellipsis-vertical-C-dQ6Kzj.js";import"./usePatientTerminology-D5bkkKg2.js";import"./patientInviteApi-BQHHKSjN.js";import"./catalogVisitMode-De-HDuz9.js";import"./useProductSubscriptionOffer-DL7oz6fV.js";import"./subscriptionOffer--xmeipjh.js";import"./ellipsis-tooltip-CfKm8VFV.js";import"./useOpenPatientProfile-CASNKG5E.js";import"./pencil-CpqYHolO.js";import"./ban-DZ1NMSKK.js";import"./power-D6NB1cYy.js";import"./scopedCategoryFirestore-C15ZJbmw.js";import"./CategoryFormDialog-bVZylz8q.js";import"./RequirementControls-Wb_UaVb6.js";import"./labBiomarkerApi-Ck21Kuon.js";import"./LabAdjudicationUnavailableNotice-Caxh_Djm.js";import"./labRecencyWindow-BLArGdSC.js";import"./labBiomarkerRequirementModel-Bqa1eFIF.js";import"./archive-restore-1_z2aByp.js";import"./collapsible-JRJGT2Lx.js";import"./formChangeLogs-Yl91HkEm.js";import"./CatalogSelectionList-D9FsL1Nv.js";import"./clock-3-31WD3-4z.js";import"./arrow-right-BC3JVmLt.js";import"./BiomarkerBadges-CRgr_flG.js";import"./venus-C_yJfLMt.js";import"./providerAssignments-C7MWOvAk.js";import"./integrationScopeAccess-DxVEy3Qu.js";import"./CatalogItemAdminFormPreviewModal-BQ14I7dT.js";import"./IntakeVersionEditorDialog-AuX4y5Es.js";import"./FormBuilder-yfdeRhed.js";import"./date-of-birth-picker-BQ2yrZNI.js";import"./quill-editor-D-DS6c39.js";import"./editor-D8UbQKN1.js";import"./audio-lines-GJL3_Ka2.js";import"./square-D7DkS8S2.js";import"./code-BEcI87AG.js";import"./strikethrough-CiKozLGy.js";import"./underline-B_XtWKJP.js";import"./list-ordered-GNrnoOhB.js";import"./useEditorTranscription-CN2PcNng.js";import"./AssistantMarkdownContent-OjQ8GujO.js";import"./useOfflineFormDraftSync-D_7gScL0.js";import"./offlineFormDrafts-CAcyqTIL.js";import"./FormPreviewDialog-DrDrSHEH.js";import"./square-check-big-BIK4lrHD.js";import"./PatientFieldDefinitionDialog-BZBSN9SQ.js";import"./usePatientFieldDefinitions-DS6fhdRU.js";import"./patientFieldDefinitionCaches-PDqtgCkY.js";import"./redo-2-DoWP9VFC.js";import"./arrow-right-left-B4vnGqzD.js";import"./core.esm-DPjjHB-Z.js";import"./sortable.esm-Cj9Co3ow.js";import"./type-CJ1z0FOW.js";import"./circle-dot-B6AVn653.js";import"./user-round-c4EWOTq5.js";import"./keyboard-DLwPN9xF.js";import"./git-branch-BaXsltg0.js";import"./ellipsis-C0FvDuxB.js";import"./hash-C7GcXMrW.js";import"./intakeVersionsApi-DctKdHHP.js";function Jn(){return t.jsxs("div",{className:"space-y-3",children:[t.jsx(Zt,{className:"h-24 w-full rounded-xl"}),t.jsx(Zt,{className:"h-24 w-full rounded-xl"})]})}function Xn({open:o,onOpenChange:x,labName:C="Lab",intent:j="copy",products:M=[],loading:d=!1,error:f="",accentColor:L,onRetry:Z,onSelectProduct:h,returnFocusRef:T}){const k=i.useRef(!1),[V,P]=i.useState(j==="open"?"open":"copy");i.useEffect(()=>{var l,v;if(o){k.current=!0,P(j==="open"?"open":"copy");return}k.current&&(T!=null&&T.current)&&((v=(l=T.current).focus)==null||v.call(l))},[o,j,T]);const{eligible:p,ineligible:F}=i.useMemo(()=>ra(M),[M]),D=p.length,Q=i.useMemo(()=>{const l=p.filter(v=>(v==null?void 0:v.sendToPatientDefaultFlow)==="visit_first");return l.length===1?new Set([l[0].clientProductId]):new Set},[p]),z=l=>Q.has(l.clientProductId),ee=[...p.map(l=>({id:l.clientProductId,icon:gr,title:l.displayName||l.name||"Product",description:On(l),testId:E("button","labs",`combined-picker-${l.clientProductId}`),badge:z(l)?t.jsx("span",{className:Gs("shrink-0 whitespace-nowrap",xr("emerald")),children:"Recommended"}):null,onSelect:()=>h==null?void 0:h(l,V)})),...F.map(l=>({id:`ineligible-${l.clientProductId}`,icon:gr,title:l.displayName||l.name||"Product",description:l.combinedLinkIneligibleReason||"Not eligible for this link.",disabled:!0,testId:E("button","labs",`combined-picker-ineligible-${l.clientProductId}`),onSelect:()=>{}}))];return t.jsx(na,{mobileCompactHeaderRow:!0,open:o,onOpenChange:x,title:Ee.pickerTitle,description:`${Ee.pickerDescription} ${C} uses the lab, then consultation path.`,headerRight:D>1?t.jsx("span",{className:Gs("shrink-0 whitespace-nowrap",xr("blue")),children:zn(D)}):null,contentTestId:E("dialog","labs","combined-checkout-picker"),closeLabel:"Close product picker",contentClassName:"max-w-2xl",bodyClassName:"max-h-[70vh] overflow-y-auto",children:t.jsx("div",{"data-row-click-ignore":!0,onClick:l=>l.stopPropagation(),children:d?t.jsx(Jn,{}):f?t.jsxs("div",{className:"space-y-3 rounded-xl border border-subtle p-4",children:[t.jsx("p",{className:"text-sm text-slate-700 dark:text-slate-300",children:f}),Z?t.jsx(A,{type:"button",variant:"outline",className:"rounded-full",onClick:Z,children:"Retry"}):null]}):p.length===0?t.jsx("div",{className:"space-y-3 rounded-xl border border-subtle p-4",children:t.jsx("p",{className:"text-sm text-slate-700 dark:text-slate-300",children:"No linked products are eligible for this combined link. Review linked products on the Products page."})}):t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(A,{type:"button",size:"sm",variant:"outline",className:"h-8 rounded-full px-3 text-xs",style:V==="copy"&&L?{borderColor:L,color:L}:void 0,"aria-pressed":V==="copy",onClick:()=>P("copy"),"data-testid":E("button","labs","combined-picker-intent-copy"),children:"Copy link"}),t.jsx(A,{type:"button",size:"sm",variant:"outline",className:"h-8 rounded-full px-3 text-xs",style:V==="open"&&L?{borderColor:L,color:L}:void 0,"aria-pressed":V==="open",onClick:()=>P("open"),"data-testid":E("button","labs","combined-picker-intent-open"),children:"Open checkout"})]}),t.jsx(Bn,{accentColor:L,columns:p.length>=2?2:1,"data-testid":E("options","labs","combined-checkout-picker"),options:ee})]})})})}function _e(o={}){var M,d,f,L;const x=String(((M=o.integrationMetadata)==null?void 0:M.adapterKey)||"").trim().toLowerCase(),C=String(((d=o.integrationMetadata)==null?void 0:d.externalStatus)||"").trim().toLowerCase();return x==="junction"||!!((f=o.integrationParams)!=null&&f.labTestId)?C==="pending_approval"?{id:"pending_approval",label:"Pending approval",blocksActivation:!0}:C==="active"||((L=o.integrationMetadata)==null?void 0:L.externalIsActive)===!0?String(o.status||"").toLowerCase()!=="active"?{id:"ready_to_activate",label:"Ready to activate",blocksActivation:!1}:{id:"active",label:"Active",blocksActivation:!1}:{id:"inactive",label:"Unavailable",blocksActivation:!0}:{id:"not_applicable",label:"",blocksActivation:!1}}function Zn(o){return o==="pending_approval"?"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-300":o==="ready_to_activate"||o==="active"?"border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-300":"border-subtle bg-surface-sunken text-content-secondary"}function Fe(o=[]){return Array.from(new Set(o.map(x=>
1String(x||"").trim()).filter(Boolean)))}function Br(o={}){return Fe([o.id,o.clientProductId,o.catalogEntryId,o.productId,o.sourceProductId,o.rootLabId])}function ia(o={},x={},C=[]){const j=o.associations||{};if(j.applyToAll===!0)return"all";const M=Fe(j.categoryIds),d=new Set(Fe(C));if(M.some(L=>d.has(L)))return"category";const f=new Set(Fe([j.productId,...Array.isArray(j.productIds)?j.productIds:[]]));return Br(x).some(L=>f.has(L))?"direct":"none"}function Qn({form:o,lab:x,shouldPair:C}){const j=(o==null?void 0:o.associations)||{},M=new Set(Br(x)),d=Fe([...Array.isArray(j.productIds)?j.productIds:[],j.productId]),f=String((x==null?void 0:x.catalogEntryId)||(x==null?void 0:x.id)||(x==null?void 0:x.clientProductId)||"").trim();return{applyToAll:j.applyToAll===!0,productIds:C?Fe([...d,f]):d.filter(L=>!M.has(L)),categoryIds:Fe(j.categoryIds)}}function eo(o={}){const x=String(o.formType||o.type||"").trim().toLowerCase(),C=String(o.status||"active").trim().toLowerCase();return["intake","consent"].includes(x)&&["active","published"].includes(C)}function qs(o={}){return o.name||o.displayName||o.title||"Untitled form"}const Ar={all:"All labs",category:"Category"};function to({lab:o,categoryIds:x=[],forms:C=[],loading:j=!1,canEdit:M=!1,savingFormIds:d=[],onToggle:f}){const[L,Z]=i.useState(!1),[h,T]=i.useState(""),k=i.useMemo(()=>new Set(d),[d]),V=i.useMemo(()=>C.filter(p=>ia(p,o,x)!=="none").length,[x,C,o]),P=i.useMemo(()=>{const p=h.trim().toLowerCase();return p?C.filter(F=>qs(F).toLowerCase().includes(p)||String(F.id||"").toLowerCase().includes(p)):C},[C,h]);return t.jsxs(ut,{open:L,onOpenChange:p=>{Z(p),p||T("")},children:[t.jsx(mt,{asChild:!0,children:t.jsxs(A,{type:"button",variant:"outline",size:"sm",className:"h-7 min-w-20 rounded-full px-2.5 text-xs font-normal",onClick:p=>p.stopPropagation(),"data-row-click-ignore":!0,"aria-label":`${M?"Manage":"View"} forms for ${o.displayName||o.name||"lab"}`,"data-testid":E("button","labs","row-forms-trigger"),children:[V," ",V===1?"form":"forms"]})}),t.jsxs(pt,{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 ${o.displayName||o.name||"lab"}`,"data-testid":E("dialog","labs","row-forms"),onClick:p=>p.stopPropagation(),children:[t.jsxs("div",{className:"border-b border-subtle px-3 py-2.5 max-lg:px-2 max-lg:py-1.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 max-lg:text-xs",children:"Client forms"}),t.jsxs("span",{className:"text-xs text-content-tertiary max-lg:text-3xs",children:[V," paired"]})]}),t.jsxs("div",{className:"relative mt-2 max-lg:mt-1.5",children:[t.jsx(Mr,{className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-content-tertiary","aria-hidden":!0}),t.jsx(ke,{value:h,onChange:p=>T(p.target.value),placeholder:"Search formsâ¦","aria-label":"Search client forms",className:"h-8 pl-7 text-xs max-lg:h-7 max-lg:py-1"})]})]}),t.jsx("div",{className:"max-h-80 overflow-y-auto p-2 max-lg:max-h-72",children:j?t.jsx("div",{className:"space-y-1.5 p-1",children:[0,1,2].map(p=>t.jsx(Zt,{className:"h-9 w-full rounded-lg"},p))}):P.length===0?t.jsx("p",{className:"px-2 py-5 text-center text-xs text-content-tertiary max-lg:py-3 max-lg:text-2xs",children:h?"No forms match your search.":"No active client forms available."}):P.map(p=>{const F=ia(p,o,x),D=F!=="none",Q=F==="all"||F==="category",z=k.has(p.id),ee=!M||Q||z;return t.jsxs("div",{className:Gs("flex min-h-9 items-center gap-2 rounded-lg px-2 py-1 text-sm text-content-secondary hover:bg-muted max-lg:min-h-8 max-lg:gap-1.5 max-lg:text-xs",z&&"opacity-70"),children:[t.jsx(Ae,{checked:D,disabled:ee,onCheckedChange:l=>void f(p,l===!0),"aria-label":`${D?"Detach":"Attach"} ${qs(p)}`}),t.jsx(A,{type:"button",variant:"ghost",className:"h-auto min-h-0 min-w-0 flex-1 justify-start truncate rounded-none p-0 text-left font-normal hover:bg-transparent max-lg:min-h-0",disabled:ee,onClick:()=>void f(p,!D),children:qs(p)}),z?t.jsx(Ve,{size:"xs",className:"shrink-0","aria-label":"Saving form pairing"}):Ar[F]?t.jsx(qt,{variant:"outline",className:"shrink-0 rounded-full px-1.5 py-0 text-3xs font-normal text-content-tertiary",children:Ar[F]}):null]},p.id)})})]})]})}function Xt(o){const x=String(o??"").trim();if(!x)return null;if(!/^(?:\d+(?:\.\d{0,2})?|\.\d{1,2})$/.test(x))return;const C=Number(x);return Number.isFinite(C)?C:void 0}function ue(o=""){return String(o||"").trim().toLowerCase()}function Er(o){return String((o==null?void 0:o.name)||(o==null?void 0:o.slug)||o||"").trim()}function so({markers:o=[],availableMarkers:x=[],integrationId:C=null,onChange:j,disabled:M=!1,readOnly:d=!1,required:f=!0}){const[L,Z]=i.useState(""),[h,T]=i.useState([]),[k,V]=i.useState(!1),P=!d&&!M,p=i.useMemo(()=>new Set(o.map(l=>
1ue(l)).filter(Boolean)),[o]),F=i.useMemo(()=>{const l=new Map;return[...x,...h].forEach(v=>{const $=Er(v),U=ue($);!U||l.has(U)||l.set(U,$)}),Array.from(l.values()).sort((v,$)=>v.localeCompare($))},[x,h]),D=i.useMemo(()=>{const l=ue(L);return F.filter(v=>{const $=ue(v);return!$||p.has($)?!1:!l||$.includes(l)}).slice(0,12)},[F,L,p]),Q=i.useMemo(()=>{const l=ue(L);return l&&F.find(v=>ue(v)===l)||null},[F,L]);i.useEffect(()=>{if(!P||!C){T([]),V(!1);return}const l=L.trim();let v=!1;const $=window.setTimeout(async()=>{V(!0);try{const U=await Bi({integrationId:C,search:l,size:100,aLaCarteEnabled:!0});if(v)return;T((U.markers||[]).map(O=>Er(O)).filter(Boolean))}catch(U){v||(T([]),l&&g.error(U.message||"Unable to search markers"))}finally{v||V(!1)}},l?350:0);return()=>{v=!0,window.clearTimeout($)}},[L,P,C]);function z(l){if(!P)return;const v=String(l||"").trim();if(!v)return;const $=ue(v);if(p.has($)){Z("");return}const U=F.find(O=>ue(O)===$);if(!U){g.error("Choose a marker from the list. Free-text markers are not allowed.");return}j==null||j([...o,U]),Z("")}function ee(l){if(!P)return;if(f&&o.length<=1){g.error("At least one marker is required.");return}const v=ue(l);j==null||j(o.filter($=>ue($)!==v))}return t.jsxs("div",{className:"pt-1 max-lg:pt-0","data-testid":E("section","labs","markers-editor"),children:[t.jsxs("p",{className:"mb-2 text-xs font-medium text-content-secondary max-lg:mb-1 max-lg:text-2xs",children:["Markers",!d&&f?t.jsx(Oi,{}):null]}),t.jsx("div",{className:"flex flex-wrap gap-2 max-lg:gap-1",children:o.length>0?o.map(l=>d?t.jsx("span",{className:"inline-flex items-center rounded-full border border-default bg-surface-raised px-2.5 py-1 text-xs font-medium text-slate-700 max-lg:px-1.5 max-lg:py-0.5 dark:text-slate-200",children:l},l):t.jsxs("button",{type:"button",onClick:v=>{v.preventDefault(),v.stopPropagation(),ee(l)},disabled:!P,className:"inline-flex items-center gap-1 rounded-full border border-default bg-surface-raised px-2.5 py-1 text-xs font-medium text-slate-700 transition hover:border-slate-300 hover:bg-slate-50 disabled:opacity-50 max-lg:px-1.5 max-lg:py-0.5 dark:text-slate-200 dark:hover:bg-slate-800","aria-label":`Remove ${l}`,children:[t.jsx("span",{children:l}),t.jsx(zi,{className:"size-3 shrink-0 text-content-tertiary pointer-events-none","aria-hidden":!0})]},l)):t.jsx("span",{className:"text-xs text-content-tertiary max-lg:text-2xs",children:"No markers yet."})}),d?t.jsx("p",{className:"mt-2 text-xs text-content-tertiary max-lg:text-2xs",children:"Markers come from the imported panel and cannot be changed here."}):t.jsxs("div",{className:"relative z-30 mt-3 max-w-md space-y-1.5",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"relative min-w-0 flex-1",children:[t.jsx(Mr,{className:"pointer-events-none absolute left-3 top-1/2 size-3.5 -translate-y-1/2 text-content-tertiary","aria-hidden":!0}),t.jsx(ke,{value:L,onChange:l=>Z(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),Q?z(Q):D[0]?z(D[0]):g.error("Choose a marker from the list. Free-text markers are not allowed."))},placeholder:"Search markers to add",disabled:!P,className:"h-9 pl-9","aria-label":"Search markers","data-testid":E("input","labs","add-marker")})]}),t.jsxs(A,{type:"button",variant:"outline",size:"sm",className:"h-9 shrink-0 rounded-full",onClick:()=>{Q?z(Q):D[0]?z(D[0]):g.error("Choose a marker from the list. Free-text markers are not allowed.")},disabled:!P||!L.trim()||k,children:[k?t.jsx(Ve,{size:"sm",className:"mr-1"}):t.jsx(Dr,{className:"mr-1 size-3.5","aria-hidden":!0}),"Add"]})]}),L.trim()?t.jsx("div",{className:"absolute z-40 mt-1 max-h-48 w-full overflow-y-auto rounded-lg border border-subtle bg-surface-raised p-1 shadow-lg",children:k&&D.length===0?t.jsx("p",{className:"px-2.5 py-2 text-sm text-content-tertiary",children:"Searching markersâ¦"}):D.length>0?D.map(l=>t.jsx("button",{type:"button",className:"flex w-full rounded-md px-2.5 py-2 text-left text-sm text-slate-700 hover:bg-slate-100 max-lg:text-xs dark:text-slate-200 dark:hover:bg-slate-800",onMouseDown:v=>v.preventDefault(),onClick:()=>z(l),children:l},l)):t.jsx("p",{className:"px-2.5 py-2 text-sm text-content-tertiary",children:"No matching markers. Pick from the list â free text is not allowed."})}):null]})]})}function Tr({lab:o,compact:x=!1,field:C="all"}){const j=xt(o),M=Ur(o),d=C==="name"?j:C==="description"?M:"";if(C!=="all"&&!d||C==="all"&&!j&&!M)return null;const f=C==="name"?"Show lab catalog name":C==="description"?"Show lab catalog description":`View ${j||"lab"} catalog details`;return t.jsx(ea,{delayDuration:150,children:t.jsxs(ta,{children:[t.jsx(sa,{asChild:!0,children:t.jsx("button",{type:"button",className:`${x?"size-4":"size-6"} inline-flex shrink-0 items-center justify-center rounded-full text-slate-400 transition hover:bg-slate-100 hover:text-slate-600 dar
1k:text-slate-500 dark:hover:bg-slate-700 dark:hover:text-slate-300`,onClick:L=>L.stopPropagation(),"data-row-click-ignore":!0,"aria-label":f,children:t.jsx($r,{className:"size-3.5"})})}),t.jsxs(aa,{side:"top",className:"max-w-xs text-xs",children:[C==="name"?d:null,C==="description"?t.jsx("span",{className:"line-clamp-4",children:d}):null,C==="all"?t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"font-semibold text-content-primary",children:"GEN Health catalog"}),j?t.jsxs("p",{children:["Name: ",j]}):null,M?t.jsxs("p",{className:"line-clamp-4",children:["Description: ",M]}):null]}):null]})]})})}const ao=10*1024*1024,ro={"image/jpeg":[".jpg",".jpeg"],"image/png":[".png"],"image/webp":[".webp"]};function io({lab:o,initialValues:x,headerRight:C,categories:j,clientId:M,clientData:d,accentColor:f,canEditLabPricing:L,isClientAdmin:Z,saving:h,onClose:T,onSave:k,availableMarkers:V=[]}){var me;const P=gt(o,d),[p,F]=i.useState(()=>({...x,biomarkers:Array.isArray(x==null?void 0:x.biomarkers)?x.biomarkers:re(o)})),[D,Q]=i.useState(""),z=i.useRef(null),[ee,l]=i.useState("overview"),[v,$]=i.useState(null),[U,O]=i.useState("");i.useEffect(()=>{if(!v)return;const b=URL.createObjectURL(v);return O(b),()=>URL.revokeObjectURL(b)},[v]);function te(b,R){b==="customerPrice"&&Q(""),F(oe=>({...oe,[b]:R}))}function We(){if(L&&Xt(p.customerPrice)===void 0){Q("Enter a non-negative price with up to two decimal places."),l("overview"),requestAnimationFrame(()=>{var b;return(b=z.current)==null?void 0:b.focus()});return}k({...p,biomarkers:re(o),imageFile:v})}function Me(b){F(R=>({...R,displayCategoryIds:R.displayCategoryIds.includes(b)?R.displayCategoryIds.filter(oe=>oe!==b):[...R.displayCategoryIds,b]}))}function ht(b,R){if(R.length){Wi.error("Please upload a JPG, PNG, or WEBP under 10MB.");return}b[0]&&$(b[0])}return t.jsx(na,{open:!0,onOpenChange:b=>{b||T()},title:"Edit lab",description:"Customize how this lab appears to patients.",size:"xl",headerRight:C,footer:t.jsxs("div",{className:"flex justify-end gap-2 max-lg:gap-1.5",children:[t.jsx(A,{type:"button",variant:"outline",className:"rounded-full",onClick:T,disabled:h,children:"Cancel"}),t.jsxs(A,{type:"submit",form:"labs-client-admin-view-form-2",className:"rounded-full text-white",style:{backgroundColor:f},disabled:h,children:[h?t.jsx(Ve,{size:"md",className:"mr-2"}):null,"Save"]})]}),children:t.jsx("form",{id:"labs-client-admin-view-form-2",className:Wn,onSubmit:Hn(We,{disabled:h}),children:t.jsx(Ri,{className:"bg-surface-raised",children:o?t.jsxs(_i,{value:ee,onValueChange:l,className:"space-y-4 max-lg:space-y-2.5",children:[t.jsxs(Ki,{className:"h-8 max-lg:w-full max-lg:justify-start max-lg:overflow-x-auto max-lg:[&>*]:shrink-0",children:[t.jsx(hr,{value:"overview",className:"text-xs",children:"Overview"}),t.jsx(hr,{value:"forms",className:"text-xs",children:"Forms"})]}),t.jsxs(fr,{value:"overview",className:"mt-0 space-y-4 max-lg:space-y-2.5",children:[t.jsxs("div",{className:"grid gap-4 max-lg:gap-2.5 md:grid-cols-[12rem_minmax(0,1fr)]",children:[t.jsx(Gt,{onDrop:(b,R)=>ht(b,R),accept:ro,maxFiles:1,maxSize:ao,noClick:!0,noKeyboard:!0,children:({getRootProps:b,getInputProps:R,open:oe})=>t.jsxs("div",{...b(),className:"space-y-2 max-lg:space-y-1.5",children:[t.jsx("input",{...R()}),t.jsx("button",{type:"button",onClick:oe,className:"flex aspect-square w-full items-center justify-center overflow-hidden rounded-xl border border-dashed border-default bg-surface-sunken max-lg:mx-auto max-lg:max-w-[8rem]","aria-label":"Upload lab image","data-testid":E("dropzone","labs","detail-image"),children:U||p.displayImageUrl?t.jsx("img",{src:U||p.displayImageUrl,alt:p.displayName||"Lab",className:"h-full w-full object-cover"}):t.jsx(Jt,{className:"size-8 text-slate-400 max-lg:size-6"})}),t.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:oe,className:"h-8 w-full rounded-full text-xs max-lg:text-2xs",children:"Upload image"})]})}),t.jsxs("div",{className:"space-y-3 max-lg:space-y-2",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"mb-1 flex items-center gap-1.5",children:[t.jsx("label",{className:"block text-xs font-medium text-content-secondary max-lg:text-2xs",children:"Display name"}
1),t.jsx(Tr,{lab:o,compact:!0,field:"name"})]}),t.jsx(ke,{"aria-label":"Display name",value:p.displayName,onChange:b=>te("displayName",b.target.value),className:"h-9"}),xt(o)?t.jsxs("p",{className:"mt-1 text-2xs text-content-tertiary max-lg:text-3xs",children:["Lab catalog name: ",t.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-300",children:xt(o)})]}):null]}),t.jsxs("div",{children:[t.jsxs("div",{className:"mb-1 flex items-center gap-1.5",children:[t.jsx("label",{className:"block text-xs font-medium text-content-secondary max-lg:text-2xs",children:"Display description"}),t.jsx(Tr,{lab:o,compact:!0,field:"description"})]}),t.jsx(Vi,{"aria-label":"Display description",value:p.displayDescription,onChange:b=>te("displayDescription",b.target.value),className:"min-h-28 max-lg:min-h-20"})]}),t.jsxs("div",{className:"grid gap-3 max-lg:gap-2 sm:grid-cols-3",children:[L?t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("label",{className:"mb-1 block text-xs font-medium text-content-secondary max-lg:text-2xs",children:"Patient total"}),t.jsx(ke,{type:"text",inputMode:"decimal",ref:z,error:D,"aria-label":"Patient total",value:p.customerPrice,onChange:b=>te("customerPrice",b.target.value),className:"h-9"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"mb-1 block text-xs font-medium text-content-secondary max-lg:text-2xs",children:"Cost"}),t.jsx(ke,{value:Te(P.totalCents/100)||"â",readOnly:!0,className:"h-9 bg-surface-sunken text-content-tertiary"}),t.jsxs("p",{className:"mt-1 text-2xs text-content-tertiary",children:[Te(P.labCostCents/100)||"$0.00"," lab",P.homeDrawFeeCents>0?t.jsxs(t.Fragment,{children:[" + ",Te(P.homeDrawFeeCents/100)," home blood draw"]}):null," + ",Te(P.feeCents/100)||"$0.00"," processing"]})]})]}):null,t.jsxs("div",{children:[t.jsx("label",{className:"mb-1 block text-xs font-medium text-content-secondary max-lg:text-2xs",children:"Lab code"}),t.jsx(ke,{value:o.code||"",readOnly:!0,className:"h-9 bg-surface-sunken text-content-tertiary"})]})]})]})]}),t.jsx(so,{markers:p.biomarkers,availableMarkers:V,integrationId:(o==null?void 0:o.integrationId)||((me=o==null?void 0:o.integrationMetadata)==null?void 0:me.integrationId)||null,onChange:b=>te("biomarkers",b),disabled:h,readOnly:!0}),t.jsxs("div",{className:"pt-1 max-lg:pt-0",children:[t.jsx("p",{className:"mb-2 text-xs font-medium text-content-secondary max-lg:mb-1 max-lg:text-2xs",children:"Categories"}),t.jsx("div",{className:"flex flex-wrap gap-2 max-lg:gap-1",children:j.length>0?j.map(b=>{const R=p.displayCategoryIds.includes(b.id);return t.jsx("button",{type:"button",onClick:()=>Me(b.id),className:`rounded-full border px-3 py-1 text-xs font-medium max-lg:px-2 max-lg:text-2xs ${R?"border-transparent text-white":"border-slate-200 bg-white text-slate-600 hover:bg-slate-50 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300 dark:hover:bg-slate-800"}`,style:R?{backgroundColor:f}:void 0,children:b.name||"Category"},b.id)}):t.jsx("span",{className:"text-xs text-content-tertiary max-lg:text-2xs",children:"No categories available."})})]}),Z?t.jsxs("div",{className:"pt-1 max-lg:pt-0",children:[t.jsx("label",{htmlFor:"lab-target-sex",className:"mb-1 block text-xs font-medium text-content-secondary max-lg:text-2xs",children:"Target Audience"}),t.jsxs(Ys,{value:p.targetSex,onValueChange:b=>te("targetSex",b),children:[t.jsx(Js,{id:"lab-target-sex",className:"h-9 max-w-xs","data-testid":E("select","labs","target-audience"),children:t.jsx(Xs,{placeholder:"Select audience"})}),t.jsx(Zs,{children:Yt.map(b=>t.jsx(Qs,{value:b.value,children:b.label},b.value))})]}),t.jsx("p",{className:"mt-1 text-2xs text-content-tertiary max-lg:text-3xs",children:'Patients filter the lab catalog by this. "Any" shows this lab to everyone.'})]}):null,Z?t.jsx("div",{className:"pt-1 max-lg:pt-0",children:t.jsx(qn,{selectedStates:p.excludedStates,onChange:b=>te("excludedStates",b),accentColor:f,testScope:"labs-client",description:"Patients in selected states cannot see or order this lab.",lockedStates:(o==null?void 0:o.inheritedExcludedStates)||[]})}):null]}),t.jsx(fr,{value:"forms",className:"mt-0",children:t.jsx(Gn,{clientId:M,catalogItem:o,catalogItemType:"lab",categoryIds:p.displayCategoryIds})})]}):null})})})}const Vt=10*1024*1024,Wt={"image/jpeg":[".jpg",".jpeg"],"image/png":[".png"],"image/webp":[".webp"]};function Ke(o={}){return(o==null?void 0:o.status)!=="inactive"}function no(o){return o?{status:"active"}:{status:"inactive",showPatient:!1}}function oo(o={}){return o!=null&&o.stripeCustomerId?!!o.defaultPaymentMethodId||Number(o.paymentMethodCount)>0:!1}
1function Ht(o){return Number.isFinite(o)?o<100?"under-100":o<250?"100-249":"250-plus":"missing"}function Fr({missingLabel:o="No value"}={}){return[{id:"missing",label:o,count:0},{id:"under-100",label:"Under $100",count:0},{id:"100-249",label:"$100-$249",count:0},{id:"250-plus",label:"$250+",count:0}]}function lo(o=[],x=3){const C=o.filter(Boolean);return C.length<=x?C.join(", "):`${C.slice(0,x).join(", ")} and ${C.length-x} more`}function lc({businessIdOverride:o=null,embedded:x=!1,brandingOverride:C=null}){var cr,dr,ur,mr;const{confirmAction:j,confirmDialog:M}=Hi(),{userDoc:d,clientData:f,loading:L}=qi(),{branding:Z}=Gi(),[h,T]=i.useState([]),[k,V]=i.useState(null),[P,p]=i.useState([]),[F,D]=i.useState({}),[Q,z]=i.useState(!0),[ee,l]=i.useState({}),[v,$]=i.useState({}),[U,O]=i.useState({}),[te,We]=i.useState({}),[Me,ht]=i.useState({}),[me,b]=i.useState({}),[R,oe]=i.useState({}),[Qt,oa]=i.useState({}),[es,ts]=i.useState({}),[He,Or]=i.useState({}),[qe,ft]=i.useState(""),Ge=i.useDeferredValue(qe),[he,ss]=i.useState("all"),[De,as]=i.useState(!1),[Ye,rs]=i.useState([]),[Je,is]=i.useState([]),[Xe,ns]=i.useState([]),[Ze,os]=i.useState([]),[Qe,ls]=i.useState([]),[et,cs]=i.useState([]),[tt,ds]=i.useState([]),[st,us]=i.useState([]),[at,ms]=i.useState([]),[bt,ps]=i.useState(!1),[zr,la]=i.useState(!1),[le,ca]=i.useState(!1),[G,da]=i.useState(!1),[yt,gs]=i.useState([]),[ua,ma]=i.useState(""),[pa,ga]=i.useState(!0),[xa,ha]=i.useState("any"),[xs,fa]=i.useState([]),[$e,rt]=i.useState(!1),[Rr,ba]=i.useState(!1),[ya,_r]=i.useState(null),[je,hs]=i.useState(null),[_,Ct]=i.useState(null),[fs,pe]=i.useState(""),[Kr,Ca]=i.useState(!1),[Vr,va]=i.useState(null),[ie,it]=i.useState(null),[ka,vt]=i.useState([]),[ja,bs]=i.useState(!1),[wa,Na]=i.useState(!1),[nt,kt]=i.useState(!1),[Sa,jt]=i.useState(""),we=i.useRef(new Map),[Wr,La]=i.useState(0),[w,wt]=i.useState(null),Pa=i.useRef(null),[Hr,ys]=i.useState(!1),[qr,Ia]=i.useState({}),[Gr,Aa]=i.useState([]),[Yr,Nt]=i.useState(!1),[Jr,Cs]=i.useState(""),[Xr,Zr]=i.useState(0),[Ea,St]=i.useState([]),[Qr,vs]=i.useState(!1),[ei,Ta]=i.useState([]),y=d==null?void 0:d.clientId,Ne=o||(d==null?void 0:d.businessId),N=!!Ne,ae=N?Ne:y,ks=N?"business":"client",W=zs(d==null?void 0:d.userType,"Client Admin"),js=!N&&Rs(d==null?void 0:d.userType,["Client Admin","Client Staff"]),se=!zs(d==null?void 0:d.userType,"Client Staff"),ws=Array.isArray((cr=d==null?void 0:d.catalogCategoryAccess)==null?void 0:cr.labs)?d.catalogCategoryAccess.labs.join("|"):null,Fa=i.useMemo(()=>Sn(d==null?void 0:d.userType,ws?ws.split("|"):null),[d==null?void 0:d.userType,ws]),Ma=String((f==null?void 0:f.model)||(k==null?void 0:k.model)||"").trim().toLowerCase()==="affiliate",Da=!N&&!Ma,ti=Da&&!x,$a=(k==null?void 0:k.platformBilling)||(f==null?void 0:f.platformBilling)||{},Ua=N||Ma||oo($a),Ue=Da&&!Ua,Ba=ti&&!!ae&&!Ua,si=h.length===0?"No labs are configured for this account yet.":"No labs are visible to patients yet. Enable labs and set patient pricing to preview them here.",ce=C||Z,ai=i.useMemo(()=>Yi(k||f),[k,f]),I=(ce==null?void 0:ce.accentColor)||(k==null?void 0:k.accentColor)||(k==null?void 0:k.primaryColor)||Ji,Oa=h.length===0&&W?"No approved labs are available in the catalog yet.":si,Ns=i.useMemo(()=>new Set(P.map(e=>e.id)),[P]),Ss=e=>(e==null?void 0:e.catalogEntryId)||(e==null?void 0:e.id)||(e==null?void 0:e.clientProductId)||null;i.useEffect(()=>{async function e(){if(!ae){z(!1);return}try{z(!0);let s={},r=[],a=[];if(N){const u=await rn(Bt,ae,{type:"lab"});s=u.business||{},r=u.products||[],a=u.catalogCategories||[]}else{const u=await kn(ae,{includeInactiveClientEntries:!0,includeIntegrationAvailable:!0,includeClientOwnedProducts:!0,skipFormCoverage:!0});s=u.client||{},r=u.products||[],a=u.catalogCategories||[]}const n=N?r:r.filter(u=>_e(u).id!=="pending_approval"),c={};V(s),T(n),p(a),n.forEach(u=>{c[`lab_${u.id}`]=u.showPatient!==void 0?u.showPatient:!0}),D(c),$(n.reduce((u,m)=>(u[m.id]=m.customerPrice!==null&&m.customerPrice!==void 0?String(m.customerPrice):m.defaultCustomerPrice!==null&&m.defaultCustomerPrice!==void 0?String(m.defaultCustomerPrice):"",u),{})),We(n.reduce((u,m)=>(m.displayName&&(u[m.id]=m.displayName),u),{})),ht(n.reduce((u,m)=>(m.displayDescription&&(u[m.id]=m.displayDescription),u),{})),b(n.reduce((u,m)=>(u[m.id]=m.displayImageUrl||"",u),{})),z(!1)}catch(s){console.error("Error fetching data:",s),g.error("Unable to load labs. Please try again."),z(!1)}}e()},[Xr,N,ae]),i.useEffect(()=>{let e=!1;if(!y||N){St([]),vs(!1);return}async function s(){try{vs(!0);const r=await yn(wr(Bt,"Clients",y,"Forms"));if(e)return;const a=r.docs.map(n=>({id:n.id,...n.data()})).filter(eo).sort((n,c)=>String(n.name||n.displayName||n.title||"").localeCompare(String(c.name||c.displayName||c.title||"")));St(a)}catch(r){e||(console.error("Unable to load client forms:",r),g.error("Unable to load client forms."),St([]))}finally{e||vs(!1)}}return s(),()=>{e=!0}},[y,N]),i.useEffect(()=>{if(!(!y||N))return gn(xn(wr(Bt,"Clients",y,"Products"),hn("type","==","lab")),e=>{T(s=>{const r=[...s];
1return e.docChanges().forEach(a=>{const n=r.findIndex(u=>u.id===a.doc.id||u.clientProductId===a.doc.id||u.catalogEntryId===a.doc.id);if(a.type==="removed"){n>=0&&r.splice(n,1);return}const c={id:a.doc.id,clientProductId:a.doc.id,...a.doc.data()};if(_e(c).id==="pending_approval"){n>=0&&r.splice(n,1);return}if(n>=0){const u=r[n];r[n]={...u,...c,...u.defaultCustomerPrice!==void 0?{defaultCustomerPrice:u.defaultCustomerPrice}:{},...u.platformLabCostCents!==void 0?{platformLabCostCents:u.platformLabCostCents}:{}}}else r.push(c)}),r})},e=>console.error("Unable to subscribe to client-created labs:",e))},[y,N]),i.useEffect(()=>{if(!y||N||!js){Aa([]),Nt(!1),Cs("");return}return Nt(!0),Cs(""),_n({ownerType:"client",scopeId:y,readOnly:zs(d==null?void 0:d.userType,"Client Staff"),onData:e=>{var s;Aa((((s=e.overview)==null?void 0:s.ownIntegrations)||[]).filter(r=>Kn(r)&&r.status==="active")),Nt(!1)},onError:e=>{console.error("Unable to load lab integrations.",e),Cs("Unable to load lab integrations."),Nt(!1)}})},[js,y,N,d==null?void 0:d.userType]);async function za(e,s,{successMessage:r}={}){if(!ae)return;const a=`lab_${e.id}`,n=s.status??(s.showPatient===!1?"inactive":"active"),c=s.showPatient??n==="active",u=e.status,m=F[a];l(S=>({...S,[a]:!0})),D(S=>({...S,[a]:c})),T(S=>S.map(B=>B.id===e.id?{...B,catalogEntryId:Ss(B)||B.id,status:n,showPatient:c}:B));try{if(!jr.currentUser)throw new Error("Not authenticated");await xe("setTenantLabFields",{lab:e,patch:{status:n,showPatient:c},...N?{businessId:Ne}:{clientId:y}}),r&&g.success(r)}catch(S){console.error("Error updating lab visibility:",S),g.error(S.message||"Unable to update settings. Please try again."),D(B=>({...B,[a]:m})),T(B=>B.map(q=>q.id===e.id?{...q,status:u,showPatient:m}:q))}finally{l(S=>({...S,[a]:!1}))}}function Ls(e,s){if(s&&Ue){g.error("Please update your account payment method to enable labs.");return}return za(e,no(s),{successMessage:`${de(e)} ${s?"activated":"deactivated"}`})}function Ps(e,s){return za(e,{status:"active",showPatient:s},{successMessage:`${de(e)} ${s?"shown on storefront":"hidden from storefront"}`})}function Ra(e,s){Or(r=>{const a=r[e];if(a!=null&&a.previewUrl&&URL.revokeObjectURL(a.previewUrl),!s){const n={...r};return delete n[e],n}return{...r,[e]:{file:s,previewUrl:URL.createObjectURL(s)}}})}const Is=i.useCallback(e=>Xt(v[e]),[v]);async function _a(e,s=null){var pr;const r=e.id,a=((s==null?void 0:s.displayName)??te[r]??"").toString().trim(),n=((s==null?void 0:s.displayDescription)??Me[r]??"").toString().trim(),c=((s==null?void 0:s.displayImageUrl)??me[r]??"").toString().trim(),u=(s==null?void 0:s.displayCategoryIds)??Es(e),m=(s==null?void 0:s.excludedStates)??Ts(e),S=(s==null?void 0:s.targetSex)??Fs(e),B=Array.isArray(s==null?void 0:s.biomarkers)?s.biomarkers.map(J=>String(J||"").trim()).filter(Boolean):re(e),q=nn(B),Ie=Mn(),Oe=se?s?Xt(s.customerPrice):Is(r):null;if(Oe===void 0){g.error("Enter a non-negative price with up to two decimal places.");return}const ct=s?s.imageFile:((pr=He[r])==null?void 0:pr.file)||null,ne=h.find(J=>J.id===r)||e,Di=re(ne);new Set(Di.map(J=>J.toLowerCase())),new Set(B.map(J=>J.toLowerCase()));const Os=Ie;if((ne.displayName||"")===a&&(ne.displayDescription||"")===n&&(ne.displayImageUrl||"")===c&&(!se||(ne.customerPrice??null)===(Oe??null))&&Ds(u,K(ne))&&Ms(m,Se(ne))&&S===ye(ne)&&!Os&&!ct){s&&Ct(null);return}O(J=>({...J,[r]:!0}));try{if(!jr.currentUser)throw new Error("Not authenticated");let Ut=c;if(ct){if(!Object.keys(Wt).includes(ct.type))throw new Error("Invalid file type");if(ct.size>Vt)throw new Error("File size exceeds 10MB");Ut=await Cr(ct,{scope:N?"business-products":"client-products",targetId:Ss(e)||r,tenantId:ae}),Ra(r,null)}const $i={displayName:a,displayDescription:n,displayImageUrl:Ut,...se?{customerPrice:Oe}:{},displayCategoryIds:u,...W?{excludedStates:m}:{},...W?{targetSex:S}:{},...Os?{biomarkers:B,markerNames:B,labTests:q,panels:[]}:{},status:ne.status||(ne.showPatient===!1?"inactive":"active"),showPatient:ne.showPatient!==!1};await xe("setTenantLabFields",{lab:e,patch:$i,...N?{businessId:Ne}:{clientId:y}}),T(X=>X.map(ze=>ze.id===r?{...ze,catalogEntryId:Ss(ze)||ze.id,displayName:a,displayDescription:n,displayImageUrl:Ut,...se?{customerPrice:Oe}:{},displayCategoryIds:u,...W?Nr(ze,m):{},...W?{targetSex:S}:{},...Os?{biomarkers:B,markerNames:B,labTests:q,labTestIds:q.map(Ui=>Ui.id),panels:[],markerCount:B.length}:{}}:ze)),We(X=>({...X,[r]:a})),ht(X=>({...X,[r]:n})),b(X=>({...X,[r]:Ut})),se&&$(X=>({...X,[r]:Oe==null?"":String(Oe)})),oe(X=>({...X,[r]:u})),oa(X=>({...X,[r]:m})),ts(X=>({...X,[r]:S})),Ct(null),g.success(`Updated lab info for ${de(e)}`)}catch(J){console.error("Error updating display info:",J),g.error(J.message||"Unable to update display info. Please try again.")}finally{O(J=>({...J,[r]:!1}))}}function Ka(e,s,r){if(r.length>0){g.error("Invalid file. Please upload a JPG, PNG, or WEBP under 10MB.");return}const a=s[0];a&&Ra(e,a)}function ri(e){_r(e),ba(!0)}const ot=i.useCallback(e=>{var s;return!!(((s=e==null?void 0:e.requirementSummary)==null?void 0:s.hasForms)===!0||Array.isArray(e==null?void 0:e.requiredFormIds)&&e.requiredFormIds.length>0||Array.isArray(e==null?void 0:e.forms)&&e.forms.length>0)},[]);
1function Va(e){const s=(te[e.id]||de(e,"")).trim(),r=(Me[e.id]||Hs(e)).trim(),a=(me[e.id]||e.displayImageUrl||"").trim(),n=Te(Y(e)),c=ot(e)?"Start Intake":"Order Lab";return t.jsx(Un,{className:"h-full",name:s||xt(e)||"Lab",price:n,description:r,imageUrl:a,imageBadgeLabel:Fn(e),turnaround:e.turnaroundTime,fasting:e.fastingRequired,sampleType:e.sampleType,collectionMethodLabel:Re(e),targetSex:e.targetSex,biomarkers:re(e),searchTerm:Ge,accentColor:I,actionLabel:c,actionKind:"order"})}const Wa=i.useCallback(e=>[dt(e),Re(e)].filter(Boolean).join(" "),[]),Y=i.useCallback(e=>{const s=v[e.id];return s!==void 0?s:e.customerPrice!==null&&e.customerPrice!==void 0?String(e.customerPrice):e.defaultCustomerPrice!==null&&e.defaultCustomerPrice!==void 0?String(e.defaultCustomerPrice):""},[v]),Ha=i.useCallback(e=>{const s=Number.parseFloat(Y(e));return Number.isFinite(s)?Te(s):"â"},[Y]),H=i.useCallback(e=>te[e.id]||de(e),[te]),fe=i.useCallback(e=>{var s;return((s=He[e.id])==null?void 0:s.previewUrl)||me[e.id]||e.displayImageUrl},[me,He]),As=i.useCallback(e=>!N&&(e==null?void 0:e.catalogScope)==="client",[N]),Lt=i.useCallback(e=>As(e)&&!(e!=null&&e.adoptedFrom),[As]),Pt=i.useCallback(e=>e!=null&&e.isDuplicate?"duplicate":Lt(e)?"client_created":"catalog",[Lt]),qa=!N&&Rs(d==null?void 0:d.userType,["Client Admin","Client Staff","Super Admin"]),It=!N&&Rs(d==null?void 0:d.userType,["Client Admin","Super Admin"]),Ga=i.useMemo(()=>{const e=new Map;return P.forEach(s=>{s!=null&&s.id&&(s.status||"active")==="active"&&e.set(s.id,s.name||"Category")}),e},[P]),Be=i.useCallback(e=>{const s=[];
1return(Array.isArray(e)?e:[]).forEach(r=>{const a=String(r||"").trim();a&&!s.includes(a)&&s.push(a)}),s},[]),K=i.useCallback(e=>{const s=new Set,r=[];return[e.displayCategoryIds,e.categories].forEach(a=>{(Array.isArray(a)?a:[]).forEach(n=>{const c=String(n||"").trim();c&&Ns.has(c)&&!s.has(c)&&(s.add(c),r.push(c))})}),r.length===0&&[e.categoryId,e.category,e.primaryCategory].forEach(a=>{const n=String(a||"").trim();n&&Ns.has(n)&&!s.has(n)&&(s.add(n),r.push(n))}),r},[Ns]),At=i.useCallback(e=>K(e).map(s=>Ga.get(s)).filter(Boolean),[Ga,K]),Es=i.useCallback(e=>R[e.id]!==void 0?Be(R[e.id]):K(e),[R,K,Be]),Se=i.useCallback(e=>Rt((e==null?void 0:e.tenantExcludedStates)??(e==null?void 0:e.excludedStates)),[]),Ts=i.useCallback(e=>Qt[e.id]!==void 0?Rt(Qt[e.id]):Se(e),[Qt,Se]),Fs=i.useCallback(e=>es[e.id]!==void 0?Xi(es[e.id]):ye(e),[es]),Ms=i.useCallback((e,s)=>{const r=Rt(e).sort(),a=Rt(s).sort();return r.length===a.length&&r.every((n,c)=>n===a[c])},[]),Ds=i.useCallback((e,s)=>{const r=Be(e),a=Be(s);return r.length===a.length&&r.every(n=>a.includes(n))},[Be]),ii=i.useMemo(()=>P.filter(e=>(e.status||"active")==="active").map(e=>({id:e.id,label:e.name||"Category",count:h.filter(s=>K(s).includes(e.id)).length})).sort((e,s)=>e.label.localeCompare(s.label)),[P,K,h]),Ya=i.useMemo(()=>{const e=new Map;return h.forEach(s=>{re(s).forEach(r=>e.set(r,(e.get(r)||0)+1))}),Array.from(e.entries()).sort(([s],[r])=>s.localeCompare(r)).map(([s,r])=>({id:s,label:s,count:r}))},[h]),ni=i.useMemo(()=>{const e=new Map;return h.forEach(s=>{const r=dt(s);r&&e.set(r,(e.get(r)||0)+1)}),Array.from(e.entries()).sort(([s],[r])=>s.localeCompare(r)).map(([s,r])=>({id:s,label:s,count:r}))},[h]),oi=i.useMemo(()=>{const e=new Map;return h.forEach(s=>{const r=Re(s);r&&e.set(r,(e.get(r)||0)+1)}),Array.from(e.entries()).sort(([s],[r])=>s.localeCompare(r)).map(([s,r])=>({id:s,label:s,count:r}))},[h]),li=i.useMemo(()=>{const e=new Map;return h.forEach(s=>{const r=ye(s);e.set(r,(e.get(r)||0)+1)}),Yt.map(s=>({id:s.value,label:s.label,count:e.get(s.value)||0}))},[h]),ci=i.useMemo(()=>{const e=Fr({missingLabel:"No price"});return h.forEach(s=>{const r=Number.parseFloat(Y(s)),a=e.find(n=>n.id===Ht(r));a&&(a.count+=1)}),e},[Y,h]),di=i.useMemo(()=>{const e=Fr({missingLabel:"No cost"});return h.forEach(s=>{const r=gt(s,f).totalCents/100,a=e.find(n=>n.id===Ht(r));a&&(a.count+=1)}),e},[f,h]),Ja=i.useMemo(()=>{const e=[{id:"catalog",label:"Catalog labs",count:0},{id:"client_created",label:"Client-created",count:0},{id:"duplicate",label:"Duplicates",count:0}];return h.forEach(s=>{const r=e.find(a=>a.id===Pt(s));r&&(r.count+=1)}),e.filter(s=>s.count>0)},[Pt,h]),Xa=i.useMemo(()=>{const e=[{id:"intake_forms",label:"Intake forms",count:0},{id:"no_intake_forms",label:"No intake forms",count:0},{id:"has_image",label:"Has image",count:0},{id:"missing_image",label:"Missing image",count:0},{id:"fasting",label:"Fasting",count:0}];return h.forEach(s=>{const r=ot(s),a=!!fe(s);r?e[0].count+=1:e[1].count+=1,a?e[2].count+=1:e[3].count+=1,s.fastingRequired===!0&&(e[4].count+=1)}),e.filter(s=>s.count>0)},[fe,h,ot]),ui=i.useCallback(e=>{var s,r,a;return(((s=te[e.id])==null?void 0:s.toString().trim())||"")!==(e.displayName||"")||(((r=Me[e.id])==null?void 0:r.toString().trim())||"")!==(e.displayDescription||"")||(((a=me[e.id])==null?void 0:a.toString().trim())||"")!==(e.displayImageUrl||"")||se&&(Is(e.id)??null)!==(e.customerPrice??null)||!Ds(Es(e),K(e))||W&&!Ms(Ts(e),Se(e))||W&&Fs(e)!==ye(e)||!!He[e.id]},[Ds,Me,me,te,Es,K,Ts,Se,Fs,He,se,W,Is,Ms]);function Za(e,s){const r=new Set(Array.isArray(e)?e:[e]),a=Object.prototype.hasOwnProperty.call(s,"excludedStates");T(n=>n.map(c=>{if(!r.has(c.id))return c;if(!a)return{...c,...s};const{excludedStates:u,...m}=s;return{...c,...m,...Nr(c,u)}}))}async function Et(e,s){await xe("setTenantLabFields",{lab:e,patch:s,...N?{businessId:Ne}:{clientId:y}}),Za(e.id,s)}async function mi(e,s){const r=Be(s??K(e));try{O(a=>({...a,[e.id]:!0})),await Et(e,{displayCategoryIds:r}),oe(a=>({...a,[e.id]:r})),pe(""),g.success("Categories updated")}catch(a){g.error(a.message||"Unable to update categories")}finally{O(a=>({...a,[e.id]:!1}))}}async function Qa(e,s){if(!se){g.error("You do not have permission to update lab pricing");return}const r=s??Y(e)??"",a=Xt(r);if(a===void 0){g.error("Enter a non-negative price with up to two decimal places.");return}if((e.customerPrice??null)!==(a??null))try{O(n=>({...n,[e.id]:!0})),await Et(e,{customerPrice:a}),$(n=>({...n,[e.id]:a==null?"":String(a)})),pe(""),g.success("Price updated")}catch(n){g.error(n.message||"Unable to update price")}finally{O(n=>({...n,[e.id]:!1}))}}async function pi(e,s){const r=String(s??"").trim();try{O(a=>({...a,[e.id]:!0})),await Et(e,{displayName:r}),We(a=>({...a,[e.id]:r})),pe(""),g.success("Name updated")}catch(a){g.error(a.message||"Unable to update name")}finally{O(a=>({...a,[e.id]:!1}))}}async function gi(e,s,r){if(!W||!y||!(e!=null&&e.id)||!(s!=null&&s.id))return;const a=`${e.id}:${s.id}`,n=Qn({form:s,lab:e,shouldPair:r});Ta(c=>[...new Set([...c,a])]);try{await In({clientId:y,formId:s.id,associations:n}),St(c=>c.map(u=>u.id===s.id?{...u,associations:n}:u)),g.success(r?"Form attached":"Form detached")}catch(c){console.error("Unable to update lab form pairing:",c),g.error(c.message||"Unable to update form pairing.")}finally{Ta(c=>c.filter(u=>
1u!==a))}}async function xi(e){if(!(N||!y||!e))try{O(c=>({...c,[e.id]:!0}));const r=(await xe("duplicateTenantLab",{lab:e,clientId:y})).newDocId,a=de(e),n={...e,id:r,catalogEntryId:r,clientProductId:r,couponEligibleClientProductId:r,isDuplicate:!0,storageModel:"scoped",status:"inactive",showPatient:!1,displayName:`${a} (Copy)`};T(c=>[...c,n]),D(c=>({...c,[`lab_${r}`]:!1})),g.success(`Duplicated ${a}`)}catch(s){console.error("Error duplicating lab:",s),g.error(s.message||"Unable to duplicate lab")}finally{O(s=>({...s,[e.id]:!1}))}}async function hi(e){if(N||!y||!(e!=null&&e.catalogEntryId))return;const s=de(e,"this duplicate");if(await j({title:`Delete "${s}"?`,description:"The duplicate lab and its pricing are deleted permanently. This cannot be undone.",confirmLabel:"Delete duplicate",tone:"destructive",confirmationText:s}))try{O(a=>({...a,[e.id]:!0})),await xe("deleteTenantLabDuplicate",{catalogEntryId:e.catalogEntryId,clientId:y}),T(a=>a.filter(n=>n.id!==e.id)),g.success("Duplicate removed")}catch(a){console.error("Error deleting duplicate lab:",a),g.error(a.message||"Unable to delete duplicate")}finally{O(a=>({...a,[e.id]:!1}))}}function fi(e){va(e),Ca(!0)}const bi=i.useCallback(async e=>{const s=br(e==null?void 0:e.productId)||br(e==null?void 0:e.id);if(!(!y||!s)){it({...e,rootLabId:s}),vt([]),bs(!1),Na(!0);try{const r=await fn(bn(Bt,"LabProductLinks",`${y}__${s}`));if(r.exists()){const a=r.data()||{};vt(Array.isArray(a.productIds)?a.productIds:[]),bs(!0)}else vt([]),bs(!1)}catch(r){console.error("Error loading linked products:",r),g.error("Unable to load linked products. Please try again.")}finally{Na(!1)}}},[y]);async function yi(){const e=ie==null?void 0:ie.rootLabId;if(!(!It||!y||!e))try{kt(!0),await xe("setClientLabAssociatedProducts",{clientId:y,labId:e,productIds:ka}),g.success("Linked products updated"),it(null)}catch(s){console.error("Error saving linked products:",s),g.error(s.message||"Unable to update linked products. Please try again.")}finally{kt(!1)}}async function Ci(){const e=ie==null?void 0:ie.rootLabId;if(!(!It||!y||!e))try{kt(!0),await xe("setClientLabAssociatedProducts",{clientId:y,labId:e,reset:!0}),g.success("Reverted to default linked products"),it(null)}catch(s){console.error("Error resetting linked products:",s),g.error(s.message||"Unable to reset linked products. Please try again.")}finally{kt(!1)}}function vi(e){gs(s=>s.includes(e)?s.filter(r=>r!==e):[...s,e])}function er(){ca(!1),gs([]),ma(""),ga(!0),ha("any"),fa([])}async function Le(e,s){const r=$s;if(r.length===0)return g.error("Select at least one lab"),!1;if(e.status==="active"&&Ue)return g.error("Please update your account payment method to enable labs."),!1;if(e.status==="active"){const a=r.filter(n=>_e(n).blocksActivation);if(a.length>0)return g.error(`Unavailable labs cannot be activated: ${lo(a.map(n=>de(n)))}. Clear them from the selection and try again.`),!1}try{rt(!0);const a=await xe("bulkSetTenantLab",{labs:r,patch:e,...N?{businessId:Ne}:{clientId:y}}),n=Array.isArray(a==null?void 0:a.failures)?a.failures:[],c=new Set(n.map(m=>(m==null?void 0:m.id)||(m==null?void 0:m.catalogEntryId)).filter(Boolean)),u=r.filter(m=>!c.has(m.id));return u.forEach(m=>Za(m.id,e)),e.showPatient!==void 0&&D(m=>{const S={...m};return u.forEach(B=>{S[`lab_${B.id}`]=e.showPatient}),S}),u.length>0&&g.success(`${s} for ${u.length} lab${u.length===1?"":"s"}`),n.length>0&&ki(n),n.length===0}catch(a){return g.error(a.message||"Unable to update selected labs"),!1}finally{rt(!1)}}function ki(e){const s=[];if(e.forEach(a=>{const n=String((a==null?void 0:a.error)||"").trim();n&&!s.includes(n)&&s.push(n)}),s.length===0){g.warning(`${e.length} lab${e.length===1?"":"s"} could not be updated.`);return}const r=s.length>3?` (+${s.length-3} more)`:"";g.warning(`${s.slice(0,3).join(" ")}${r}`,{duration:12e3})}const lt=i.useMemo(()=>h.filter(e=>{var n,c,u;const s=Ke(e),r=s&&e.showPatient!==!1;if(he==="active"&&!s||he==="inactive"&&s||De&&!r||!Fa(K(e))||Ye.length>0&&!Ye.some(m=>K(e).includes(m))||Je.length>0&&!Je.some(m=>re(e).includes(m))||Ze.length>
10&&!Ze.includes(dt(e))||Qe.length>0&&!Qe.includes(Re(e))||Xe.length>0&&!Xe.includes(ye(e))||st.length>0&&!st.includes(Pt(e)))return!1;if(at.length>0){const m=ot(e),S=!!fe(e);if(!at.some(q=>q==="intake_forms"?m:q==="no_intake_forms"?!m:q==="has_image"?S:q==="missing_image"?!S:q==="fasting"?e.fastingRequired===!0:!1))return!1}if(et.length>0){const m=gt(e,f).totalCents/100;if(!et.includes(Ht(m)))return!1}if(tt.length>0){const m=Number.parseFloat(Y(e));if(!tt.includes(Ht(m)))return!1}if(!Ge.trim())return!0;const a=Ge.toLowerCase();return de(e).toLowerCase().includes(a)||Hs(e).toLowerCase().includes(a)||xt(e).toLowerCase().includes(a)||Ur(e).toLowerCase().includes(a)||((n=e.displayName)==null?void 0:n.toLowerCase().includes(a))||((c=e.displayDescription)==null?void 0:c.toLowerCase().includes(a))||re(e).join(" ").toLowerCase().includes(a)||Wa(e).toLowerCase().includes(a)||((u=e.code)==null?void 0:u.toLowerCase().includes(a))||[e.id,e.clientProductId,e.catalogEntryId,e.productId,e.clientId,e.businessId,e.providerNetworkId].some(m=>String(m||"").toLowerCase().includes(a))}),[Ye,f,Qe,et,Xe,Ge,K,Wa,Pt,fe,Fa,h,at,st,ot,Je,Y,tt,he,De,Ze]),ji=i.useMemo(()=>lt.map(e=>({...e,biomarkerCount:re(e).length,categorySort:At(e).join(", "),displayNameSort:H(e)||"",panelCostSort:gt(e,f).totalCents/100,patientTotalSort:Number(Y(e)||0)})),[f,lt,H,At,Y]),{sortedData:ge,sortKey:wi,sortDirection:Ni,handleSort:Si}=Nn(ji,"displayNameSort","asc"),tr=i.useMemo(()=>new Set(yt),[yt]),$s=i.useMemo(()=>le?ge.filter(e=>tr.has(e.id)):lt,[le,lt,tr,ge]),Us=i.useMemo(()=>ge.filter(e=>{if(e.showPatient===!1)return!1;const s=Number.parseFloat(Y(e));return Number.isFinite(s)&&s>0}),[Y,ge]),Li=i.useMemo(()=>N||!k?!0:on(k),[k,N]),Pi=!N&&Li===!1,Ii="Set up a payment processor before patients can purchase this lab.";function Ai(){ss(e=>e==="all"?"active":e==="active"?"inactive":"all")}function Ei(e){rs(e||[])}function sr(e){oe(s=>({...s,[e.id]:K(e)})),oa(s=>({...s,[e.id]:Se(e)})),ts(s=>({...s,[e.id]:ye(e)})),Ct(e)}function ar(e){const s=Ke(e),r=s&&F[`lab_${e.id}`]!==!1,a=!!U[e.id],n=Lt(e);return[{id:"edit",label:"Edit details",onSelect:()=>sr(e)},{id:"preview",label:"Preview",onSelect:()=>ri(e)},qa&&e.clientProductId?{id:"send-to-patient",label:"Send to patient",disabled:e.status==="inactive",onSelect:()=>fi(e)}:null,It?{id:"linked-products",label:"Linked products",onSelect:()=>bi(e)}:null,!N&&!n&&!e.isDuplicate?{id:"duplicate",label:"Duplicate",disabled:a,onSelect:()=>xi(e)}:null,!N&&e.isDuplicate?{id:"delete-duplicate",label:"Delete this duplicate",danger:!0,onSelect:()=>hi(e)}:null,{id:"toggle-storefront",label:r?"Hide from storefront":"Show on storefront",disabled:!s||!!ee[`lab_${e.id}`],onSelect:()=>Ps(e,!r)},{id:"toggle-active",label:s?"Deactivate":"Activate",disabled:!!ee[`lab_${e.id}`]||!s&&Ue,onSelect:()=>Ls(e,!s)},ui(e)?{id:"save",label:a?"Savingâ¦":"Save changes",disabled:a,onSelect:()=>_a(e)}:null].filter(Boolean)}function Ti(e){const s=Ce(e)&&y?Ir({client:k,clientId:y,labClientProductId:Ce(e)}):"",r=Number.parseFloat(e==null?void 0:e.customerPrice);return Ke(e)?(e==null?void 0:e.hasActiveClientLabIntegration)!==!0?"Connect an active lab integration before sharing this lab.":!Number.isFinite(r)||r<=0?"Set a patient price above $0 before sharing this lab.":s?"":"Add this lab to the client catalog before sharing it.":"Activate this lab before sharing its checkout link."}const rr=i.useCallback(async e=>{const s=e==null?void 0:e.id,r=Sr(e);if(!s||!y||!Lr(e))return;const a=we.current.get(s);if(!((a==null?void 0:a.status)==="loading"||(a==null?void 0:a.status)==="ready")){we.current.set(s,{status:"loading",products:[],error:""}),La(n=>n+1);try{const n=await xe("getLabAssociatedProducts",{labProductId:r,clientId:y}),c=Array.isArray(n==null?void 0:n.products)?n.products:[];we.current.set(s,{status:"ready",products:c,error:""})}catch(n){we.current.set(s,{status:"error",products:[],error:(n==null?void 0:n.message)||Ee.availabilityLoadFailed})}finally{La(n=>n+1)}}},[y]),Tt=i.useCallback(async(e,s)=>{if(!_t(s))return;const r=Pr({client:k,clientId:y,labClientProductId:Ce(e),consultClientProductId:Ce(s)});if(!r){g.error("Unable to build the combined checkout link.");return}try{await navigator.clipboard.writeText(r);const a=Kt(e.id,ve.COMBINED,s.clientProductId);
1jt(a),g.success(`Combined checkout link for ${s.displayName||s.name||"product"} copied`),setTimeout(()=>jt(""),2e3)}catch{g.error("Unable to copy the combined checkout link.")}},[k,y]),Ft=i.useCallback((e,s)=>{if(!_t(s))return;const r=Pr({client:k,clientId:y,labClientProductId:Ce(e),consultClientProductId:Ce(s)});if(!r){g.error("Unable to open the combined checkout link.");return}window.open(r,"_blank","noopener,noreferrer")},[k,y]),Bs=i.useCallback((e,s,r={})=>{const a=we.current.get(e.id),{eligible:n}=ra((a==null?void 0:a.products)||[]),c=n.filter(_t);if(r.mode==="direct"&&r.product){const u=c.find(m=>m.clientProductId===r.product.clientProductId);if(!u){g.error("That consultation is no longer eligible for this link.");return}s==="copy"?Tt(e,u):Ft(e,u);return}if(c.length===1){s==="copy"?Tt(e,c[0]):Ft(e,c[0]);return}c.length>=2&&(Pa.current=r.triggerElement||null,wt({lab:e,intent:s,products:(a==null?void 0:a.products)||[],loading:(a==null?void 0:a.status)==="loading",error:(a==null?void 0:a.status)==="error"?a.error:""}))},[Tt,Ft]);i.useEffect(()=>{var s;if(!((s=w==null?void 0:w.lab)!=null&&s.id))return;const e=we.current.get(w.lab.id);e&&wt(r=>{var a;return!r||((a=r.lab)==null?void 0:a.id)!==w.lab.id?r:{...r,products:e.products||[],loading:e.status==="loading",error:e.status==="error"?e.error:""}})},[Wr,(dr=w==null?void 0:w.lab)==null?void 0:dr.id]);function Fi(e){var q;if(N||!ai.commerce)return[];const s=Ti(e),r=Ce(e)&&y?Ir({client:k,clientId:y,labClientProductId:Ce(e)}):"",a={id:ve.PAYMENT_FIRST,label:Ee.paymentFirst.label,description:s||Ee.paymentFirst.description,copied:Sa===Kt(e.id,ve.PAYMENT_FIRST),disabled:!!s,disabledTooltip:s||void 0,onCopy:async()=>{try{await navigator.clipboard.writeText(r),jt(Kt(e.id,ve.PAYMENT_FIRST)),g.success("Lab checkout URL copied to clipboard"),setTimeout(()=>jt(""),2e3)}catch{g.error("Unable to copy the lab checkout URL.")}},onOpen:()=>window.open(r,"_blank","noopener,noreferrer")};if(As(e)&&!Sr(e))return[a];const c=we.current.get(e.id);if(!Lr(e))return[a];if(!c||c.status==="loading")return[{id:ve.COMBINED,label:"Lab + consultation â loading",description:"Checking linked consultationsâ¦",loading:!0,disabled:!0},a];if(c.status==="error")return[{id:ve.COMBINED,label:"Lab + consultation â unavailable",description:Ee.availabilityLoadFailed,disabled:!0,disabledTooltip:Ee.availabilityLoadFailed},a];const{eligible:m}=ra(c.products||[]),S=Rn(m);return[{id:ve.COMBINED,label:S.label||"Lab + consultation",description:S.disabledTooltip||S.description,recommended:S.recommended===!0,requiresChoice:S.requiresChoice===!0,badges:S.badges||[],disabled:S.mode==="disabled"||!!s,disabledTooltip:s||S.disabledTooltip,copied:S.mode==="direct"&&Sa===Kt(e.id,ve.COMBINED,(q=S.product)==null?void 0:q.clientProductId),onChoose:({triggerElement:Ie}={})=>{Bs(e,"copy",{...S,triggerElement:Ie})},onCopy:({triggerElement:Ie}={})=>{Bs(e,"copy",{...S,triggerElement:Ie})},onOpen:({triggerElement:Ie}={})=>{Bs(e,"open",{...S,triggerElement:Ie})}},a]}const Mt=!!(qe.trim()||he!=="all"||De||Ye.length>0||Je.length>0||Ze.length>0||Qe.length>0||et.length>0||Xe.length>0||tt.length>0||st.length>0||at.length>0),ir={all:"All",active:"Active only",inactive:"Inactive only"},nr=[{id:"status",type:"custom",render:()=>t.jsx(A,{type:"button",variant:"outline",onClick:Ai,className:`h-8 rounded-full border px-3 text-xs ${he==="all"?"border-slate-200 bg-white text-slate-700 hover:bg-slate-50 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-300 dark:hover:bg-slate-700":"hover:brightness-95"}`,style:he!=="all"?{backgroundColor:Ot(I,.1),borderColor:Ot(I,.3),color:I}:void 0,"aria-label":`Status filter: ${ir[he]}. Click to cycle.`,children:ir[he]})},{id:"storefront",type:"custom",render:()=>t.jsx(A,{type:"button",variant:"outline",onClick:()=>as(e=>!e),className:`h-8 rounded-full border px-3 text-xs ${De?"hover:brightness-95":"border-border bg-card text-foreground hover:bg-muted"}`,style:De?{backgroundColor:Ot(I,.1),borderColor:Ot(I,.3),color:I}:void 0,"aria-pressed":De,children:"Storefront only"})},{id:"integrationLab",filters:ni,activeFilters:Ze,onFilterChange:e=>os(e||[]),multiSelect:!0,defaultLabel:"All labs",searchable:!0},{id:"categories",filters:ii,activeFilters:Ye,onFilterChange:Ei,multiSelect:!0,defaultLabel:"All categories"},{id:"cost",filters:di,activeFilters:et,onFilterChange:e=>cs(e||[]),multiSelect:!0,defaultLabel:"All costs"},{id:"price",filters:ci,activeFilters:tt,onFilterChange:e=>ds(e||[]),multiSelect:!0,defaultLabel:"All prices"},{id:"collectionMethod",filters:oi,activeFilters:Qe,onFilterChange:e=>ls(e||[]),multiSelect:!0,defaultLabel:"All methods"},{id:"markers",filters:Ya,activeFilters:Je,onFilterChange:e=>is(e||[]),multiSelect:!0,defaultLabel:"All markers",searchable:!0},{id:"targetSex",filters:li,activeFilters:Xe,onFilterChange:e=>ns(e||[]),multiSelect:!0,defaultLabel:"Target audience"},Ja.length>1&&{id:"source",filters:Ja,activeFilters:st,onFilterChange:e=>us(e||[]),multiSelect:!0,defaultLabel:"Source"},Xa.length>1&&{id:"setup",filters:Xa,activeFilters:at,onFilterChange:e=>ms(e||[]),multiSelect:!0,defaultLabel:"Setup"},{id:"bulk-toggle",type:"custom",className:"lab-table-mode-actions ml-auto",render:()=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(zt,{variant:le?"default":"outline",icon:t.jsx(Zi,{className:"size-3.5"}),label:le?"Cancel bulk":"Bulk",className:le?"text-white":"",style:le?{backgroundColor:I}:void 0,onClick:()=>{le?er():(ca(!0),ps(!1))},"aria-pressed":le}),t.jsx(zt,{variant:G?"default":"outline",icon:t.jsx(Yn,{className:"size-3.5"}),label:G?"Normal view":"Config view",className:G?"text-white":"",style:G?{backgroundColor:I}:void 0,onClick:()=>{da(e=>!e),ps(!1)},"aria-pressed":G})]})}
1].filter(Boolean),be=$s.length===0||$e,Pe="h-8 rounded-full px-3 text-xs max-lg:h-7 max-lg:!min-h-7 max-lg:px-2 max-lg:text-3xs",Dt="w-[min(20rem,calc(100vw-2rem))] rounded-xl border border-border bg-popover p-3 text-popover-foreground shadow-lg max-lg:p-2",or=le?t.jsx("div",{className:"rounded-xl border border-border bg-card p-3 max-lg:p-2",children:t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 max-lg:gap-1.5",children:[t.jsxs("p",{className:"text-xs font-medium text-muted-foreground max-lg:text-2xs",children:[$s.length," selected"]}),t.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 max-lg:w-full max-lg:flex-nowrap max-lg:justify-start max-lg:gap-1 max-lg:overflow-x-auto max-lg:pb-0.5 max-lg:[&>*]:shrink-0",children:[G?t.jsxs(ut,{children:[t.jsx(mt,{asChild:!0,children:t.jsx(A,{type:"button",variant:"outline",size:"sm",className:Pe,disabled:be,children:"Storefront"})}),t.jsx(pt,{className:Dt,align:"end",children:t.jsxs("div",{className:"space-y-3",children:[t.jsxs("label",{className:"flex items-center justify-between gap-3 rounded-lg border border-border bg-card px-3 py-2",children:[t.jsx("span",{className:"text-sm font-semibold",children:"Show on storefront"}),t.jsx(Ae,{checked:pa,onCheckedChange:e=>ga(e===!0),"aria-label":"Set selected labs to show on storefront"})]}),t.jsx(A,{type:"button",size:"sm",className:"w-full text-white",style:{backgroundColor:I},disabled:$e,onClick:()=>Le({showPatient:pa},"Storefront visibility updated"),children:"Apply"})]})})]}):t.jsxs(t.Fragment,{children:[t.jsxs(A,{type:"button",variant:"outline",size:"sm",className:Pe,disabled:be||Ue,onClick:()=>Le({status:"active",showPatient:!0},"Activated"),children:[$e?t.jsx(Ve,{size:"xs",className:"mr-2"}):null,"Activate"]}),t.jsx(A,{type:"button",variant:"outline",size:"sm",className:Pe,disabled:be,onClick:()=>Le({status:"inactive",showPatient:!1},"Deactivated"),children:"Deactivate"})]}),se?t.jsxs(ut,{children:[t.jsx(mt,{asChild:!0,children:t.jsx(A,{type:"button",variant:"outline",size:"sm",className:Pe,disabled:be,children:"Update price"})}),t.jsx(pt,{className:Dt,align:"end",children:t.jsxs("div",{className:"space-y-2",children:[t.jsx("p",{className:"text-sm font-semibold",children:"Update patient price"}),t.jsx(ke,{value:ua,onChange:e=>ma(e.target.value),placeholder:"0.00",inputMode:"decimal",className:"h-9"}),t.jsx(A,{type:"button",size:"sm",className:"w-full text-white",style:{backgroundColor:I},disabled:$e,onClick:()=>{const e=Number.parseFloat(String(ua).replace(/[^0-9.]/g,""));if(!Number.isFinite(e)){g.error("Enter a non-negative price with up to two decimal places.");return}Le({customerPrice:e},"Patient price updated")},children:"Apply"})]})})]}):null,t.jsxs(ut,{children:[t.jsx(mt,{asChild:!0,children:t.jsx(A,{type:"button",variant:"outline",size:"sm",className:Pe,disabled:be,children:"Set categories"})}),t.jsx(pt,{className:Dt,align:"end",children:t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"text-sm font-semibold",children:"Set categories"}),t.jsx("div",{className:"max-h-48 space-y-1 overflow-auto",children:P.some(e=>(e.status||"active")==="active")?P.filter(e=>(e.status||"active")==="active").map(e=>t.jsxs("label",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-muted",children:[t.jsx(Ae,{checked:xs.includes(e.id),onCheckedChange:()=>fa(s=>s.includes(e.id)?s.filter(r=>r!==e.id):[...s,e.id])}),t.jsx("span",{className:"truncate",children:e.name||"Category"})]},e.id)):t.jsx("p",{className:"text-xs text-muted-foreground",children:"No categories configured."})}),t.jsx(A,{type:"button",size:"sm",className:"w-full text-white",style:{backgroundColor:I},disabled:$e||xs.length===0,onClick:()=>Le({displayCategoryIds:xs},"Categories updated"),children:"Apply"})]})})]}),G&&W?t.jsxs(ut,{children:[t.jsx(mt,{asChild:!0,children:t.jsx(A,{type:"button",variant:"outline",size:"sm",className:Pe,disabled:be,children:"Set audience"})}),t.jsx(pt,{className:Dt,align:"end",children:t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"text-sm font-semibold",children:"Set audience"}),t.jsxs(Ys,{value:xa,onValueChange:ha,children:[t.jsx(Js,{"aria-label":"Audience for selected labs",children:t.jsx(Xs,{})}),t.jsx(Zs,{children:Yt.map(e=>t.jsx(Qs,{value:e.value,children:e.label},e.value))})]}),t.jsx(A,{type:"button",size:"sm",className:"w-full text-white",style:{backgroundColor:I},disabled:$e,onClick:()=>Le({targetSex:xa},"Audience updated"),children:"Apply"})]})})]}):null,G?null:t.jsx(Gt,{accept:Wt,multiple:!1,maxSize:Vt,disabled:be,onDrop:async(e,s)=>{if(s.length>0||!e[0]){g.error("Invalid file. Please upload a JPG, PNG, or WEBP under 10MB.");return}try{rt(!0);const r=await Cr(e[0],{scope:N?"business-products":"client-products",targetId:`${ae||"scope"}-bulk-labs-${Date.now()}`,tenantId:ae});rt(!1),await Le({displayImageUrl:r},"Image updated")}catch(r){rt(!1),g.error(r.message||"Unable to upload image")}},children:({getRootProps:e,getInputProps:s})=>t.jsxs(A,{type:"button",variant:"outline",size:"sm",...e(),className:Pe,disabled:be,children:[t.jsx("input",{...s()}),t.jsx(yr,{className:"mr-1.5 size-3.5"}),"Upload image"]})})]})]})}):null,lr=t.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 max-lg:flex-nowrap max-lg:gap-1 max-lg:[&>*]:shrink-0",children:[js?t.jsxs(A,{type:"button",size:"sm",onClick:()=>ys(!0),className:"h-8 rounded-full px-3 text-xs text-white",style:{backgroundColor:I},"data-testid":E("button","labs","client-create"),children:[t.jsx(Dr,{className:"mr-1.5 size-3.5"}),"Create Lab"]}):null,N?null:t.jsx(Ln,{products:h,categories:P,branding:ce,accentColor:I,userType:d==null?void 0:d.userType,clientId:y,clientExperienceConfig:f==null?void 0:f.experienceConfig,hoverRevealTrigger:!0}),t.jsx(zt,{icon:t.jsx(Qi,{className:"size-3.5"}),label:bt?"Table":"Storefront",expanded:bt,onClick:()=>ps(e=>{const s=!e;
1return s&&(da(!1),er()),s}),"aria-pressed":bt}),N?null:t.jsx(zt,{icon:t.jsx(en,{className:"size-3.5"}),label:"Categories",onClick:()=>la(!0)})]}),Mi=[le&&{id:"bulkSelect",header:t.jsx(Ae,{checked:ge.length>0&&ge.every(e=>yt.includes(e.id)),onCheckedChange:e=>{gs(e===!0?ge.map(s=>s.id):[])},"aria-label":"Select all labs"}),align:"center",minWidth:40,fixedWidth:!0,headerClassName:"px-0 max-lg:px-0",cellClassName:"px-0 max-lg:px-0",renderCell:e=>t.jsx("div",{className:"flex items-center justify-center","data-row-click-ignore":!0,children:t.jsx(Ae,{checked:yt.includes(e.id),onCheckedChange:()=>vi(e.id),"aria-label":`Select ${H(e)}`})}),skeletonClassName:"size-4"},G&&{id:"status",header:"Active",sortKey:"status",align:"center",minWidth:56,fixedWidth:!0,headerClassName:"px-1",cellClassName:"p-0",renderCell:e=>{const s=Ke(e),r=!!ee[`lab_${e.id}`],a=_e(e);return t.jsx("div",{className:"flex min-h-[76px] items-center justify-center","data-row-click-ignore":!0,children:t.jsx(Ae,{checked:s,onCheckedChange:n=>Ls(e,n===!0),disabled:r||a.blocksActivation||!s&&Ue,"aria-label":`${s?"Deactivate":"Activate"}: ${H(e)}`})})},skeletonClassName:"w-12"},G&&{id:"storefront",header:"Storefront",sortKey:"showPatient",align:"center",minWidth:80,fixedWidth:!0,headerClassName:"px-1",cellClassName:"p-0",renderCell:e=>{const s=Ke(e),r=s&&F[`lab_${e.id}`]!==!1,a=_e(e);return t.jsx("div",{className:"flex min-h-[76px] items-center justify-center","data-row-click-ignore":!0,children:t.jsx(Ae,{checked:r,onCheckedChange:n=>Ps(e,n===!0),disabled:!s||!!ee[`lab_${e.id}`]||a.blocksActivation,"aria-label":`${r?"Hide from storefront":"Show on storefront"}: ${H(e)}`})})},skeletonClassName:"w-12"},{id:"image",header:"Image",minWidth:72,renderCell:e=>t.jsx(Gt,{onDrop:(s,r)=>Ka(e.id,s,r),accept:Wt,maxFiles:1,maxSize:Vt,noClick:!0,noKeyboard:!0,children:({getRootProps:s,getInputProps:r,open:a})=>t.jsxs("div",{...s(),"data-row-click-ignore":!0,children:[t.jsx("input",{...r()}),t.jsx("button",{type:"button",onClick:n=>{n.stopPropagation(),fe(e)?hs(e):a()},className:"relative rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500","aria-label":fe(e)?`Preview image for ${H(e)}`:`Upload image for ${H(e)}`,"data-testid":E("dropzone","labs","image"),children:t.jsx(mn,{src:fe(e),alt:H(e),fallback:t.jsx(Jt,{className:"size-4"}),className:"size-10 rounded-lg max-lg:size-8"})})]})}),skeletonClassName:"size-10 rounded-lg"},{id:"name",header:"Name",sortKey:"displayNameSort",minWidth:200,csvValue:e=>H(e)||"â",renderCell:e=>{const s=`name-${e.id}`,r=H(e)||"â";return t.jsxs("div",{className:"flex min-w-0 items-start gap-1.5 max-lg:gap-1",children:[Pi?t.jsx(ea,{delayDuration:150,children:t.jsxs(ta,{children:[t.jsx(sa,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex shrink-0 items-center justify-center text-red-600 transition hover:text-red-700 dark:text-red-400 dark:hover:text-red-300","aria-label":"Payment processor missing",onClick:a=>a.stopPropagation(),"data-row-click-ignore":!0,children:t.jsx(tn,{className:"size-5 fill-red-600 stroke-white max-lg:size-4 dark:fill-red-500",strokeWidth:3})})}),t.jsx(aa,{side:"top",className:"max-w-xs text-xs",children:Ii})]})}):null,t.jsx("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5","data-row-click-ignore":!0,children:t.jsx(An,{open:fs===s,onOpenChange:a=>{pe(a?s:n=>n===s?"":n)},initialValue:H(e)||"",accentColor:I,saving:!!U[e.id],onSave:a=>pi(e,a),trigger:t.jsx(A,{type:"button",variant:"ghost",className:"h-auto min-h-0 w-full justify-start whitespace-normal rounded-none p-0 text-left text-sm font-medium leading-snug text-content-primary hover:bg-transparent hover:underline max-lg:min-h-0 max-lg:text-xs",onClick:a=>a.stopPropagation(),"data-row-click-ignore":!0,"aria-label":`Edit name for ${r}`,children:t.jsx("span",{className:"whitespace-normal break-words",children:t.jsx(cn,{text:r,highlight:Ge})})})})})]})},skeletonClassName:"w-36"},!G&&{id:"biomarkerCount",header:"Markers",sortKey:"biomarkerCount",minWidth:116,csvValue:e=>re(e),renderCell:e=>t.jsx(Vn,{markers:re(e)}),skeletonClassName:"w-20 rounded-full"},{id:"labVendor",header:"Lab",minWidth:140,csvValue:e=>dt(e)||"â",renderCell:e=>t.jsx("span",{className:"block truncate text-xs text-content-secondary",children:dt(e)||(Lt(e)?"Client-owned":"â")}),skeletonClassName:"w-24"},{id:"collectionMethod",header:"Method",minWidth:140,csvValue:e=>Re(e)||"â",renderCell:e=>t.jsx("span",{className:"block truncate text-xs text-content-secondary",children:Re(e)||"â"}),skeletonClassName:"w-24"},{id:"targetSex",header:"Target Audience",sortKey:"targetSex",minWidth:132,csvValue:e=>vr(e),renderCell:e=>G?t.jsx("div",{className:"px-1","data-row-click-ignore":!0,children:t.jsxs(Ys,{value:ye(e),disabled:!W||!!U[e.id],onValueChange:async s=>{try{O(r=>({...r,[e.id]:!0})),await Et(e,{targetSex:s}),ts(r=>({...r,[e.id]:s})),g.success("Audience updated")}catch(r){g.error(r.message||"Unable to update audience")}finally{O(r=>({...r,[e.id]:!1}))}},children:[t.jsx(Js,{className:"h-8 min-w-28 text-xs","aria-label":`Audience for ${H(e)}`,children:t.jsx(Xs,{})}),t.jsx(Zs,{children:Yt.map(s=>t.jsx(Qs,{value:s.value,children:s.label},s.value))})]})}):t.jsx("span",{className:"block truncate text-xs text-content-secondary",children:vr(e)}),skeletonClassName:"w-16"},{id:"categorySort",header:"Category",sortKey:"categorySort",minWidth:140,hideOnMobile:!0,csvValue:e=>At(e).join(", "),renderCell:e=>{const s=At(e),r=`category-${e.id}`;return t.jsx("div",{"data-row-click-ignore":!0,children:t.jsx(En,{open:fs===r,onOpenChange:a=>{pe(a?r:n=>n===r?"":n)},initialCategoryIds:K(e),categories:P,accentColor:I,saving:!!U[e.id],onSave:a=>mi(e,a),trigger:t.jsxs("button",{type:"button",className:"flex max-w-full flex-wrap gap-1 rounded-md p-1 text-left hover:bg-slate-50 dark:hover:bg-slate-700/50",onClick:a=>a.stopPropagation(),"data-row-click-ignore":!0,children:[s.length>0?s.slice(0,2).map(a=>t.jsx(qt,{variant:"outline",className:"max-w-[140px] truncate rounded-full border-subtle bg-surface-sunken px-2 py-0.5 text-xs text-content-secondary max-lg:px-1.5",children:a},`${e.id}-${a}`)):t.jsx("span",{className:"text-xs text-slate-400 max-lg:text-3xs dark:text-slate-500",children:"â"}),s.length>2?t.jsxs(qt,{variant:"outline",className:"rounded-full border-subtle bg-surface-sunken px-2 py-0.5 text-xs text-content-secondary max-lg:px-1.5",children:["+",s.length-2]}):null]})})})},skeletonClassName:"w-24"},G&&!N&&{id:"forms",header:"Forms",minWidth:112,align:"center",csvValue:e=>Ea.filter(s=>ia(s,e,K(e))!=="none").length,renderCell:e=>{const s=`${e.id}:`,r=ei.filter(a=>a.startsWith(s)).map(a=>a.slice(s.length));return t.jsx("div",{className:"flex min-h-[76px] items-center justify-center","data-row-click-ignore":!0,children:t.jsx(to,{lab:e,categoryIds:K(e),forms:Ea,loading:Qr,canEdit:W,savingFormIds:r,onToggle:(a,n)=>gi(e,a,n)})})},skeletonClassName:"w-16 rounded-full"},!G&&{id:"panelCost",header:"Cost",sortKey:"panelCostSort",minWidth:104,hideOnTablet:!0,csvValue:e=>Te(gt(e,f).totalCents/100)||"â",renderCell:e=>t.jsx($n,{lab:e,tenant:f}),skeletonClassName:"w-16"},{id:"price",cellClassName:"text-metric",align:"right",header:"Patient Price",sortKey:"patientTotalSort",minWidth:130,csvValue:e=>Ha(e),renderCell:e=>{const s=`price-${e.id}`,r=Ha(e);return G?t.jsx("div",{className:"flex min-h-[76px] items-center justify-end px-1","data-row-click-ignore":!0,children:t.jsx(ke,{defaultValue:Y(e),placeholder:"0.00",inputMode:"decimal",disabled:!se||!!U[e.id],onClick:a=>a.stopPropagation(),onKeyDown:a=>{a.key==="Enter"&&a.currentTarget.blur()},onBlur:a=>Qa(e,a.currentTarget.value),className:"h-8 w-[5.25rem] rounded-md px-2 text-right text-xs max-lg:h-7 max-lg:w-[4.25rem] max-lg:px-1.5","aria-label":`Patient price for ${H(e)}`},`config-price-${e.id}-${Y(e)}`)}):se?t.jsx("div",{"data-row-click-ignore":!0,children:t.jsx(Tn,{open:fs===s,onOpenChange:a=>{pe(a?s:n=>n===s?"":n)},initialValue:Y(e),accentColor:I,saving:!!U[e.id],onSave:a=>Qa(e,a),trigger:t.jsx("button",{type:"button",className:"rounded-md px-2 py-1 text-left hover:bg-slate-50 max-lg:px-1.5 max-lg:py-0.5 dark:hover:bg-slate-700/50",onClick:a=>a.stopPropagation(),"data-row-click-ignore":!0,children:t.jsx("span",{className:"block text-sm font-medium text-content-primary max-lg:text-2xs",children:r})})})}):t.jsx("span",{className:"px-2 py-1 text-sm font-medium text-content-primary max-lg:px-1.5 max-lg:py-0.5 max-lg:text-2xs",children:r})},skeletonClassName:"w-16"},{id:"actions",header:"Actions",align:"center",minWidth:80,renderCell:e=>{const s=H(e);return t.jsxs("div",{className:"flex items-center justify-center gap-1",children:[t.jsx(ln,{actions:Fi(e),label:`Checkout link for ${s}`,testId:E("menu","labs",`links-${e.id}`),onOpen:()=>rr(e)}),t.jsx(pn,{actions:ar(e),label:`Open actions for ${s}`,testId:E("menu","labs",`row-${e.id}`)})]})},skeletonClassName:"w-7 rounded-md"}
1].filter(Boolean),$t=L||Q;return t.jsxs("div",{className:x?"space-y-4 max-lg:space-y-2.5":"app-page-shell space-y-4 max-lg:space-y-3 sm:space-y-6","data-testid":E("page","labs",x?"embedded":"client-admin"),"aria-label":"Client admin labs",children:[t.jsx(sn,{headerId:"labs-client",titleClassName:"max-lg:truncate"}),!ae&&!$t?t.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-6 max-lg:p-3 dark:border-red-800 dark:bg-red-900/20",children:[t.jsxs("h3",{className:"font-semibold text-red-900 max-lg:text-sm dark:text-red-200",children:["No ",ks[0].toUpperCase()+ks.slice(1)," Assigned"]}),t.jsxs("p",{className:"mt-1 text-sm text-red-700 max-lg:text-xs dark:text-red-300",children:["You must be assigned to a ",ks," to manage labs."]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2 max-lg:space-y-1.5",children:[Ba?t.jsx(vn,{entityType:"client",entityId:ae,platformBilling:$a,variant:"labs",accentColor:I}):null,bt?t.jsx(dn,{id:"labs-client-labs",title:"Labs",icon:Jt,accentColor:I,actions:lr,filteredCount:Us.length,totalCount:h.length,search:{placeholder:"Search labsâ¦",value:qe,onChange:ft,testId:E("input","labs","client-search")},filters:nr,hasActiveFilters:Mt,headerExtra:or,onClearFilters:()=>{ft(""),ss("all"),as(!1),rs([]),is([]),os([]),ls([]),cs([]),ns([]),ds([]),us([]),ms([])},loading:$t,bodyClassName:"bg-surface-raised p-4",children:$t?t.jsx("div",{className:"grid gap-4 max-lg:gap-2.5 sm:grid-cols-2 min-[1025px]:grid-cols-3 xl:grid-cols-4",children:Array.from({length:6}).map((e,s)=>t.jsx(Zt,{className:"h-80 rounded-2xl max-lg:h-64"},`storefront-skeleton-${s}`))}):Us.length>0?t.jsx("div",{className:"grid gap-4 max-lg:gap-2.5 sm:grid-cols-2 min-[1025px]:grid-cols-3 xl:grid-cols-4",children:Us.map(e=>t.jsx("div",{"data-testid":E("row","labs",`storefront-${e.id}`),children:Va(e)},e.id))}):t.jsxs("div",{className:"rounded-xl border border-dashed border-subtle p-10 text-center max-lg:p-5",children:[t.jsx("p",{className:"text-sm font-medium text-content-primary max-lg:text-xs",children:"No patient-visible labs"}),Mt?t.jsx("p",{className:"mt-1 text-sm text-content-tertiary max-lg:text-2xs",children:"No labs match the current filters."}):t.jsx("div",{className:"mt-1 text-sm text-content-tertiary max-lg:text-2xs",children:Oa})]})}):t.jsx(un,{id:"labs-client-labs",title:"Labs",className:Ba?"rounded-t-none border-t-0":"",icon:Jt,accentColor:I,actions:lr,filteredCount:lt.length,totalCount:h.length,search:{placeholder:"Search labsâ¦",value:qe,onChange:ft,testId:E("input","labs","client-search")},filters:nr,hasActiveFilters:Mt,headerExtra:or,onClearFilters:()=>{ft(""),ss("all"),as(!1),rs([]),is([]),os([]),ls([]),cs([]),ns([]),ds([]),us([]),ms([])},mobileList:{title:"name",meta:"categorySort",actions:"actions",fields:["price","biomarkerCount"]},columns:Mi,rows:ge,csvExport:{feature:"labs",tenantSlug:(f==null?void 0:f.name)||(k==null?void 0:k.name),rawExport:{getRows:()=>Cn(ge,h)},allData:{mode:"client",getRows:()=>h},hoverRevealTrigger:!0},rowClick:sr,rowClassName:e=>e.showPatient===!1?"opacity-60":"",rowTestId:e=>E("row","labs",e.id),contextMenuActions:e=>ar(e),loading:$t,skeletonRowCount:6,emptyMessage:qe.trim()?"No labs match your search.":Mt?"No labs match the current filters.":Oa,tableLabel:"Client labs table",tableTestId:E("table","labs","client-list"),sortKey:wi,sortDirection:Ni,onSort:Si,maxHeight:x?"420px":"min(calc(100dvh - 12rem), 960px)",pageScroll:!x,virtualized:!0,virtualRowHeight:76,virtualUseFixedRowHeight:!1})]}),t.jsx(_s,{open:Rr,onOpenChange:ba,children:t.jsxs(Ks,{className:"max-h-[calc(100dvh-2rem)] w-full max-w-[min(100vw-2rem,42rem)] overflow-x-hidden overflow-y-auto max-lg:p-3","aria-label":"Lab preview","data-testid":E("dialog","labs","preview"),children:[t.jsx(Vs,{children:t.jsx(Ws,{children:"Lab Preview"})}),ya&&t.jsx("div",{className:"mt-4 min-w-0 max-w-full overflow-x-hidden max-lg:mt-2.5",children:Va(ya)})]})}),t.jsx(na,{open:Hr,onOpenChange:e=>{ys(e),e||Ia({})},title:"Create lab",description:"Add a lab to the client catalog.",size:"xl",mobileFullHeight:!0,mobileStickyHeader:!0,contentTestId:E("dialog","labs","client-create"),...qr,children:t.jsx(Dn,{product:null,onClose:()=>{ys(!1),Zr(e=>e+1)},categories:P,integrations:Gr,integrationsLoading:Yr,integrationsError:Jr,setDialogProps:Ia,accentColor:I,backgroundColor:ce==null?void 0:ce.backgroundColor,canEditPrice:se,canEditTargetSex:W,canEditAssociatedProducts:W,showPlatformBillingFields:!1,allowStateExclusions:!1,billingTenant:k||f})}),_?t.jsx(io,{lab:_,initialValues:{displayName:de(_,""),displayDescription:Hs(_),customerPrice:String(_.customerPrice??_.defaultCustomerPrice??""),displayImageUrl:_.displayImageUrl||"",displayCategoryIds:K(_),excludedStates:Se(_),targetSex:ye(_),biomarkers:re(_)},availableMarkers:Ya.map(e=>e.label),headerRight:_?(()=>{const e=h.find(n=>n.id===_.id)||_,s=Ke(e),r=s&&F[`lab_${_.id}`]!==!1,a=_e(e);return t.jsxs("div",{className:"flex flex-wrap items-center gap-2 max-lg:flex-nowrap max-lg:gap-1 max-lg:[&>*]:shrink-0",children:[a.label&&!["active","ready_to_activate"].includes(a.id)?t.jsx(qt,{variant:"outline",className:`rounded-full px-2 py-1 text-3xs ${Zn(a.id)}`,children:a.label}):null,t.jsxs("label",{className:"flex items-center gap-2 rounded-full border border-subtle bg-surface-raised px-3 py-1.5 max-lg:gap-1.5 max-lg:px-2 max-lg:py-1",children:[t.jsx("span",{className:"text-xs font-medium text-slate-700 max-lg:text-3xs dark:text-slate-300",children:"Active"}),t.jsx(kr,{checked:s,onCheckedChange:n=>Ls(e,n),disabled:a.blocksActivation||!s&&Ue,className:"data-[state=checked]:bg-[var(--switch-checked)]",style:{"--switch-checked":I},"aria-label":"Lab active"})]}),t.jsxs("div",{className:"flex items-center gap-2 rounded-full border border-subtle bg-surface-raised px-3 py-1.5 max-lg:gap-1.5 max-lg:px-2 max-lg:py-1",children:[t.jsx("span",{className:`text-xs font-medium max-lg:text-3xs ${s?"text-slate-700 dark:text-slate-300":"text-slate-400 dark:text-slate-500"}`,children:"Storefront"}),t.jsx(ea,{delayDuration:150,children:t.jsxs(ta,{children:[t.jsx(sa,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex size-4 items-center justify-center rounded-full text-slate-400 hover:text-slate-600 dar
1k:text-slate-500 dark:hover:text-slate-300","aria-label":"Storefront and dashboard visibility help",children:t.jsx($r,{className:"size-3.5"})})}),t.jsx(aa,{side:"bottom",className:"max-w-xs text-xs",children:"Storefront makes this lab available in Labs. Labs cannot be added with Dashboard HTML; use Send to Patient to create a patient Dashboard action."})]})}),t.jsx(kr,{checked:r,onCheckedChange:n=>Ps(e,n),disabled:!s||a.blocksActivation,className:"data-[state=checked]:bg-[var(--switch-checked)]",style:{"--switch-checked":I},"aria-label":"Show lab on storefront"})]})]})})():null,categories:P,clientId:y,clientData:f,accentColor:I,canEditLabPricing:se,isClientAdmin:W,saving:!!U[_.id],onClose:()=>Ct(null),onSave:e=>_a(_,e)},_.id):null,t.jsx(_s,{open:!!je,onOpenChange:e=>{e||hs(null)},children:t.jsxs(Ks,{className:"max-h-[calc(100dvh-2rem)] w-full max-w-[min(100vw-2rem,56rem)] gap-0 overflow-hidden p-0","aria-label":"Lab image preview","data-testid":E("dialog","labs","image-preview"),children:[t.jsx(Vs,{className:"sr-only",children:t.jsx(Ws,{children:je&&H(je)||"Lab image"})}),je?t.jsxs("div",{className:"relative bg-slate-950",children:[t.jsx("div",{className:"flex max-h-[calc(100dvh-6rem)] min-h-[18rem] items-center justify-center",children:t.jsx("img",{src:fe(je),alt:H(je)||"Lab image",className:"max-h-[calc(100dvh-6rem)] w-full object-contain"})}),t.jsx("div",{className:"absolute bottom-3 right-3",children:t.jsx(Gt,{onDrop:(e,s)=>{Ka(je.id,e,s),hs(null)},accept:Wt,maxFiles:1,maxSize:Vt,noClick:!0,noKeyboard:!0,children:({getRootProps:e,getInputProps:s,open:r})=>t.jsxs("div",{...e(),children:[t.jsx("input",{...s()}),t.jsxs(A,{type:"button",variant:"outline",size:"sm",className:"rounded-full",onClick:r,children:[t.jsx(yr,{className:"mr-1.5 size-3.5"}),"Replace"]})]})})})]}):null]})}),t.jsx(Xn,{open:!!w,onOpenChange:e=>{e||wt(null)},labName:((ur=w==null?void 0:w.lab)==null?void 0:ur.displayName)||((mr=w==null?void 0:w.lab)==null?void 0:mr.name)||"Lab",intent:(w==null?void 0:w.intent)||"copy",products:(w==null?void 0:w.products)||[],loading:(w==null?void 0:w.loading)===!0,error:(w==null?void 0:w.error)||"",accentColor:I,returnFocusRef:Pa,onRetry:()=>{w!=null&&w.lab&&rr(w.lab)},onSelectProduct:(e,s)=>{w!=null&&w.lab&&_t(e)&&(s==="open"?Ft(w.lab,e):Tt(w.lab,e),wt(null))}}),qa?t.jsx(jn,{open:Kr,onClose:()=>{Ca(!1),va(null)},product:Vr,clientId:y,variant:"lab",accentColor:I}):null,It?t.jsx(_s,{open:!!ie,onOpenChange:e=>{e||it(null)},children:t.jsxs(Ks,{className:"max-h-[calc(100dvh-2rem)] w-full max-w-[min(100vw-2rem,40rem)] overflow-y-auto p-0","aria-label":"Linked products","data-testid":E("dialog","labs","client-linked-products"),children:[t.jsx(Vs,{className:"px-5 pt-5 max-lg:px-3 max-lg:pt-3 sm:px-6",children:t.jsxs(Ws,{children:["Linked products",ie!=null&&ie.name?` â ${ie.name}`:""]})}),t.jsx("p",{className:"px-5 text-xs text-content-tertiary max-lg:px-3 max-lg:text-2xs sm:px-6",children:ja?"This client overrides the linked follow-on products for this lab.":"Using the network or default linked products. Saving creates a client-specific override."}),wa?t.jsxs("p",{className:"flex items-center gap-2 px-5 py-6 text-sm text-content-tertiary max-lg:px-3 max-lg:py-4 max-lg:text-xs sm:px-6",children:[t.jsx(Ve,{size:"md"}),"Loading linked products..."]}):t.jsx(wn,{value:ka,onChange:vt,disabled:nt,clientId:y}),t.jsxs(an,{className:"flex-col-reverse gap-2 px-5 pb-5 max-lg:gap-1.5 max-lg:px-3 max-lg:pb-3 sm:flex-row sm:justify-between sm:px-6",children:[t.jsx("div",{children:ja?t.jsx(A,{type:"button",variant:"ghost",onClick:Ci,disabled:nt,children:"Reset to default"}):null}),t.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row",children:[t.jsx(A,{type:"button",variant:"outline",onClick:()=>it(null),disabled:nt,children:"Cancel"}),t.jsxs(A,{type:"button",onClick:yi,disabled:nt||wa,className:"text-white",style:{backgroundColor:I},"data-testid":E("button","labs","client-linked-products-save"),children:[nt?t.jsx(Ve,{size:"md",className:"mr-2"}):null,"Save"]})]})]})]})}):null,t.jsx(Pn,{open:zr,onOpenChange:la,scopeId:ae,isBusinessTenant:N,clientId:y,businessId:Ne,accentColor:I,onCategoriesChanged:p,canManage:W,exportTenantSlug:ce==null?void 0:ce.businessName})]}),M]})}export{lc as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.