1import{e as $,r as s,j as e}from"./react-vendor-CWwlbjRo-1790978053425.js";import"./CreateLeadModal-BSWhBK9--1790978053425.js";import{_ as T,T as I,aF as L,a1 as R,bk as J,m as W,S as X,X as q,aa as z,O as G}from"./index-DsAuDdHa-1790978053425.js";import{u as H}from"./crm-multiselect-field-uHspvH-j-1790978053425.js";import"./ben-CbEv7h_G-1790978053425.js";import"./SettingsShell-CdMucJZR-1790978053425.js";/* empty css */import{g as F,a as Q}from"./CRMLayout-Bqsl90uv-1790978053425.js";import{e as f,b as O,a as B,C as Z}from"./CrmSettingsStates-FvwA5pep-1790978053425.js";import{a as N}from"./crmOpportunityApi-D3lqPqnw-1790978053425.js";/* empty css */import{F as ee}from"./FilterField-ZsCglQvH-1790978053425.js";import{u as te}from"./useDebouncedValue-D8fKHrSX-1790978053425.js";/* empty css *//* empty css */import"./mail-DKnD_OIn-1790978053425.js";import"./FilterSelect-D6djYx78-1790978053425.js";import"./SearchableSelect-fd2SkgrT-1790978053425.js";import"./circle-check-CMk7dTHi-1790978053425.js";import"./shellPaths-BtLch0ST-1790978053425.js";import"./useLayoutConfig-zkwSCOgf-1790978053425.js";import"./onboardingV2Api-bWnONEh1-1790978053425.js";import"./useSFTransition-BYP_ti7v-1790978053425.js";import"./trophy-CW1gdJoH-1790978053425.js";import"./circle-user-round-DDy3ZngB-1790978053425.js";import"./clipboard-check-C5A1FNIV-1790978053425.js";import"./calendar-days-C_OVIfuQ-1790978053425.js";import"./gauge-V69bakM3-1790978053425.js";import"./wand-sparkles--0av4RCp-1790978053425.js";import"./boxes-Drr6M8uU-1790978053425.js";import"./user-cog-HjeqZ7Uq-1790978053425.js";const se=l=>l.toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:0});function ae(){const l=$(),h=F(),[r,b]=s.useState(null),[i,d]=s.useState(!0),[m,u]=s.useState(null),n=s.useCallback(async()=>{d(!0),u(null);try{b(await N.partnerRoi())}catch(a){u(f(a,"Could not load partner performance."))}finally{d(!1)}},[]);return s.useEffect(()=>{n()},[n]),i?e.jsx(O,{label:"partner performance"}):m?e.jsx("div",{className:"msg msg-error",role:"alert",children:m}):r?e.jsxs("section",{className:"mb-6",children:[e.jsx("h2",{className:"text-sm font-semibold mb-1",children:"Partner performance"}),e.jsx("p",{className:"text-xs text-(--muted) mb-2",children:"Who sends you people, and what happens to them. Ordered by how many they send."}),r.unattributed_referrals>0&&e.jsxs("div",{className:"setting-note mb-2",role:"status",children:[e.jsx(T,{className:"w-3.5 h-3.5 inline mr-1"}),r.unattributed_referrals," referral",r.unattributed_referrals===1?"":"s"," name a referrer with no partner account, so ",r.unattributed_referrals===1?"it is":"they are"," not counted below. Create an account for them and set âReferred By (Partner)â on those leads to include them."]}),r.rows.length===0?e.jsx(B,{title:"No referrals attributed to a partner yet",sub:"Set âReferred By (Partner)â on a lead to start tracking where your referrals come from.",icon:e.jsx(I,{className:"w-6 h-6"})}):e.jsx("div",{className:"crm-table-wrap",children:e.jsxs("table",{className:"crm-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Partner"}),e.jsx("th",{className:"text-right",children:"Sent"}),e.jsx("th",{className:"text-right",children:"Admitted"}),e.jsx("th",{className:"text-right",children:"Avg stay"}),e.jsx("th",{className:"text-right",children:"Value"})]})}),e.jsx("tbody",{children:r.rows.map(a=>e.jsxs("tr",{className:"cursor-pointer hover:bg-(--hover)",onClick:()=>l(`${h}/accounts/${a.account_id}`),children:[e.jsx("td",{className:"font-medium",children:a.account_name}),e.jsx("td",{className:"text-right tabular-nums",children:a.referrals_in}),e.jsxs("td",{className:"text-right tabular-nums",children:[a.admitted,a.admit_rate!==null&&e.jsxs("span",{className:"text-xs text-(--muted) ml-1",children:["(",a.admit_rate,"%)"]})]}),e.jsxs("td",{className:"text-right tabular-nums",children:[a.avg_days_admitted===null?e.jsx("span",{className:"text-(--muted)",title:"No completed stays recorded for this partner yet",children:"â"}
1):e.jsxs(e.Fragment,{children:[a.avg_days_admitted,"d",e.jsxs("span",{className:"text-xs text-(--muted) ml-1",children:["(of ",a.days_known_for,")"]})]}),a.excluded_implausible>0&&e.jsx(T,{className:"w-3 h-3 inline ml-1 text-(--warn)","aria-label":`${a.excluded_implausible} stay(s) outside the plausible range, not counted`})]}),e.jsx("td",{className:"text-right tabular-nums",children:a.value_known_for===0?e.jsx("span",{className:"text-(--muted)",title:"No episode value recorded for this partner's referrals",children:"â"}):e.jsxs(e.Fragment,{children:[se(a.total_value),e.jsxs("span",{className:"text-xs text-(--muted) ml-1",children:["(of ",a.value_known_for,")"]})]})})]},a.account_id))})]})})]}):null}const re=[{value:"patient",label:"Patient"},{value:"referral_partner",label:"Referral Partner"}],ne={value:"",label:"All types"};function Be(){const l=$(),h=F(),[r,b]=s.useState([]),[i,d]=s.useState(!0),[m,u]=s.useState(null),[n,a]=s.useState(""),[c,D]=s.useState(""),[M,x]=s.useState(!1),[y,g]=s.useState(""),[v,V]=s.useState("patient"),[_,C]=s.useState(!1),[w,S]=s.useState(null),k=te(n,300),{getOptions:A}=H(),p=s.useMemo(()=>{const t=A("account_type");return t.length?t.map(o=>({value:o.value,label:o.label})):re},[A]),U=s.useMemo(()=>[ne,...p],[p]),K=s.useMemo(()=>Object.fromEntries(p.map(t=>[t.value,t.label])),[p]),j=s.useCallback(async()=>{d(!0),u(null);try{const t=await N.list({search:k||void 0,account_type:c||void 0});b(t)}catch(t){u(f(t,"Could not load accounts."))}finally{d(!1)}},[k,c]);s.useEffect(()=>{j()},[j]);const E=async()=>{const t=y.trim();if(t){C(!0),S(null);try{const o=await N.create({name:t,account_type:v||void 0});x(!1),g(""),l(`${h}/accounts/${o.id}`)}catch(o){S(f(o,"Could not create this account."))}finally{C(!1)}}},P=s.useMemo(()=>r.filter(t=>t.opportunity_count>1).length,[r]),Y=e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(X,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-(--muted)","aria-hidden":!0}),e.jsx("input",{type:"search",value:n,onChange:t=>a(t.target.value),placeholder:"Search accountsâ¦","aria-label":"Search accounts",className:"field pl-9 pr-8 w-56"}),n&&e.jsx("button",{type:"button",onClick:()=>a(""),"aria-label":"Clear search",className:"absolute right-2 top-1/2 -translate-y-1/2 text-(--muted) hover:text-(--fg)",children:e.jsx(q,{className:"w-3.5 h-3.5"})})]}),e.jsx(ee,{label:"Type",children:e.jsx(L,{value:c,onValueChange:D,options:U,ariaLabel:"Filter by account type"})}),e.jsx("button",{type:"button",className:"btn",onClick:()=>void j(),"aria-label":"Refresh accounts",children:e.jsx(z,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),e.jsxs("button",{type:"button",className:"btn btn-primary",onClick:()=>x(!0),children:[e.jsx(G,{className:"w-4 h-4"})," New Account"]})]});return e.jsx(Q,{title:"Accounts",subtitle:i?void 0:`${r.length} account${r.length===1?"":"s"}`+(P?` · ${P} returning`:""),headerActions:Y,children:e.jsxs("div",{className:"crm-settings settings-shell p-6",children:[M&&e.jsxs("div",{className:"rounded-lg border border-(--line) p-4 mb-4",children:[e.jsx("h2",{className:"text-sm font-semibold mb-3",children:"New account"}),w&&e.jsx("div",{className:"msg msg-error mb-3",role:"alert",children:w}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[1fr_14rem_auto]",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-(--muted)",children:"Name"}),e.jsx("input",{autoFocus:!0,className:"field w-full mt-1",value:y,onChange:t=>g(t.target.value),onKeyDown:t=>{t.key==="Enter"&&E(),t.key==="Escape"&&x(!1)},placeholder:"Jane Doe"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-(--muted)",children:"Type"}),e.jsx("div",{className:"mt-1",children:e.jsx(L,{value:v,onValueChange:V,options:p,ariaLabel:"Account type"})})]}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void E(),disabled:_||!y.trim(),children:_?"Creatingâ¦":"Create"}),e.jsx("button",{type:"button",className:"btn",onClick:()=>x(!1),children:"Cancel"})]})]})]}),c==="referral_partner"&&e.jsx(ae,{}),i?e.jsx(O,{label:"Loading accountsâ¦",rows:8}):m?e.jsx(Z,{detail:m,onRetry:()=>void j()}):r.length===0?e.jsx(B,{title:n||c?"No accounts match those filters":"No accounts yet",sub:n||c?"Try a broader search or clear the type filter.":"Accounts are created automatically when you convert a lead into an opportunity.",icon:e.jsx(R,{className:"w-6 h-6"})}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-(--muted) border-b border-(--line)",children:[e.jsx("th",{scope:"col",className:"py-2 pr-4 font-medium",children:"Name"}),e.jsx("th",{scope:"col",className:"py-2 pr-4 font-medium",children:"Type"}),e.jsx("th",{scope:"col",className:"py-2 pr-4 font-medium text-right",children:"Episodes"}),e.jsx("th",{scope:"col",className:"py-2 pr-4 font-medium text-right",children:"Contacts"}),e.jsx("th",{scope:"col",className:"py-2 pr-4 font-medium",children:"Phone"}),e.jsx("th",{scope:"col",className:"py-2 pr-4 font-medium",children:"Location"}),e.jsx("th",{scope:"col",className:"py-2 w-8",children:e.jsx("span",{className:"sr-only",children:"Open"})})]})}),e.jsx("tbody",{children:r.map(t=>e.jsxs("tr",{onClick:()=>l(`${h}/accounts/${t.id}`),className:"border-b border-(--line) hover:bg-(--hover) cursor-pointer",children:[e.jsx("td",{className:"py-2.5 pr-4",children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[t.account_type==="patient"?e.jsx(J,{className:"w-4 h-4 text-(--muted)","aria-hidden":!0}):e.jsx(R,{className:"w-4 h-4 text-(--muted)","aria-hidden":!0}),e.jsx("span",{className:"font-medium",children:t.name})]})}),e.jsx("td",{className:"py-2.5 pr-4 text-(--muted)",children:t.account_type?K[t.account_type]??t.account_type:"â"}),e.jsx("td",{className:"py-2.5 pr-4 text-right tabular-nums",children:t.opportunity_count>1?e.jsx("span",{className:"badge",title:"Returning patient â more than one episode of care",children:t.opportunity_count}):t.opportunity_count}),e.jsx("td",{className:"py-2.5 pr-4 text-right tabular-nums",children:t.contact_count}),e.jsx("td",{className:"py-2.5 pr-4 text-(--muted)",children:t.phone||"â"}),e.jsx("td",{className:"py-2.5 pr-4 text-(--muted)",children:[t.billing_city,t.billing_state].filter(
1Boolean).join(", ")||"â"}),e.jsx("td",{className:"py-2.5 text-(--muted)",children:e.jsx(W,{className:"w-4 h-4","aria-hidden":!0})})]},t.id))})]})})]})})}export{Be 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.