1import{j as e,r as o}from"./react-vendor-CU6Sz31W.js";import{mF as dt,df as fs,fL as bs,f2 as gs,gL as Mt,ah as Ss,h2 as Ns,c7 as ys,c8 as js,c9 as vs,ca as Ts,cb as ks,i7 as ut,ae as we,af as Ee,i as B,bY as Vt,ag as Ae,bZ as Bt,b_ as zt,b$ as Dt,a0 as qe,c0 as Yt,c1 as Gt,c2 as at,aQ as nt,at as Cs,bN as mt,bO as pt,bP as xt,aY as Is,e as ie,bQ as ht,dQ as Ps,dR as ws,dV as Es,dg as As,dd as Kt,cd as Qt,cW as Rs,cr as Ls,I as Wt,E as yt,al as Ht,b as Xt,u as ft,bg as tt,b2 as _s,gs as Os,ak as Fs,a3 as Us,S as $s,ax as qs,c6 as _e,g9 as M,ms as Ms,kI as Vs,kJ as Bs,d as Jt,ce as bt,l7 as jt,he as vt,ka as zs,aD as Ds,t as V,C as Ys,dv as Zt,a2 as es,dX as Gs,s$ as Ks,dY as Tt}from"./index-DEXJEDAi.js";import{B as Qs}from"./BusinessPageHeader-GNMgWFy7.js";import"./calendar-RV2oTCrW.js";import{a as Ws}from"./DataTableCard-BluwWKn_.js";import"./ExportCsvAction-BJr9eiP6.js";import{a as Hs}from"./localTableUtils-D6jRZlmf.js";import{a as be,b as Xs}from"./filterDescriptorUtils-NUS9ISaN.js";import"./patient-name-link-BAfQKbEs.js";import{T as kt}from"./text-highlight-BFqqfcjs.js";import{F as ts,G as Ie,H as it,I as Oe,J as Js,K as ss,L as Zs,N as er,g as lt,m as tr,k as sr,i as gt,f as Me,M as Ct,h as rs,d as as,e as rr,b as ns,n as Ne,S as ar,C as nr,j as It,l as Pt,O as ir,P as lr,Q as or,R as cr,p as dr,A as ur,v as Fe,B as mr,T as pr,U as xr}from"./SupportSeverityIcon-BUAxKUiE.js";import{a as wt}from"./supportTicketTableNavigation-DxmgNJHU.js";import{M as hr,m as fr}from"./modal-form-CqN5DZuv.js";import{S as br}from"./SupportAttachmentDropzone-j9pVKAmB.js";import{B as gr,u as Sr,S as Nr,a as yr}from"./SupportRelatedGuidesPanel-DUBMqjg3.js";import{U as is}from"./user-cog-Dx6cbGGN.js";import{u as jr}from"./usePatientTerminology-D5bkkKg2.js";import{u as vr}from"./usePatientTypesenseSearch-245dVN16.js";import{S as Tr,O as Et,a as kr,o as Cr}from"./SupportRecipientCards-Dv84hxQb.js";import{m as Ir,o as Pr,n as wr}from"./editorHtmlToMarkdown-CzTs4scD.js";import{A as At,T as Er}from"./cells-Db2ZEFlu.js";import{A as Ar}from"./arrow-up-right-DG_mPx_g.js";import{R as Rr}from"./RoutePageHeader-9W0v4VlT.js";import"./firebase-w6DYUbFN.js";import"./payment-icons-Daq1K3F1.js";import"./RoutePageTitle-D_8Od-sv.js";import"./addWeeks-1hrFjz19.js";import"./index-BSuGcRaZ.js";import"./table-CxPdvV_9.js";import"./arrow-up-D6DFVL4j.js";import"./arrow-down-BjUlbB4f.js";import"./pill-filter-CtZSNPVl.js";import"./date-picker-filter-Qp1kqu9t.js";import"./clear-filters-button-DmPemFGr.js";import"./modal-option-cards-Dksohkou.js";import"./editor-D8UbQKN1.js";import"./markdownToEditorHtml-CEcC5rdd.js";import"./list-ordered-GNrnoOhB.js";import"./strikethrough-CiKozLGy.js";import"./link-2-a8lhpkQ6.js";import"./minus-Du80G9MU.js";import"./ellipsis-vertical-C-dQ6Kzj.js";import"./RoutePageHeaderContent-FkxdZGox.js";const ls={Truck:Ns,FileText:Ss,Pill:Mt,Stethoscope:gs,FlaskConical:bs,CreditCard:fs,UserCog:is,Bug:gr,MessageCircle:dt};function Lr({value:t,onSelect:r,disabled:n,categories:a=ts}){return e.jsxs(ys,{value:t||void 0,onValueChange:r,disabled:n,children:[e.jsx(js,{className:"w-full",children:e.jsx(vs,{placeholder:"Select a topic"})}),e.jsx(Ts,{children:a.map(l=>{const d=ls[l.icon]||dt;return e.jsx(ks,{value:l.value,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(d,{className:"size-4 shrink-0 text-slate-400 dark:text-slate-500"}),e.jsx("span",{className:"text-content-primary",children:l.label})]})},l.value)})})]})}function _r({value:t,onSelect:r,disabled:n,accentColor:a,compact:l,categories:d=ts}){return l?e.jsx(Lr,{value:t,onSelect:r,disabled:n,categories:d}):e.jsx("div",{className:"grid gap-3 max-lg:gap-2 sm:grid-cols-2",children:d.map(u=>{const m=ls[u.icon]||dt,p=t===u.value;return e.jsxs("button",{type:"button",onClick:()=>r==null?void 0:r(u.value),disabled:n,"aria-pressed":p,className:`flex items-start gap-3 rounded-xl border px-4 py-4 text-left transition-colors max-lg:gap-2 max-lg:px-2.5 max-lg:py-2.5 ${p?"border-blue-500 bg-blue-50 dark:border-blue-400 dark:bg-blue-900/20":"border-slate-200 bg-white hover:border-slate-300 dark:border-slate-700 dark:bg-slate-900 dark:hover:border-slate-600"} ${n?"cursor-not-allowed opacity-70":"cursor-pointer"}`,style:p&&a?{borderColor:a}:void 0,children:[e.jsx("span",{className:`mt-0.5 shrink-0 ${p?"text-blue-600 dar
1k:text-blue-300":"text-slate-400 dark:text-slate-500"}`,children:e.jsx(m,{className:"size-5 max-lg:size-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"text-sm font-semibold text-content-primary max-lg:text-xs",children:u.label}),e.jsx("span",{className:"mt-1 block text-xs leading-relaxed text-content-secondary max-lg:mt-0.5 max-lg:text-2xs max-lg:leading-snug",children:u.description})]})]},u.value)})})}function Or(t){return t&&([t.firstName,t.lastName].filter(Boolean).join(" ").trim()||t.displayName||t.fullName||t.name||t.email)||""}function Rt({enabled:t,tenantField:r="clientId",scopeTenantId:n="",tenantFilters:a,selectedPatientId:l="",selectedPatientName:d="",onChange:u,disabled:m=!1,required:p=!1}){const{singular:i}=jr(),x=i.toLowerCase(),[N,g]=o.useState(!1),[y,f]=o.useState(""),{patients:j,loading:v,searching:R,error:A}=vr({enabled:!!t,searchTerm:y,tenantField:r,scopeTenantId:n,tenantFilters:a,statusMode:"lifecycle",initialSortKey:"lastName",initialSortDirection:"asc",refreshIntervalMs:0,searchDebounceMs:200});return o.useEffect(()=>{t||(g(!1),f(""))},[t]),t?e.jsxs("div",{className:"space-y-1.5 max-lg:space-y-1",children:[e.jsxs("label",{className:"text-xs font-semibold uppercase tracking-wide text-content-tertiary max-lg:text-2xs",children:[i,p?e.jsx(ut,{}):" (Optional)"]}),e.jsx("p",{className:"text-xs text-content-tertiary max-lg:text-2xs max-lg:leading-snug",children:p?`Select the ${x} this request concerns.`:`Link the ${x} this issue concerns. Leave blank if it does not apply to a specific ${x}.`}),e.jsxs("div",{className:"flex items-center gap-2 max-lg:gap-1.5",children:[e.jsxs(we,{open:N,onOpenChange:g,modal:!0,children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(B,{type:"button",variant:"outline",role:"combobox","aria-expanded":N,"aria-label":i,disabled:m,className:"h-9 w-full min-w-0 justify-between rounded-md border-default bg-surface-raised text-left font-normal text-slate-700 hover:bg-white dark:text-slate-200 dark:hover:bg-slate-950",children:[e.jsx("span",{className:"min-w-0 truncate",children:d||`Select a ${x}â¦`}),e.jsx(Vt,{className:"ml-2 size-4 shrink-0 opacity-60 max-lg:ml-1.5 max-lg:size-3.5"})]})}),e.jsx(Ae,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",accessibleLabel:`${i} options`,children:e.jsxs(Bt,{shouldFilter:!1,children:[e.jsx(zt,{placeholder:"Search patientsâ¦",className:"h-9",label:"Search patients",value:y,onValueChange:f}),e.jsx(Dt,{className:"max-h-[min(300px,40vh)] overscroll-contain",onWheel:P=>P.stopPropagation(),children:(v||R)&&j.length===0?e.jsx("div",{className:"space-y-2 p-2 max-lg:space-y-1.5 max-lg:p-1.5",children:Array.from({length:5}).map((P,k)=>e.jsx(qe,{className:"h-9 w-full rounded-md max-lg:h-7"},k))}):j.length===0?e.jsx(Yt,{children:A||"No patients found."}):e.jsx(Gt,{children:j.map(P=>{const k=Or(P);return e.jsxs(at,{value:`${k} ${P.email||""}`,onSelect:()=>{u==null||u(P.id,k,P.email||""),g(!1)},className:"items-start py-2 max-lg:py-1.5",children:[e.jsx(nt,{className:`mt-0.5 mr-2 size-4 max-lg:mr-1.5 max-lg:size-3.5 ${l===P.id?"opacity-100":"opacity-0"}`}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate font-medium text-content-primary max-lg:text-xs",children:k||"Unknown"}),P.email?e.jsx("span",{className:"mt-0.5 block truncate text-2xs italic text-content-tertiary max-lg:text-3xs",children:P.email}):null]})]},P.id)})})})]})})]}),l?e.jsx(B,{type:"button",variant:"ghost",size:"sm",disabled:m,onClick:()=>u==null?void 0:u("","",""),"aria-label":"Clear selected patient",className:"h-9 shrink-0 px-2 text-content-tertiary hover:text-slate-900 dark:hover:text-slate-200",children:e.jsx(Cs,{className:"size-4 max-lg:size-3.5"})}):null]})]}):null}function ot(t){return(t==null?void 0:t.pharmacyId)||(t==null?void 0:t.externalPharmacyId)||""}function Lt(t){return(t==null?void 0:t.pharmacyName)||(t==null?void 0:t.name)||ot(t)}function Fr({pharmacies:t=[],loading:r=!1,value:n="",selectedPharmacyName:a="",onChange:l,disabled:d=!1}){const[u,m]=o.useState(!1);let p="";if(n===Ie)p="General â not specific to one pharmacy";else if(n){const i=t.find(x=>ot(x)===n);p=i?Lt(i):a}return e.jsxs("div",{className:"space-y-1.5 max-lg:space-y-1",children:[e.jsxs("label",{className:"text-xs font-semibold uppercase tracking-wide text-content-tertiary max-lg:text-2xs",children:["Pharmacy ",e.jsx(ut,{})]}),e.jsx("p",{className:"text-xs text-content-tertiary max-lg:text-2xs max-lg:leading-snug",children:"Choose the pharmacy this issue concerns, or General if it isnât tied to one pharmacy."}),e.jsxs(we,{open:u,onOpenChange:m,modal:!0,children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(B,{type:"button",variant:"outline",role:"combobox","aria-expanded":u,"aria-label":"Pharmacy",disabled:d,className:"h-9 w-full min-w-0 justify-between rounded-md border-default bg-surface-raised text-left font-normal text-slate-700 hover:bg-white dark:text-slate-200 dark:hover:bg-slate-950",children:[e.jsx("span",{className:"min-w-0 truncate",children:p||"Select a pharmacyâ¦"}),e.jsx(Vt,{className:"ml-2 size-4 shrink-0 opacity-60 max-lg:ml-1.5 max-lg:size-3.5"})]})}),e.jsx(Ae,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",accessibleLabel:"Pharmacy options",children:e.jsxs(Bt,{children:[e.jsx(zt,{placeholder:"Search pharmaciesâ¦",className:"h-9",label:"Search pharmacies"}),e.jsx(Dt,{className:"max-h-[min(300px,40vh)] overscroll-contain",onWheel:i=>i.stopPropagation(),children:r?e.jsx("div",{className:"space-y-2 p-2 max-lg:space-y-1.5 max-lg:p-1.5",children:Array.from({length:5}).map((i,x)=>e.jsx(qe,{className:"h-9 w-full rounded-md max-lg:h-7"},x))}):e.jsxs(e.Fragment,{children:[e.jsx(Yt,{children:"No pharmacies found."}),e.jsxs(Gt,{children:[e.jsxs(at,{value:"General not specific to a pharmacy",onSelect:()=>{l==null||l(Ie,""),m(!1)},className:"items-start py-2 max-lg:py-1.5",children:[e.jsx(nt,{className:`mt-0.5 mr-2 size-4 max-lg:mr-1.5 max-lg:size-3.5 ${n===Ie?"opacity-100":"opacity-0"}`}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate font-medium text-content-primary max-lg:text-xs",children:"General"}),e.jsx("span",{className:"mt-0.5 block truncate text-2xs italic text-content-tertiary max-lg:text-3xs",children:"Not specific to one pharmacy"})]})]}),t.map(i=>{const x=ot(i),N=Lt(i);return e.jsxs(at,{value:`${N} ${x}`,onSelect:()=>{l==null||l(x,N),m(!1)},className:"items-start py-2 max-lg:py-1.5",children:[e.jsx(nt,{className:`mt-0.5 mr-2 size-4 max-lg:mr-1.5 max-lg:size-3.5 ${n===x?"opacity-100":"opacity-0"}`}),e.jsx("span",{className:"block min-w-0 truncate font-medium text-content-primary max-lg:text-xs",children:N})]},x)})]})]})})]})})]})]})}function Ur({label:t,children:r,className:n}){return r?e.jsx(mt,{delayDuration:150,children:e.jsxs(pt,{children:[e.jsx(xt,{asChild:!0,children:e.jsx(B,{t
1ype:"button",variant:"ghost",size:"icon",className:ie("size-5 shrink-0 rounded-full text-content-tertiary hover:text-content-secondary","max-[1024px]:min-h-5 max-[1024px]:min-w-5",n),"aria-label":t?`${t} details`:"Field details",children:e.jsx(Is,{className:"size-3.5","aria-hidden":!0})})}),e.jsx(ht,{className:"max-w-xs text-xs leading-relaxed",children:r})]})}):null}const $r={tension:420,friction:36,mass:.7};function qr({measureKey:t,className:r,children:n}){const a=o.useRef(null),[l,d]=o.useState(null),u=o.useRef(!1),m=Ps();o.useEffect(()=>{const N=a.current;if(!N||typeof window>"u")return;let g=0;function y(){window.cancelAnimationFrame(g),g=window.requestAnimationFrame(()=>{a.current&&d(a.current.offsetHeight)})}if(y(),typeof ResizeObserver>"u")return window.addEventListener("resize",y),()=>{window.cancelAnimationFrame(g),window.removeEventListener("resize",y)};const f=new ResizeObserver(y);return f.observe(N),()=>{window.cancelAnimationFrame(g),f.disconnect()}},[t]);const p=l!=null,i=m||!p||!u.current;o.useEffect(()=>{p&&(u.current=!0)},[p]);const x=ws({height:l??0,immediate:i,config:$r});return e.jsx(Es.div,{className:"overflow-hidden",style:p?x:void 0,children:e.jsx("div",{ref:a,"data-step-key":t,className:ie("min-w-0",r),children:n})})}const Mr={Package:Kt,Pill:Mt,User:As,UserCog:is},Vr=20;function Br(t,r=250){const[n,a]=o.useState(t);return o.useEffect(()=>{const l=window.setTimeout(()=>a(t),r);return()=>window.clearTimeout(l)},[r,t]),n}function _t(t,r){return[t,r].filter(Boolean).join(" ").trim()}function zr(t){const r=Number(t);return!Number.isFinite(r)||r<=0?"":new Date(r).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})}function Ue(t){const r=String(t||"").replace(/[_-]+/g," ").trim();return r?r.charAt(0).toUpperCase()+r.slice(1):""}const Dr={order:t=>({id:t.orderId||t.id,columns:[t.productName||"Order",t.patientName||t.patientEmail||"â",[Ue(t.status),zr(t.purchaseDateMs||t.createdAt)].filter(Boolean).join(" · ")||"â"],record:{type:"order",id:t.orderId||t.id,label:t.productName||`Order ${t.orderId||t.id}`,sublabel:t.patientName||t.patientEmail||"",meta:Ue(t.status)}}),prescription:t=>({id:t.id,columns:[[t.medicationName||"Prescription",t.dosage].filter(Boolean).join(" "),t.patientName||t.patientEmail||"â",[Ue(t.status),t.pharmacyName].filter(Boolean).join(" · ")||"â"],record:{type:"prescription",id:t.id,label:[t.medicationName||"Prescription",t.dosage].filter(Boolean).join(" "),sublabel:t.patientName||t.patientEmail||"",meta:Ue(t.status)}}),patient:t=>({id:t.id,columns:[_t(t.firstName,t.lastName)||t.fullName||t.email||"Patient",t.email||"â",t.phone||"â"],record:{type:"patient",id:t.id,label:_t(t.firstName,t.lastName)||t.fullName||t.email||"Patient",sublabel:t.email||"",meta:""}}),user:t=>({id:t.id,columns:[t.fullName||t.email||"User",t.email||"â",t.userType||"â"],record:{type:"user",id:t.id,label:t.fullName||t.email||"User",sublabel:t.email||"",meta:t.userType||""}})},Yr={order:["Product","Patient","Status"],prescription:["Medication","Patient","Status"],patient:["Name","Email","Phone"],user:["Name","Email","Role"]};function Gr({type:t,selectedKeys:r,onPick:n,disabled:a}){const l=ss[t],[d,u]=o.useState(""),m=Br(d),[p,i]=o.useState({loading:!0,rows:[],error:""}),[x,N]=o.useState(0),g=o.useRef(0);o.useEffect(()=>{const f=g.current+1;g.current=f;let j=!1;return i(v=>({...v,loading:!0,error:""})),Rs({entity:l.searchEntity,query:m,page:1,perPage:Vr}).then(v=>{if(j||g.current!==f)return;const R=Dr[t];i({loading:!1,error:"",rows:Zs(v,l.resultsKey).map(A=>R(A)).filter(A=>A.id)})}).catch(v=>{j||g.current!==f||i({loading:!1,rows:[],error:(v==null?void 0:v.message)||`Unable to search ${l.label.toLowerCase()}s.`})}),()=>{j=!0}},[l.label,l.resultsKey,l.searchEntity,m,x,t]);const y=Yr[t];return e.jsxs("div",{className:"flex max-h-[26rem] flex-col",children:[e.jsx("div",{className:"shrink-0 border-b border-border p-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ls,{className:"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-content-tertiary","aria-hidden":!0}),e.jsx(Wt,{value:d,onChange:f=>u(f.target.value),placeholder:l.searchPlaceholder,"aria-label":`Search ${l.label.toLowerCase()}s`,disabled:a,className:"h-8 pl-8 text-sm"})]})}),e.jsx("div",{className:"grid shrink-0 grid-cols-[minmax(0,1.3fr)_minmax(0,1.2fr)_minmax(0,1fr)] gap-3 border-b border-border bg-muted px-3 py-1.5",children:y.map(f=>e.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wide text-content-tertiary",children:f},f))}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[p.loading?e.jsxs("div",{className:"space-y-1.5 p-3",role:"status","aria-label":`Searching ${l.label.toLowerCase()}s`,children:[Array.from({length:4}).map((f,j)=>e.jsx(qe,{className:"h-7 w-full rounded-md"},j)),e.jsx("span",{className:"sr-only",children:"Loading results"})]}):null,!p.loading&&p.error?e.jsx(yt,{reason:"error",title:`Could not search ${l.label.toLowerCase()}s`,description:p.error,action:{label:"Try again",onClick:()=>N(f=>f+1)},className:"px-4 py-6"}):null,!p.loading&&!p.error&&p.rows.length===0?e.jsx(yt,{reason:m?"filtered":"empty",title:m?`No ${l.label.toLowerCase()}s match "${m}"`:`No ${l.label.toLowerCase()}s to attach`,description:m?"Try a different id, name, or email.":`Nothing here yet â ${l.label.toLowerCase()}s appear once they exist on this account.`,action:m?{label:"Clear search",onClick:()=>u("")}:null,className:"px-4 py-6"}):null,!p.loading&&!p.error&&p.rows.map(f=>{const j=r.has(it(f.record));return e.jsxs(B,{type:"button",variant:"ghost",onClick:()=>n(f.record),disabled:a||j,className:ie("grid h-auto w-full grid-cols-[minmax(0,1.3fr)_minmax(0,1.2fr)_minmax(0,1fr)] items-center gap-3","rounded-none border-b border-border px-3 py-2 text-left font-normal","focus-visible:ring-inset",j?"cursor-not-allowed opacity-60":"hover:bg-muted"),children:[e.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:f.columns[0]}),e.jsx("span",{className:"truncate text-xs text-content-secondary",children:f.columns[1]}),e.jsx("span",{className:"truncate text-xs text-content-tertiary",children:j?"Attached":f.columns[2]})]},`${t}:${f.id}`)})]})]})}function Kr({value:t=[],onChange:r,disabled:n=!1,types:a=Js,onLimitReached:l}){const[d,u]=o.useState(""),m=o.useMemo(()=>new Set(t.map(x=>it(x))),[t]),p=t.length>=Oe,i=o.useCallback(x=>{if(!m.has(it(x))){if(t.length>=Oe){l==null||l(Oe);return}r==null||r([...t,x]),u("")}},[r,l,m,t]);return e.jsxs("div",{className:"flex flex-wrap items-center gap-2 max-lg:gap-1.5",children:[a.map(x=>{const N=ss[x];if(!N)return null;const g=Mr[N.icon]||Kt;return e.jsxs(we,{open:d===x,onOpenChange:y=>u(y?x:""),children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(B,{type:"button",variant:"outline",size:"sm",disabled:n||p,className:"h-8 rounded-full px-3 text-xs max-lg:h-7 max-lg:px-2.5",children:[e.jsx(Qt,{className:"mr-1.5 size-3.5 max-lg:mr-1","aria-hidden":!0}),N.addLabel]})}),e.jsxs(Ae,{align:"start",className:"w-[min(36rem,calc(100vw-2rem))] p-0",onOpenAutoFocus:y=>{var f,j;y.preventDefault(),(j=(f=y.currentTarget)==null?void 0:f.querySelector("input"))==null||j.focus({preventScroll:!0})},children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[e.jsx(g,{className:"size-3.5 text-content-tertiary","aria-hidden":!0}),e.jsx("p",{className:"text-xs font-semibold text-foreground",children:N.addLabel})]}),e.jsx(Gr,{type:x,selectedKeys:m,onPick:i,disabled:n})]})]},x)}),p?e.jsx("p",{className:"text-2xs text-content-tertiary",children:`Limit reached (${Oe}).`}):null]})}const Qr=new Set(["Client Admin","Client Staff"]),Wr=new Set(["Provider Network Admin","Provider","Provider Delegate"]),Hr=new Set(["Business Admin","Business Location Admin","Business Staff","Business Provider","Business Provider Delegate"]),Xr=new Set(["Patient","Standard User"]),C={RECIPIENT:"recipient",TOPIC:"topic",DETAILS:"details",REVIEW:"review"},Ot=fr("create-support-ticket"),Jr="Include clear steps, expected behavior, and what actually happened. Use the toolbar for lists, links, or a simple table.",Zr="Add screenshots or files that help diagnose the issue faster, and attach the order, prescription, patient, or user the ticket is about.",ea="Add screenshots or files that help diagnose the issue faster.",Ft={low:{selected:"border-emerald-500 bg-emerald-50 dark:border-emerald-500 dark:bg-emerald-900/20",unselected:"border-emerald-200 bg-emerald-50/60 hover:border-emerald-300 dark:border-emerald-800 dark:bg-emerald-900/10 dark:hover:border-emerald-700",text:"text-emerald-900 dark:text-emerald-100",body:"text-emerald-800 dark:text-emerald-200"},medium:{selected:"border-amber-500 bg-amber-50 dark:border-amber-500 dark:bg-amber-900/20",unselected:"border-amber-200 bg-amber-50/60 hover:border-amber-300 dark:border-amber-800 dark:bg-amber-900/10 dark:hover:border-amber-700",text:"text-amber-900 dark:text-amber-100",body:"text-amber-800 dark:text-amber-200"},high:{selected:"border-rose-500 bg-rose-50 dark:border-rose-500 dark:bg-rose-900/20",unselected:"border-rose-200 bg-rose-50/60 hover:border-rose-300 dark:border-rose-800 dark:bg-rose-900/10 dark:hover:border-rose-700",text:"text-rose-900 dark:text-rose-100",body:"text-rose-800 dark:text-rose-200"}},ta={low:"Informational request, clarification, or non-blocking issue.",medium:"Standard issue that affects normal workflow but has a temporary workaround.",high:"Critical blocker causing immediate operational or care disruption."};function $e({htmlFor:t,children:r,required:n=!1,optional:a=!1,hint:l}){const d=t?"label":"span";return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs(d,{...t?{htmlFor:t}:{},className:"text-xs font-semibold uppercase tracking-wide text-content-tertiary max-lg:text-2xs",children:[r,n?e.jsx(ut,{}):null,a?" (Optional)":null]}),e.jsx(Ur,{label:typeof r=="string"?r:void 0,children:l})]})}function sa({value:t,onChange:r,disabled:n,severityRequired:a}){return e.jsxs("div",{className:"space-y-2 max-lg:space-y-1.5",children:[e.jsx($e,{required:a,optional:!a,hint:"Priority sets the queue order support works the ticket in. High is for an active blocker with no workaround.",children:"Priority"}),e.jsx(Vs,{value:t,onValueChange:r,className:"grid grid-cols-1 gap-2 max-lg:gap-1.5",disabled:n,children:gt.map(l=>{const d=Ft[l.value]||Ft.medium,u=t===l.value,m=`support-severity-${l.value}`;return e.jsxs("label",{htmlFor:m,className:ie("flex w-full items-start gap-2.5 rounded-xl border px-3 py-2.5 text-left transition-colors","max-lg:gap-2 max-lg:px-2.5 max-lg:py-2",u?d.selected:d.unselected,n?"cursor-not-allowed opacity-70":"cursor-pointer"),children:[e.jsx(Bs,{id:m,value:l.value,disabled:n,className:"mt-0.5 size-4 shrink-0 border-black bg-white text-black data-[state=checked]:border-black data-[state=checked]:bg-white max-lg:size-3.5"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:ie("block text-xs font-semibold max-lg:text-2xs",d.text),children:Me(l.value).toUpperCase()}),e.jsx("span",{className:ie("mt-0.5 block text-xs leading-snug max-lg:text-2xs",d.body),children:ta[l.value]})]})]},l.value)})})]})}function ra({open:t,onOpenChange:r,businessWorkspace:n=!1,severityRequired:a,hasActivePatientTicket:l,submitting:d,onSubmit:u}){const{branding:m}=Ht(),p=(m==null?void 0:m.accentColor)||Xt,{userDoc:i,clientData:x,providerNetworkBrandingMap:N}=ft(),g=tt(i==null?void 0:i.userType,[...Qr]),y=tt(i==null?void 0:i.userType,[...Wr]),f=Hr.has(i==null?void 0:i.userType),j=Xr.has(i==null?void 0:i.userType),v=o.useMemo(()=>g?_s(x||{}):[],[g,x]),R=tt(i==null?void 0:i.userType,["Provider","Provider Delegate"])&&!!(i!=null&&i.providerNetworkId),A=o.useMemo(()=>g||y||f?["platform","onlyscripts"]:[],[g,y,f]),P=o.useMemo(()=>{const h=S=>{const I=(N==null?void 0:N[S])||{};return{id:S,name:I.name||I.displayName||S,accentColor:I.accentColor||I.primaryColor||null,primaryColor:I.primaryColor||I.accentColor||null,logoUrl:I.logoUrl||null,iconUrl:I.iconUrl||null}};return g?v.map(h):R?[h(i.providerNetworkId)]:[]},[R,g,v,N,i==null?void 0:i.providerNetworkId]),k=A.length>0,G=!j,c=k?C.RECIPIENT:C.TOPIC,[b,K]=o.useState(c),[Ve,ye]=o.useState("forward"),[L,le]=o.useState(""),[X,J]=o.useState(""),je=k?L:j?"client":void 0,Be=o.useMemo(()=>
1er(je),[je]),[w,_]=o.useState(""),[Q,Z]=o.useState(""),[ee,te]=o.useState(""),[oe,z]=o.useState(""),[D,ve]=o.useState([]),[ce,O]=o.useState([]),[W,Y]=o.useState(""),[Te,F]=o.useState(""),[ze,H]=o.useState([]),[De,de]=o.useState(!1),[se,ue]=o.useState(""),[ke,U]=o.useState(""),[me,re]=o.useState(""),[pe,xe]=o.useState(""),[Ce,ae]=o.useState(""),Re=o.useRef(null),$=o.useCallback((h,S="forward")=>{ye(S),K(h)},[]),s=k&&L==="onlyscripts",[T,E]=o.useState(!1),ne=T&&(k?L==="platform":!j),he=Sr({subject:Q,description:ee,category:w,categoryLabel:w?lt(w):"",searchFaqs:wr,enabled:t&&!!w&&ne});o.useEffect(()=>{if(!t)return;let h=!1;return Ir().then(S=>{h||E((S==null?void 0:S.createFaqEnabled)===!0)}).catch(()=>{h||E(!1)}),()=>{h=!0}},[t]),o.useEffect(()=>{t||(K(c),ye("forward"),le(""),J(""),_(""),Z(""),te(""),z(""),ve([]),O([]),Y(""),F(""),H([]),ue(""),U(""),re(""),xe(""),ae(""))},[c,t]),o.useEffect(()=>{s||(xe(""),ae(""))},[s]),o.useEffect(()=>{L==="provider_network"&&v.length===1&&J(v[0])},[L,v]),o.useEffect(()=>{if(w!=="prescriptions"||s){Y(""),F(""),H([]),s||(ue(""),U(""),re(""));return}const h=(i==null?void 0:i.clientId)||null,S=(i==null?void 0:i.providerNetworkId)||null,I=(i==null?void 0:i.businessId)||null;if(!h&&!S&&!I)return;let q=!1;return de(!0),(h?Os({clientId:h}):Fs(S?{providerNetworkId:S}:{businessId:I})).then(fe=>{if(q)return;const Nt=Array.isArray(fe==null?void 0:fe.pharmacies)?fe.pharmacies.filter(et=>!et.error):[];H(Nt),Nt.length===0&&(Y(et=>et||Ie),F(""))}).catch(()=>{q||(H([]),Y(fe=>fe||Ie),F(""))}).finally(()=>{q||de(!1)}),()=>{q=!0}},[w,s,i==null?void 0:i.clientId,i==null?void 0:i.providerNetworkId,i==null?void 0:i.businessId]);function Ye({type:h,networkId:S}){le(h),J(h==="provider_network"&&S||""),_(""),$(C.TOPIC,"forward")}function Ge(h){_(h),$(C.DETAILS,"forward")}function Ke(){if(b===C.REVIEW){$(C.DETAILS,"backward");return}if(b===C.DETAILS){_(""),$(C.TOPIC,"backward");return}b===C.TOPIC&&k&&(le(""),J(""),$(C.RECIPIENT,"backward"))}function Le(){var S;if(s){if(!se)return M.error("Select the patient this OnlyScripts request concerns."),!1;if(!pe||!Ce)return M.error("Select the prescription or order this request concerns."),!1}else if(w==="prescriptions"&&!W)return M.error("Select the pharmacy this issue concerns."),!1;if(!Q.trim())return M.error("Subject is required."),(S=Re.current)==null||S.focus(),!1;const h=ee.trim();return h?h.length>Ct?(M.error(`Description must be ${Ct} characters or fewer.`),!1):!0:(M.error("Description is required."),!1)}async function Qe(){if(!w){M.error("Choose a topic first."),$(C.TOPIC,"backward");return}if(!Le()){$(C.DETAILS,"backward");return}if(a&&!oe){M.error("Select a priority level before submitting.");return}if(l){M.error("You already have an active support ticket.");return}await(u==null?void 0:u({category:w,subject:Q.trim(),severity:oe||null,description:ee.trim(),attachments:D,linkedRecords:ce,relatedPharmacyId:W||null,pharmacyName:Te||null,relatedPatientId:se||null,relatedPatientName:ke||null,relatedPatientEmail:me||null,recipientType:k?L:j?"client":null,recipientProviderNetworkId:L==="provider_network"?X:null,onlyScriptsSourceType:s?pe:null,onlyScriptsSourceId:s?Ce:null}))!==!1&&(r==null||r(!1))}function We(h){if(h.preventDefault(),!d){if(b===C.DETAILS){Le()&&$(C.REVIEW,"forward");return}Qe()}}const He=b===C.RECIPIENT?"Who is this ticket for?":b===C.TOPIC?"What do you need help with? Pick a topic to get started.":`Topic: ${lt(w)}`,Xe=b!==C.RECIPIENT&&!(b===C.TOPIC&&!k),Je=b===C.DETAILS||b===C.REVIEW,Ze=e.jsxs("div",{className:"flex w-full items-center justify-between gap-3 max-lg:gap-2",children:[e.jsx("div",{className:"min-w-0",children:Xe?e.jsxs(B,{type:"button",variant:"ghost",onClick:Ke,disabled:d,className:"rounded-full px-3 text-content-secondary max-lg:h-8 max-lg:px-2 max-lg:text-xs",children:[e.jsx(Us,{className:"mr-1 size-4 max-lg:size-3.5","aria-hidden":!0}),"Back"]}):null}),e.jsxs("div",{className:"flex items-center gap-3 max-lg:gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:()=>r==null?void 0:r(!1),disabled:d,className:"rounded-full max-lg:h-8 max-lg:px-3 max-lg:text-xs",children:"Cancel"}
1),Je?e.jsx(B,{type:"submit",form:Ot,disabled:d,style:{backgroundColor:p},className:"rounded-full text-white hover:opacity-90 max-lg:h-8 max-lg:px-3 max-lg:text-xs",children:d?e.jsxs(e.Fragment,{children:[e.jsx($s,{size:"sm",className:"mr-2 max-lg:mr-1.5"}),D.length>0?"Uploadingâ¦":"Submittingâ¦"]}):b===C.DETAILS?"Next":"Submit ticket"}):null]})]});return e.jsx(qs,{open:t,onOpenChange:r,size:"lg",title:"New Support Ticket",description:He,footer:Ze,mobileStickyHeader:!0,mobileStickyFooter:!0,contentClassName:n?"business-support-ticket-create":void 0,children:e.jsx(qr,{measureKey:b,children:e.jsxs("div",{"data-step-direction":Ve,className:"support-step-enter",children:[b===C.RECIPIENT?e.jsx(Tr,{options:A,networks:P,value:L,selectedNetworkId:X,onSelect:Ye,disabled:d}):null,b===C.TOPIC?e.jsx(_r,{value:w,onSelect:Ge,disabled:d,accentColor:p,categories:Be}):null,b===C.DETAILS||b===C.REVIEW?e.jsx("form",{id:Ot,onSubmit:We,className:hr,children:e.jsx("div",{className:"space-y-3 max-lg:space-y-2",children:b===C.DETAILS?e.jsxs(e.Fragment,{children:[s||w==="prescriptions"?e.jsx(_e,{className:"space-y-4 max-lg:space-y-2.5",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Rt,{enabled:t,required:!0,tenantField:i!=null&&i.businessId?"businessId":"clientId",selectedPatientId:se,selectedPatientName:ke,onChange:(h,S,I)=>{ue(h),U(S),re(I),xe(""),ae("")},disabled:d}),e.jsx(Nr,{patientId:se,businessId:(i==null?void 0:i.businessId)||"",sourceType:pe,sourceId:Ce,onChange:(h,S)=>{xe(h),ae(S)},disabled:d})]}):e.jsxs(e.Fragment,{children:[e.jsx(Fr,{pharmacies:ze,loading:De,value:W,selectedPharmacyName:Te,onChange:(h,S)=>{Y(h),F(S)},disabled:d}),e.jsx(Rt,{enabled:t&&w==="prescriptions",tenantField:i!=null&&i.businessId?"businessId":"clientId",selectedPatientId:se,selectedPatientName:ke,onChange:(h,S,I)=>{ue(h),U(S),re(I)},disabled:d})]})}):null,e.jsxs(_e,{className:"space-y-4 max-lg:space-y-2.5",children:[e.jsxs("div",{className:"space-y-1.5 max-lg:space-y-1",children:[e.jsx($e,{htmlFor:"ticket-subject",required:!0,hint:"One line support can scan in the queue â name the thing that is wrong, not the whole story.",children:"Subject"}),e.jsx(Wt,{id:"ticket-subject",ref:Re,placeholder:"Brief summary of the issue",value:Q,onChange:h=>Z(h.target.value),disabled:d,maxLength:180,required:!0})]}),e.jsxs("div",{className:"space-y-1.5 max-lg:space-y-1",children:[e.jsx($e,{htmlFor:"ticket-description",required:!0,hint:Jr,children:"Description"}),e.jsx(tr,{id:"ticket-description",value:ee,onChange:te,disabled:d,required:!0,minHeightClassName:"min-h-40 max-lg:min-h-32"}),ne?e.jsx(yr,{sources:he.sources,loading:he.loading,searched:he.searched,disabled:d,onHelped:()=>{M.success("Thanks â closing without a ticket."),r==null||r(!1)}}):null]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(B,{type:"button",variant:"ghost",onClick:()=>$(C.DETAILS,"backward"),disabled:d,"aria-label":"Edit subject and description",className:ie(Ms,"bg-card","flex h-auto w-full flex-col items-stretch gap-0 overflow-hidden p-0 text-left font-normal","hover:bg-surface-sunken"),children:[e.jsx("span",{className:"w-full border-b border-subtle px-3.5 py-2.5 max-lg:px-2.5 max-lg:py-2",children:e.jsx("span",{className:"block break-words text-sm font-semibold text-foreground max-lg:text-xs",children:Q.trim()})}),e.jsx("span",{className:"w-full whitespace-pre-wrap break-words px-3.5 py-2.5 text-xs leading-relaxed text-content-secondary max-lg:px-2.5 max-lg:py-2",children:Pr(ee.trim(),{preserveLineBreaks:!0})})]}),e.jsxs("div",{className:"support-step-reveal space-y-3 max-lg:space-y-2",children:[e.jsx(_e,{children:e.jsx(sa,{value:oe,onChange:z,disabled:d,severityRequired:a})}),e.jsxs(_e,{className:"space-y-3 max-lg:space-y-2",children:[e.jsx($e,{optional:!0,hint:G?Zr:ea,children:"Attachments"}),G?e.jsxs(e.Fragment,{children:[e.jsx(Kr,{value:ce,onChange:O,disabled:d,onLimitReached:h=>M.error(`You can attach up to ${h} records.`)}),e.jsx(sr,{records:ce,onRemove:h=>O(S=>S.filter(I=>!(I.type===h.type&&I.id===h.id))),compact:!0})]}):null,e.jsx(br,{files:D,onFilesChange:ve,disabled:d,uploading:d,accentColor:p,title:G?"Files":"Files (Optional)",resetToken:t})]})]})]})})}):null]},b)})})}const Ut=480;function aa(t){const r=String(t||"").trim();if(!r)return"";const n=r.replace(/\r\n?/g,` 2`).replace(/\[([^\]]+)\]\([^)\s]+\)/g,"$1").replace(/[*_`~|>#]+/g,"").replace(/^\s*[-*+]\s+/gm,"⢠").replace(/^\s*\d+\.\s+/gm,"").replace(/\|/g," ").replace(/[ \t]+\n/g,` 3`).replace(/\n{3,}/g,` 4 5`).trim();return n.length<=Ut?n:`${n.slice(0,Ut).trimEnd()}â¦`}function na({className:t=""}){return e.jsx("span",{className:`pointer-events-none absolute right-0 top-0 size-2 roun
5ded-full bg-red-500 shadow-[0_0_8px_2px_rgba(239,68,68,0.55)] ring-2 ring-red-500/35 animate-pulse ${t}`,"aria-label":"Needs attention",title:"Needs attention"})}function ia({label:t="Escalated to provider network"}){return e.jsx(mt,{delayDuration:0,children:e.jsxs(pt,{children:[e.jsx(xt,{asChild:!0,children:e.jsx("span",{className:"inline-flex shrink-0 items-center text-content-tertiary","aria-label":t,children:e.jsx(Ar,{className:"size-3.5","aria-hidden":!0})})}),e.jsx(ht,{side:"top",children:t})]})})}function la({subject:t,secondary:r="",description:n="",highlight:a="",needsAttention:l=!1,transferredOut:d=!1,transferredLabel:u="Escalated to provider network"}){const m=t||"Untitled ticket",p=aa(n),i=e.jsx("span",{className:"truncate pr-2.5 text-sm font-medium text-content-primary max-lg:text-2xs",children:e.jsx(kt,{text:m,highlight:a})});return e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[d?e.jsx(ia,{label:u}):null,e.jsxs("div",{className:"min-w-0 flex-1 space-y-1 max-lg:space-y-0.5",children:[e.jsxs("p",{className:"relative inline-flex max-w-full min-w-0",children:[p?e.jsx(mt,{delayDuration:250,children:e.jsxs(pt,{children:[e.jsx(xt,{asChild:!0,children:e.jsx("span",{className:"inline-flex max-w-full min-w-0 cursor-default",tabIndex:0,"aria-label":`${m}. Description preview available.`,children:i})}),e.jsx(ht,{side:"bottom",align:"start",className:"max-w-sm whitespace-pre-wrap text-xs leading-relaxed",children:p})]})}):i,l?e.jsx(na,{className:"-right-0.5 -top-0.5"}):null]}),r?e.jsx("p",{className:"truncate text-xs text-content-tertiary max-lg:text-3xs",children:e.jsx(kt,{text:r,highlight:a})}):null]})]})})}const os=o.forwardRef(function({children:r,ariaLabel:n,disabled:a,onClick:l,...d},u){return e.jsx("button",{ref:u,type:"button","aria-label":n,disabled:a,"data-row-click-ignore":!0,onClick:m=>{m.stopPropagation(),l==null||l(m)},className:"flex w-full items-center gap-1.5 rounded-md px-1 py-0.5 text-left transition hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-60 dark:hover:bg-slate-700",...d,children:r})});function cs({ticket:t}){return t.severity?e.jsxs(e.Fragment,{children:[e.jsx(rs,{severity:t.severity}),e.jsx("span",{className:`truncate text-xs font-semibold max-lg:hidden ${as[t.severity]||"text-slate-700 dark:text-slate-200"}`,children:rr(t.severity)})]}):e.jsx("span",{className:"text-xs text-slate-400 dark:text-slate-500",children:"â"})}function ct({status:t}){return e.jsx(bt,{className:`truncate rounded-full border ${ar[t]||"border-slate-200"}`,children:Ne(t)})}function oa({ticket:t,open:r,onOpenChange:n,updating:a,onSelect:l}){const d=t.severity?Me(t.severity):"not set";return e.jsxs(we,{open:r,onOpenChange:n,children:[e.jsx(Ee,{asChild:!0,children:e.jsx(os,{ariaLabel:`Priority for ${t.subject||"ticket"}: ${d}. Change priority`,disabled:a,children:a?e.jsx(Jt,{className:"size-3.5 animate-spin text-slate-400"}):e.jsx(cs,{ticket:t})})}),e.jsxs(Ae,{className:"w-64 space-y-2 p-3",align:"start",accessibleLabel:"Set support ticket priority",onClick:u=>u.stopPropagation(),children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-content-tertiary",children:"Set priority"}),e.jsxs("div",{className:"space-y-1",children:[gt.map(u=>e.jsxs("button",{type:"button",onClick:()=>l(u.value),className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left text-xs transition ${t.severity===u.value?"border-slate-300 bg-slate-50 dark:border-slate-600 dark:bg-slate-800":"border-transparent hover:border-slate-200 hover:bg-slate-50 dark:hover:border-slate-700 dark:hover:bg-slate-800"}`,children:[e.jsx(rs,{severity:u.value}),e.jsx("span",{className:`font-semibold ${as[u.value]||"text-slate-600 dark:text-slate-300"}`,children:u.label})]},u.value)),e.jsx("button",{type:"button",onClick:()=>l(null),disabled:!t.severity,className:"flex w-full items-center rounded-md border border-transparent px-2 py-1.5 text-left text-xs text-content-tertiary transition hover:border-slate-200 hover:bg-slate-50 disabled:opacity-50 dark:hover:border-slate-700 dark:hover:bg-slate-800",children:"Clear priority"})]})]})]})}function ca({ticket:t,statusOptions:r,open:n,onOpenChange:a,updating:l,onSelect:d}){const u=ns(r,t.status);return e.jsxs(we,{open:n,onOpenChange:a,children:[e.jsx(Ee,{asChild:!0,children:e.jsx(os,{ariaLabel:`Status for ${t.subject||"ticket"}
5: ${Ne(t.status)}. Change status`,disabled:l,children:l?e.jsx(Jt,{className:"size-3.5 animate-spin text-slate-400"}):e.jsx(ct,{status:t.status})})}),e.jsxs(Ae,{className:"w-56 space-y-2 p-3",align:"start",accessibleLabel:"Update support ticket status",onClick:m=>m.stopPropagation(),children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-content-tertiary",children:"Update status"}),e.jsx("div",{className:"space-y-1",children:u.map(m=>e.jsx("button",{type:"button",onClick:()=>d(m),className:`flex w-full items-center rounded-md border px-2 py-1.5 text-left transition ${t.status===m?"border-slate-300 bg-slate-50 dark:border-slate-600 dark:bg-slate-800":"border-transparent hover:border-slate-200 hover:bg-slate-50 dark:hover:border-slate-700 dark:hover:bg-slate-800"}`,children:e.jsx(ct,{status:m})},m))})]})]})}const da={client:"client",provider_network:"network",business:"business"};function st(t){return t.categoryLabel||lt(t.category)||""}function ua({kind:t,label:r,color:n}){return t==="platform"?e.jsx("span",{className:"inline-flex max-w-full items-center",title:r||vt,children:e.jsx("img",{src:zs,alt:r||vt,className:"h-5 w-auto max-w-[7.5rem] object-contain object-left max-lg:h-4 max-lg:max-w-[6.5rem]"})}):t==="onlyscripts"?e.jsx("span",{className:"inline-flex max-w-full items-center rounded-md px-1.5 py-0.5",style:{backgroundColor:kr},title:r||Et,children:e.jsx("img",{src:Cr,alt:r||Et,className:"h-4 w-auto max-w-[6.5rem] object-contain object-left max-lg:h-3.5"})}):e.jsx(Er,{type:da[t],color:n,className:"truncate",children:r})}function ma({isIncoming:t,searchTerm:r="",showAssignee:n=!1,canManageTicket:a=()=>!1,statusOptions:l=[],inlineEditor:d=null,onInlineEditorChange:u=()=>{},inlineUpdatingId:m="",onUpdatePriority:p=null,onUpdateStatus:i=null}){const x=c=>typeof p=="function"&&a(c),N=c=>typeof i=="function"&&a(c),g=(c,b)=>(d==null?void 0:d.ticketId)===c&&(d==null?void 0:d.type)===b,y={id:"priority",header:"Priority",sortKey:"presentation.priorityWeight",minWidth:t?116:104,csvValue:c=>c.severity?Me(c.severity):"",renderCell:c=>x(c)?e.jsx(oa,{ticket:c,open:g(c.id,"priority"),onOpenChange:b=>u(b?{ticketId:c.id,type:"priority"}:null),updating:m===c.id,onSelect:b=>p(c,b)}):e.jsx("span",{className:"flex min-w-0 items-center gap-1.5",children:e.jsx(cs,{ticket:c})})},f={id:"subject",header:"Subject",sortKey:"subject",minWidth:220,csvValue:c=>c.subject||"",renderCell:c=>{var b;return e.jsx(la,{subject:c.subject||"Untitled ticket",secondary:c.presentation.patientName||"",description:c.description||"",highlight:r,needsAttention:(b=c.presentation)==null?void 0:b.needsQueueAttention})}},j={id:"requester",header:"Requester",sortKey:"presentation.requesterName",minWidth:180,csvValue:c=>c.presentation.requesterName||"",renderCell:c=>e.jsx(At,{label:c.presentation.requesterName,sublabel:c.presentation.requesterUserType||"",highlight:r,toneClassName:jt(c.presentation.requesterUserType)})},v={id:"counterparty",header:t?"From":"Sent to",sortKey:"presentation.counterpartyLabel",minWidth:170,csvValue:c=>c.presentation.counterpartyLabel||"",renderCell:c=>e.jsx(ua,{kind:c.presentation.counterpartyKind,label:c.presentation.counterpartyLabel,color:c.presentation.counterpartyColor})},R={id:"topic",header:"Topic",sortKey:"presentation.topicSortValue",minWidth:150,csvValue:st,renderCell:c=>st(c)?e.jsx(bt,{className:`truncate rounded-full border ${nr[c.category]||"border-slate-200"}`,children:st(c)}):e.jsx("span",{className:"text-xs text-slate-400 dark:text-slate-500",children:"â"})},A={id:"status",header:"Status",sortKey:"status",minWidth:t?172:156,csvValue:c=>Ne(c.status),renderCell:c=>N(c)?e.jsx(ca,{ticket:c,statusOptions:l,open:g(c.id,"status"),onOpenChange:b=>u(b?{ticketId:c.id,type:"status"}:null),updating:m===c.id,onSelect:b=>i(c,b)}):e.jsx(ct,{status:c.status})},P={id:"assignee",header:"Assigned",sortKey:"presentation.assigneeName",minWidth:160,csvValue:c=>c.presentation.assigneeName||"Unassigned",renderCell:c=>c.presentation.assigneeName?e.jsx(At,{label:c.presentation.assigneeName,sublabel:c.presentation.assigneeUserType||"",highlight:r,toneClassName:jt(c.presentation.assigneeUserType)}):e.jsx("span",{className:"text-xs text-slate-400 dark:text-slate-500",children:"Unassigned"})},k={id:"createdAt",header:"Created",sortKey:"presentation.createdAt",minWidth:116,csvValue:c=>c.createdAt?Pt(c.createdAt):"",renderCell:c=>e.jsx(It,{value:c.createdAt,className:"max-lg:text-2xs"})},G={id:"updatedAt",header:"Updated",sortKey:"presentation.updatedAt",minWidth:116,csvValue:c=>c.updatedAt?Pt(c.updatedAt):"",renderCell:c=>e.jsx(It,{value:c.presentation.updatedAt,className:"max-lg:text-2xs"})};return t?[y,f,j,v,A,R,...n?[P]:[],k,G]:[f,v,A,y,R,...n?[P]:[],k,G]}const St="none",Pe="unassigned";function ds(t){return(t==null?void 0:t.severity)||St}function us(t,r=n=>n){return r((t==null?void 0:t.status)||"")||""}function ms(t){return(t==null?void 0:t.category)||""}function ps(t){const r=(t==null?void 0:t.presentation)||{};return r.requesterProfileUserId||r.requesterName||""}function xs(t){const r=(t==null?void 0:t.presentation)||{};return r.counterpartyId||r.counterpartyKind||""}function hs(t){return Array.isArray(t==null?void 0:t.assignedUserIds)?t.assignedUserIds.length?t.assignedUserIds:[Pe]:(t==null?void 0:t.assignedProviderUserId)||Pe}function ge(t,r,n){const a=String(r??"").trim(),l=String(n??"").trim();if(!a||!l)return;const d=t.get(a);t.set(a,{id:a,label:l,count:((d==null?void 0:d.count)||0)+1})}function Se(t){return[...t.values()].sort((r,n)=>r.label.localeCompare(n.label))}function pa(t=[],{priorityLabels:r={},formatStatusLabel:n}={}){const a=new Map,l=new Map,d=new Map,u=new Map,m=new Map,p=new Map;return t.forEach(i=>
5{var f,j;const x=(i==null?void 0:i.presentation)||{},N=us(i,n);ge(a,N,N),ge(l,ms(i),x.topicSortValue);const g=ds(i);ge(d,g,g===St?"No priority set":r[g]||g),ge(u,ps(i),x.requesterName),ge(m,xs(i),x.counterpartyLabel);const y=hs(i);for(const v of Array.isArray(y)?y:[y])ge(p,v,v===Pe?"Unassigned":((j=(f=i.assignees)==null?void 0:f.find(R=>R.id===v))==null?void 0:j.name)||x.assigneeName||"Assigned")}),{statuses:Se(a),topics:Se(l),priorities:xa(Se(d)),requesters:Se(u),counterparties:Se(m),assignees:ha(Se(p))}}function xa(t){const r={high:0,medium:1,low:2,[St]:3};return[...t].sort((n,a)=>(r[n.id]??9)-(r[a.id]??9))}function ha(t){return[...t].sort((r,n)=>r.id===Pe?-1:n.id===Pe?1:r.label.localeCompare(n.label))}function fa(t={},{formatStatusLabel:r}={}){return[{id:"status",getValue:n=>us(n,r),activeValues:t.statuses||[]},{id:"topic",getValue:ms,activeValues:t.topics||[]},{id:"priority",getValue:ds,activeValues:t.priorities||[]},{id:"requester",getValue:ps,activeValues:t.requesters||[]},{id:"counterparty",getValue:xs,activeValues:t.counterparties||[]},{id:"assignee",getValue:hs,activeValues:t.assignees||[]}]}function ba({createdRange:t}={}){return[{id:"created",field:"createdAt",dateRange:t}]}const ga=[t=>{var r;return((r=t==null?void 0:t.presentation)==null?void 0:r.searchText)||""}];function Sa({searchTerm:t="",selection:r={},createdRange:n=null}={}){const a=Object.values(r).some(l=>Array.isArray(l)&&l.length>0);return!!(String(t).trim()||a||n!=null&&n.from)}function $t(){return{statuses:[],topics:[],priorities:[],requesters:[],counterparties:[],assignees:[]}}const rt=[{id:"incoming",label:"Incoming Requests",icon:Zt},{id:"sent",label:"Your Support Tickets",icon:es}],Na=gt.reduce((t,r)=>({...t,[r.value]:r.label}),{});function qt({showHeader:t=!0,businessWorkspace:r=!1}){const{currentUser:n,userDoc:a,userType:l,clientData:d}=ft(),{branding:u}=Ht(),[m,p]=Ds(),i=(u==null?void 0:u.accentColor)||Xt,[x,N]=o.useState([]),[g,y]=o.useState(!0),[f,j]=o.useState(""),[v,R]=o.useState(""),[A,P]=o.useState("incoming"),[k,G]=o.useState($t),[c,b]=o.useState(void 0),[K,Ve]=o.useState({key:"presentation.updatedAt",direction:"desc"}),[ye,L]=o.useState(null),[le,X]=o.useState(""),[J,je]=o.useState(!1),[Be,w]=o.useState(!1),_=o.useMemo(()=>({id:(a==null?void 0:a.id)||(n==null?void 0:n.uid)||null,userType:(a==null?void 0:a.userType)||l||"",email:(a==null?void 0:a.email)||(n==null?void 0:n.email)||null,fullName:(a==null?void 0:a.fullName)||(a==null?void 0:a.name)||(n==null?void 0:n.displayName)||null,clientId:(a==null?void 0:a.clientId)||null,providerNetworkId:(a==null?void 0:a.providerNetworkId)||null,businessId:(a==null?void 0:a.businessId)||null}),[n==null?void 0:n.displayName,n==null?void 0:n.email,n==null?void 0:n.uid,a==null?void 0:a.id,a==null?void 0:a.clientId,a==null?void 0:a.email,a==null?void 0:a.fullName,a==null?void 0:a.name,a==null?void 0:a.providerNetworkId,a==null?void 0:a.businessId,a==null?void 0:a.userType,l]),Q=ir.has(l),Z=l==="Patient"||l==="Standard User",ee=(d==null?void 0:d.name)||(d==null?void 0:d.displayName)||"your care team",te=o.useMemo(()=>ns(),[]),oe=o.useCallback(s=>{const T=new URLSearchParams(m);s?T.set("supportTicketId",s):T.delete("supportTicketId"),p(T)},[m,p]);o.useEffect(()=>{if(!_.id){N([]),y(!1);return}return y(!0),lr({actor:_,onData:T=>{N(Array.isArray(T)?T:[]),j(""),y(!1)},onError:T=>{j(Fe(T,"Unable to load support tickets.")),y(!1)}})},[_]);const z=or(_.userType),D=o.useMemo(()=>cr(x,_),[x,_]),ve=o.useMemo(()=>z?D.filter(s=>!s.presentation.isIncoming):D,[D,z]),ce=o.useMemo(()=>z?D.filter(s=>s.presentation.isIncoming):[],[D,z]),O=z&&A==="incoming",W=O?ce:ve,Y=z&&O,Te=o.useCallback(s=>dr(_,s).canManageQueue,[_]),F=o.useMemo(()=>pa(W,{priorityLabels:Na,formatStatusLabel:Ne}),[W]),{filteredRows:ze,sortedRows:H,filteredCount:De,totalCount:de}=o.useMemo(()=>Hs(W,{searchTerm:v,searchFields:ga,filters:fa(k,{formatStatusLabel:Ne}),dateFilters:ba({createdRange:c}),sortKey:K.key,sortDirection:K.direction}),[W,c,v,k,K.direction,K.key]);o.useEffect(()=>{wt({source:"support-tenant-table",ticketIds:H.map(s=>s.id)})},[H]),o.useEffect(()=>()=>
5{wt({source:"",ticketIds:[]})},[]);const se=de>0&&Sa({searchTerm:v,selection:k,createdRange:c}),ue=o.useCallback(()=>{R(""),G($t()),b(void 0)},[]),ke=o.useCallback(s=>{Ve(T=>T.key!==s?{key:s,direction:"asc"}:T.direction==="asc"?{key:s,direction:"desc"}:{key:null,direction:"asc"})},[]),U=o.useCallback((s,T)=>{G(E=>({...E,[s]:T}))},[]),me=o.useMemo(()=>Z?x.some(s=>(s==null?void 0:s.isActive)===!0):!1,[Z,x]),re=o.useCallback(async(s,T)=>{if(!(s!=null&&s.id)||T===(s.severity||null)){L(null);return}X(s.id);try{await ur({ticketId:s.id,severity:T}),L(null),V.success(T?`Priority set to ${Me(T)}.`:"Priority cleared.")}catch(E){V.error(Fe(E,"Unable to update ticket priority."))}finally{X("")}},[]),pe=o.useCallback(async(s,T)=>{if(!(s!=null&&s.id)||T===s.status){L(null);return}X(s.id);try{await mr({ticketId:s.id,status:T,statusOptions:te}),L(null),V.success(`Status updated to ${Ne(T)}.`)}catch(E){V.error(Fe(E,"Unable to update ticket status."))}finally{X("")}},[te]),xe=o.useMemo(()=>ma({isIncoming:O,searchTerm:v,showAssignee:Y,canManageTicket:Te,statusOptions:te,inlineEditor:ye,onInlineEditorChange:L,inlineUpdatingId:le,onUpdatePriority:re,onUpdateStatus:pe}),[Te,re,pe,ye,le,O,v,Y,te]);async function Ce(s){var S,I;const T=(s==null?void 0:s.category)||"",E=((S=s==null?void 0:s.subject)==null?void 0:S.trim())||"",ne=((I=s==null?void 0:s.description)==null?void 0:I.trim())||"",he=(s==null?void 0:s.severity)||null,Ye=Array.isArray(s==null?void 0:s.attachments)?s.attachments:[],Ge=pr(s==null?void 0:s.linkedRecords),Ke=(s==null?void 0:s.relatedPharmacyId)||null,Le=(s==null?void 0:s.pharmacyName)||null,Qe=(s==null?void 0:s.relatedPatientId)||null,We=(s==null?void 0:s.relatedPatientName)||null,He=(s==null?void 0:s.relatedPatientEmail)||null,Xe=(s==null?void 0:s.recipientType)||null,Je=(s==null?void 0:s.recipientProviderNetworkId)||null,Ze=(s==null?void 0:s.onlyScriptsSourceType)||null,h=(s==null?void 0:s.onlyScriptsSourceId)||null;if(!T)return V.error("Choose a topic first."),!1;if(!E)return V.error("Subject is required."),!1;if(!ne)return V.error("Description is required."),!1;if(Q&&!he)return V.error("Select a priority level before submitting."),!1;if(me)return V.error("Patients can only have one active support ticket at a time."),!1;je(!0);try{const q=await xr({actor:_,category:T,subject:E,description:ne,severity:he,attachments:Ye,linkedRecords:Ge,relatedPharmacyId:Ke,pharmacyName:Le,relatedPatientId:Qe,relatedPatientName:We,relatedPatientEmail:He,recipientType:Z?"client":Xe,recipientProviderNetworkId:Je,onlyScriptsSourceType:Ze,onlyScriptsSourceId:h});return V.success("Support ticket submitted."),w(!1),q!=null&&q.ticket&&oe(q.ticket.id),!0}catch(q){return V.error(Fe(q,"Unable to submit support ticket.")),!1}finally{je(!1)}}const ae=O?"Incoming Requests":"Your Support Tickets",Re=f?"Support tickets could not be loaded.":de===0?O?"No requests yet. Requests routed to your team will appear here.":"No support tickets yet. Create one to get started.":"No tickets match these filters.",$=o.useMemo(()=>[be({id:"status",filters:F.statuses,activeFilters:k.statuses,onFilterChange:s=>U("statuses",s),defaultLabel:"All statuses"}),be({id:"topic",filters:F.topics,activeFilters:k.topics,onFilterChange:s=>U("topics",s),defaultLabel:"All topics",searchable:!0}),be({id:"priority",filters:F.priorities,activeFilters:k.priorities,onFilterChange:s=>U("priorities",s),defaultLabel:"All priorities"}),O?be({id:"requester",filters:F.requesters,activeFilters:k.requesters,onFilterChange:s=>U("requesters",s),defaultLabel:"All requesters",searchable:!0}):null,be({id:"counterparty",filters:F.counterparties,activeFilters:k.counterparties,onFilterChange:s=>U("counterparties",s),defaultLabel:O?"All accounts":"All recipients",searchable:!0}),Y?be({id:"assignee",filters:F.assignees,activeFilters:k.assignees,onFilterChange:s=>U("assignees",s),defaultLabel:"All assignees",searchable:!0}):null,Xs({id:"created",label:"Created",date:c,setDate:b})].filter(Boolean),[c,F,O,k,Y,U]);return e.jsxs("div",{className:`app-page-shell space-y-6 max-lg:space-y-3 ${r?"business-support-page":""}`,children:[t?r?e.jsx(Qs,{title:"Support",description:"Create requests and track responses.",testId:"section-support-header"}):e.jsx(Rr,{title:"Support",description:Z?`Submit support requests to ${ee} and track responses here.`:"Submit support requests and track updates from the GEN Health team."}):null,z?e.jsx(Ys,{className:"border border-subtle bg-surface-raised p-1 max-lg:p-0.5",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:`absolute bottom-0 top-0 rounded-lg shadow-sm transition-transform motion-reduce:transition-none ${r?"[transition-duration:var(--business-motion-base)] [transition-timing-function:var(--business-motion-ease)]":"duration-300 ease-out"}`,style:{backgroundColor:i,width:`${100/rt.length}%`,left:0,transform:`translateX(${rt.findIndex(s=>s.id===A)*100}%)`}}),e.jsx("div",{className:"relative flex",children:rt.map(s=>{const T=s.icon,E=A===s.id,ne=s.id==="incoming"?ce.length:ve.length;return e.jsxs("button",{type:"button",onClick:()=>P(s.id),"aria-pressed":E,"data-testid":`button-support-queue-${s.id}`,className:`relative z-raised inline-flex min-w-0 flex-1 items-center justify-center gap-1.5 rounded-lg px-2 py-2 text-2xs font-medium transition-colors duration-200 sm:gap-2 sm:px-4 sm:py-2.5 sm:text-sm ${E?"text-white":"text-slate-600 hover:text-slate-900 dark:text-slate-400 dark:hover:text-slate-200"}`,children:[e.jsx(T,{className:"hidden size-4 shrink-0 sm:block","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:s.label}),g?e.jsx(qe,{className:`h-5 w-8 rounded-full ${E?"bg-white/25":"bg-slate-200 dark:bg-slate-600"}`}):e.jsx(bt,{variant:"secondary",className:`h-5 min-w-[20px] shrink-0 px-1.5 ${E?"border-white bg-white":"bg-slate-100 text-slate-700 dark:bg-slate-700 dark:text-slate-300"}`,style:E?{color:i}:void 0,children:ne})]},s.id)})})]})}):null,e.jsx(Ws,{id:"support-tickets",title:ae,icon:O?Zt:es,accentColor:i,className:"min-w-0",loading:g,error:f,filteredCount:De,totalCount:de,actions:e.jsxs(B,{type:"button",onClick:()=>w(!0),disabled:J||me,className:"h-8 rounded-full px-3 text-xs font-semibold text-white hover:opacity-90",style:{backgroundColor:i},"data-testid":"button-support-create-ticket",children:[e.jsx(Qt,{className:"mr-1.5 size-3.5"}),e.jsx("span",{className:"max-lg:hidden",children:"Create Support Ticket"}),e.jsx("span",{className:"lg:hidden",children:"New ticket"})]}
5),search:{value:v,onChange:R,placeholder:"Search by subject, requester, account, topic, or patientâ¦",testId:"input-support-tickets-search"},filters:$,hasActiveFilters:se,onClearFilters:ue,headerExtra:me?e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-300",children:"You already have an active support ticket. Please close it before creating a new one."}):null,columns:xe,rows:H,rowKey:"id",rowClick:s=>oe(s.id),rowKeyboardAccessible:!0,rowAriaLabel:s=>`Open support ticket ${(s==null?void 0:s.subject)||(s==null?void 0:s.id)}`,rowTestId:s=>`row-support-ticket-${s==null?void 0:s.id}`,sortKey:K.key,sortDirection:K.direction,onSort:ke,csvExport:{feature:"support-tickets",tenantSlug:u==null?void 0:u.businessName,view:{getRows:()=>ze},allData:{mode:"client",getRows:()=>D,label:"Export both queues"}},compactDensity:!0,virtualized:!0,stretchToMaxHeight:!0,tableTestId:"table-support-tickets",tableLabel:`${ae} table`,emptyMessage:Re}),e.jsx(ra,{open:Be,onOpenChange:w,severityRequired:Q,hasActivePatientTicket:me,submitting:J,onSubmit:Ce})]})}const ya=new Set(["Patient","Standard User"]);function pn({showHeader:t=!0,businessWorkspace:r=!1}){const{userType:n,clientData:a,loading:l}=ft();return l?e.jsx(Gs,{title:"Support",description:"Review support options and support history.",message:"Loading supportâ¦"}):ya.has(n)?Ks(a)?e.jsx(qt,{showHeader:t,businessWorkspace:r}):e.jsx(Tt,{to:"/dashboard",replace:!0}):n==="Provider"||n==="Provider Delegate"||n==="Business Admin"||n==="Business Location Admin"||n==="Business Provider"||n==="Business Provider Delegate"||n==="Business Staff"||n==="Provider Network Admin"||n==="Client Admin"||n==="Client Staff"?e.jsx(qt,{showHeader:t,businessWorkspace:r}):e.jsx(Tt,{to:"/dashboard",replace:!0})}export{pn 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.