PageSourceSearch

https://crewops.lovable.app/assets/Clients-DdZ8qLw6.js

js crewops.lovable.app collected 2026-10-03 03:21:22 UTC 39,631 bytes, 7 lines download raw bytes

1import{c as cs,ab as Me,I as fe,al as ge,r as N,ad as L,am as Q,j as e,B as S,s as ie,ba as Pe,a6 as H,m as ae,ap as me,aL as Ae,aO as Ke,aP as $e,aQ as Re,bb as ds,a0 as T,a1 as K,b2 as Ie,b3 as ms,P as pe,K as i,i as us,a as xs,D as hs,bc as Oe,bd as Qe,be as Ue,bf as Ve,T as je,H as ps,u as js,y as fs,aJ as gs,aq as vs,Q as oe,V as xe,Y as he,aX as ys,$ as ce,aK as bs,as as Y,at as G,au as X,av as ee,aw as C,aM as Ns,aN as _s,aV as qe,b5 as ke,aa as ws,aS as Te,aT as De,aU as Fe,M as Cs,bg as Ss}from"./index-B01jGDSO.js";import{T as qs,a as ks,b as de,c as O,d as Ts,e as A}from"./table-B_s0nExu.js";import{E as Ds,d as Fs}from"./csvExport-BwqVVIcg.js";import{E as Ls}from"./EntityFilePanel-CgSyZqzk.js";import{S as He}from"./sticky-note-of5i_-EC.js";import{A as Es}from"./arrow-up-right-DFPCC9HW.js";import{C as zs}from"./ClientEstimatesTab-BGZgcC1m.js";import{T as Ms,a as Ps,b as se,c as te}from"./tabs-DXmrEda4.js";import{R as As,a as Le}from"./radio-group-DQYqzodQ.js";import{R as Ee}from"./refresh-cw-DwcaIqPh.js";import{A as Ks}from"./archive-BS_SqSA5.js";import{U as $s}from"./user-check-LFi4Rd55.js";import{S as Rs}from"./square-pen-DJdQABvx.js";import"./useVaultFiles-C0QT3n5Z.js";import"./grid-3x3-CGKvexKP.js";import"./list-PSQKtgFH.js";import"./upload-DN3hAjDd.js";import"./download-BRkpldLd.js";import"./file-DCKgDxmT.js";import"./useOrgQuery-JRPR4imB.js";import"./estimator-constants-Du1pKv40.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Is=cs("ArrowDownLeft",[["path",{d:"M17 7 7 17",key:"15tmo1"}],["path",{d:"M17 17H7V7",key:"1org7z"}]]),Os={email:e.jsx(ie,{className:"h-4 w-4"}),sms:e.jsx(Pe,{className:"h-4 w-4"}),note:e.jsx(He,{className:"h-4 w-4"}),call:e.jsx(pe,{className:"h-4 w-4"})},Qs={email:"bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300",sms:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300",note:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/40 dark:text-yellow-300",call:"bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300"};function Us({customerId:j,customerEmail:f,customerName:p}){const{orgId:u}=Me(),{toast:E}=fe(),_=ge(),[h,D]=N.useState(null),[F,I]=N.useState(""),[c,v]=N.useState(""),{data:m=[],isLoading:$}=L({queryKey:["customer-comms",j],queryFn:async()=>{const{data:g,error:z}=await i.from("customer_communications").select("*, profiles:sent_by(full_name)").eq("customer_id",j).order("sent_at",{ascending:!1});if(z)throw z;return g||[]},enabled:!!j}),[r,o]=N.useState(!1),R=Q({mutationFn:async()=>{var y;const{data:g}=await i.auth.getUser(),z=(y=g.user)==null?void 0:y.id;let x=null;if(z){const{data:U}=await i.from("profiles").select("id").eq("user_id",z).single();x=(U==null?void 0:U.id)||null}if(h==="email"&&f){o(!0);const{data:U,error:B}=await i.functions.invoke("send-email",{body:{type:"follow_up",to:f,subject:F,body:c,data:{customer_id:j,client_name:p||"",sent_by:x,organization_id:u}}});if(o(!1),B)throw B;return}const{error:w}=await i.from("customer_communications").insert({organization_id:u,customer_id:j,type:h,direction:"outbound",subject:h==="email"?F:null,body:c,sent_by:x,status:h==="note"?"logged":"sent"});if(w)throw w},onSuccess:()=>{_.invalidateQueries({queryKey:["customer-comms",j]}),_.invalidateQueries({queryKey:["customer-last-comms"]}),E({title:h==="note"?"Note added":`${h==null?void 0:h.toUpperCase()} logged`}),W()},onError:g=>E({title:"Error",description:g.message,variant:"destructive"})});function M(g){D(g),I(""),v("")}function W(){D(null)}const re={email:"Log Email",sms:"Log SMS",note:"Add Note"};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>M("email"),children:[e.jsx(ie,{className:"h-3.5 w-3.5 mr-1.5"})," Send Email"]}),e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>M("sms"),children:[e.jsx(Pe,{className:"h-3.5 w-3.5 mr-1.5"})," Send SMS"]}),e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>M("note"),children:[e.jsx(He,{className:"h-3.5 w-3.5 mr-1.5"})," Add Note"]})]}),$?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(H,{className:"h-5 w-5 animate-spin"})}):m.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No communications yet."}):e.jsxs("div",{className:"relative space-y-0",children:[e.jsx("div",{className:"absolute left-[19px] top-2 bottom-2 w-px bg-border"}),m.map(g=>{var z;return e.jsxs("div",{className:"relative flex gap-3 py-3",children:[e.jsx("div",{className:`relative z-10 flex items-center justify-center h-10 w-10 rounded-full shrink-0 ${Qs[g.type]||"bg-muted text-muted-foreground"}`,children:Os[g.type]||e.jsx(ie,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(ae,{variant:"secondary",className:"text-[10px] px-1.5 py-0 capitalize",children:g.type}),g.direction==="inbound"?e.jsxs("span",{className:"text-[10px] text-muted-foreground flex items-center gap-0.5",children:[e.jsx(Is,{className:"h-2.5 w-2.5"})," Inbound"]}):e.jsxs("span",{className:"text-[10px] text-muted-foreground flex items-center gap-0.5",children:[e.jsx(Es,{className:"h-2.5 w-2.5"})," Outbound"]}
6),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:me(new Date(g.sent_at),"MMM d, yyyy · h:mm a")}),((z=g.profiles)==null?void 0:z.full_name)&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["by ",g.profiles.full_name]})]}),g.subject&&e.jsx("p",{className:"text-sm font-medium truncate",children:g.subject}),g.body&&e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap line-clamp-3",children:g.body})]})]},g.id)})]}),e.jsx(Ae,{open:!!h,onOpenChange:()=>W(),children:e.jsxs(Ke,{className:"sm:max-w-md",children:[e.jsxs($e,{children:[e.jsx(Re,{children:h?re[h]:""}),e.jsx(ds,{children:h==="note"?"Add an internal note for this customer.":`Log a ${h} communication.`})]}),e.jsxs("div",{className:"space-y-4",children:[h==="email"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"Subject"}),e.jsx(K,{value:F,onChange:g=>I(g.target.value),placeholder:"Email subject line"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:h==="note"?"Note":"Message"}),e.jsx(Ie,{value:c,onChange:g=>v(g.target.value),rows:5,placeholder:h==="note"?"Write your note…":"Message content…"})]})]}),e.jsxs(ms,{children:[e.jsx(S,{variant:"outline",onClick:W,children:"Cancel"}),e.jsxs(S,{onClick:()=>R.mutate(),disabled:!c.trim()||R.isPending||r,children:[(R.isPending||r)&&e.jsx(H,{className:"h-4 w-4 mr-2 animate-spin"}),h==="email"&&f?"Send Email":h==="note"?"Add Note":"Log & Send"]})]})]})})]})}function Vs({clientId:j}){const{data:f=[],isLoading:p}=L({queryKey:["client-estimates",j],queryFn:async()=>{const{data:c,error:v}=await i.from("estimates").select("id, project_number, project_name, status, estimate_date, estimate_items(unit_price, quantity)").eq("client_id",j).order("created_at",{ascending:!1});if(v)throw v;return c||[]}}),{data:u=[],isLoading:E}=L({queryKey:["client-jobs",j],queryFn:async()=>{const{data:c,error:v}=await i.from("jobs").select("id, job_number, project_name, status, scheduled_start").eq("client_id",j).order("created_at",{ascending:!1});if(v)throw v;return c||[]}}),{data:_=[],isLoading:h}=L({queryKey:["client-invoices",j],queryFn:async()=>{const{data:c,error:v}=await i.from("invoices").select("id, invoice_number, total, balance_due, status, issue_date").eq("client_id",j).order("created_at",{ascending:!1});if(v)throw v;return c||[]}});if(p||E||h)return e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})});const F=c=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(c),I=c=>(c.estimate_items||[]).reduce((v,m)=>v+(Number(m.unit_price)||0)*(Number(m.quantity)||0),0);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2 mb-2",children:[e.jsx(us,{className:"h-4 w-4"})," Estimates (",f.length,")"]}),f.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No estimates"}):e.jsx("div",{className:"space-y-1.5",children:f.map(c=>e.jsxs("div",{className:"flex items-center justify-between p-2 border rounded text-sm",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-mono text-xs mr-2",children:["#",c.project_number]}),e.jsx("span",{className:"font-medium",children:c.project_name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:F(I(c))}),e.jsx(ae,{variant:"outline",className:"text-[10px]",children:c.status})]})]},c.id))})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2 mb-2",children:[e.jsx(xs,{className:"h-4 w-4"})," Jobs (",u.length,")"]}),u.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No jobs"}):e.jsx("div",{className:"space-y-1.5",children:u.map(c=>e.jsxs("div",{className:"flex items-center justify-between p-2 border rounded text-sm",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-mono text-xs mr-2",children:["#",c.job_number]}),e.jsx("span",{className:"font-medium",children:c.project_name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c.scheduled_start&&e.jsx("span",{className:"text-xs text-muted-foreground",children:me(new Date(c.scheduled_start),"MMM d")}),e.jsx(ae,{variant:"outline",className:"text-[10px]",children:c.status})]})]},c.id))})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2 mb-2",children:[e.jsx(hs,{className:"h-4 w-4"})," Invoices (",_.length,")"]}),_.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No invoices"}):e.jsx("div",{className:"space-y-1.5",children:_.map(c=>e.jsxs("div",{className:"flex items-center justify-between p-2 border rounded text-sm",children:[e.jsx("div",{children:e.jsxs("span",{className:"font-mono text-xs mr-2",children:["INV-",String(c.invoice_number).padStart(4,"0")]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:F(Number(c.total))}),Number(c.balance_due)>0&&e.jsxs("span",{className:"text-xs text-destructive",children:[F(Number(c.balance_due))," due"]}),e.jsx(ae,{variant:"outline",className:"text-[10px]",children:c.status})]})]},c.id))})]})]})}function ze(j){return L({queryKey:["client-record-counts",j],queryFn:async()=>
6{if(!j)return{invoices:0,estimates:0,notes:0,leads:0,jobs:0};const[f,p,u,E,_]=await Promise.all([i.from("invoices").select("id",{count:"exact",head:!0}).eq("client_id",j),i.from("estimates").select("id",{count:"exact",head:!0}).eq("client_id",j),i.from("activities").select("id",{count:"exact",head:!0}).eq("client_id",j),i.from("leads").select("id",{count:"exact",head:!0}).eq("converted_to_client_id",j),i.from("jobs").select("id",{count:"exact",head:!0}).eq("client_id",j)]);return{invoices:f.count||0,estimates:p.count||0,notes:u.count||0,leads:E.count||0,jobs:_.count||0}},enabled:!!j})}function Hs({open:j,onOpenChange:f,clientA:p,clientB:u,orgId:E}){const{toast:_}=fe(),h=ge(),[D,F]=N.useState("A"),{data:I}=ze(p==null?void 0:p.id),{data:c}=ze(u==null?void 0:u.id),v=Q({mutationFn:async()=>{if(!p||!u)throw new Error("Missing clients");const r=D==="A"?p.id:u.id,o=D==="A"?u.id:p.id,R=D==="A"?p.name:u.name;await Promise.all([i.from("invoices").update({client_id:r}).eq("client_id",o),i.from("estimates").update({client_id:r}).eq("client_id",o),i.from("activities").update({client_id:r}).eq("client_id",o),i.from("leads").update({converted_to_client_id:r}).eq("converted_to_client_id",o),i.from("jobs").update({client_id:r}).eq("client_id",o),i.from("contracts").update({client_id:r}).eq("client_id",o),i.from("customer_communications").update({customer_id:r}).eq("customer_id",o)]);const{error:M}=await i.from("clients").update({status:"archived",merged_into_id:r,updated_at:new Date().toISOString()}).eq("id",o);if(M)throw M;return R},onSuccess:r=>{h.invalidateQueries({queryKey:["clients"]}),_({title:"Records merged",description:`${r}'s history has been combined.`}),f(!1)},onError:r=>_({title:"Merge failed",description:r.message,variant:"destructive"})}),m=Q({mutationFn:async()=>{if(!p||!u||!E)throw new Error("Missing data");const{data:{user:r}}=await i.auth.getUser(),{error:o}=await i.from("duplicate_dismissals").insert({tenant_id:E,client_id_a:p.id,client_id_b:u.id,dismissed_by:(r==null?void 0:r.id)||null});if(o)throw o},onSuccess:()=>{h.invalidateQueries({queryKey:["duplicate-dismissals"]}),_({title:"Dismissed",description:"These records will no longer be flagged as duplicates."}),f(!1)},onError:r=>_({title:"Error",description:r.message,variant:"destructive"})});if(!p||!u)return null;const $=(r,o,R)=>e.jsxs("div",{className:"flex-1 space-y-2 min-w-0",children:[e.jsx("p",{className:"text-xs font-bold text-muted-foreground uppercase tracking-wider",children:R}),e.jsx("p",{className:"font-semibold text-sm truncate",children:r.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r.phone||"—"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r.email||"—"}),r.city&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[r.city,", ",r.state]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Added: ",me(new Date(r.created_at),"MMM d, yyyy")]}),e.jsxs("div",{className:"pt-1 space-y-0.5 text-xs",children:[e.jsxs("p",{children:[(o==null?void 0:o.invoices)??"..."," invoice",((o==null?void 0:o.invoices)??0)!==1?"s":""]}),e.jsxs("p",{children:[(o==null?void 0:o.estimates)??"..."," estimate",((o==null?void 0:o.estimates)??0)!==1?"s":""]}),e.jsxs("p",{children:[(o==null?void 0:o.jobs)??"..."," job",((o==null?void 0:o.jobs)??0)!==1?"s":""]})]})]});return e.jsx(Oe,{open:j,onOpenChange:f,children:e.jsxs(Qe,{className:"sm:max-w-md overflow-y-auto",children:[e.jsx(Ue,{children:e.jsxs(Ve,{className:"flex items-center gap-2 text-amber-600 dark:text-amber-400",children:[e.jsx(je,{className:"h-5 w-5"}),"Possible Duplicate Found"]})}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"These two records may be the same customer. Review and merge or dismiss."}),e.jsxs("div",{className:"flex gap-4 mt-5 border border-border rounded-lg p-4 bg-muted/30",children:[$(p,I,"Record A"),e.jsx("div",{className:"w-px bg-border"}),$(u,c,"Record B")]}),e.jsxs("div",{className:"mt-5 space-y-3",children:[e.jsx("p",{className:"text-sm font-semibold",children:"Keep as primary:"}),e.jsxs(As,{value:D,onValueChange:r=>F(r),className:"flex gap-6",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Le,{value:"A",id:"keep-a"}),e.jsxs(T,{htmlFor:"keep-a",className:"text-sm",children:["A — ",p.name]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Le,{value:"B",id:"keep-b"}),e.jsxs(T,{htmlFor:"keep-b",className:"text-sm",children:["B — ",u.name]})]})]})]}),e.jsxs("div",{className:"mt-5 space-y-1.5 text-xs text-muted-foreground",children:[e.jsx("p",{className:"font-semibold text-foreground text-sm",children:"What happens when you merge:"}),["All invoices move to primary","All estimates move to primary","All jobs move to primary","All notes & activities move to primary","Duplicate record 
6is archived (not deleted — preserved)"].map(r=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ps,{className:"h-3.5 w-3.5 text-primary shrink-0"}),e.jsx("span",{children:r})]},r))]}),e.jsxs("div",{className:"flex gap-3 mt-6",children:[e.jsxs(S,{className:"flex-1",onClick:()=>v.mutate(),disabled:v.isPending,children:[v.isPending?e.jsx(H,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Merge Records"]}),e.jsx(S,{variant:"outline",className:"flex-1",onClick:()=>m.mutate(),disabled:m.isPending,children:"Not a Dup"})]})]})})}function ht(){const j=js(),{toast:f}=fe(),{role:p}=fs(),u=ge(),{connection:E,syncCustomers:_,isSyncing:h}=gs(),{orgId:D}=Me(),[F,I]=N.useState(""),[c,v]=N.useState(!1),[m,$]=N.useState(null),[r,o]=N.useState(new Set),[R,M]=N.useState(!1),[W,re]=N.useState(null),[g,z]=N.useState(null),[x,w]=N.useState({name:"",company:"",email:"",phone:"",address:"",city:"",state:"WI",zip:"",notes:"",source:"",assigned_to:""}),{data:y=[],isLoading:U}=L({queryKey:["clients"],queryFn:async()=>{const{data:s,error:a}=await i.from("clients").select("*, profiles:assigned_to(id, full_name, user_id)").order("name");if(a)throw a;return s.map(t=>({...t,status:t.status||"active"}))}}),{data:B={}}=L({queryKey:["customer-last-comms"],queryFn:async()=>{const{data:s,error:a}=await i.from("customer_communications").select("customer_id, sent_at").order("sent_at",{ascending:!1});if(a)throw a;const t={};for(const n of s||[])t[n.customer_id]||(t[n.customer_id]=n.sent_at);return t}}),{data:We=[]}=L({queryKey:["profiles-for-assignment"],queryFn:async()=>{const{data:s,error:a}=await i.from("profiles").select("id, full_name, user_id").order("full_name");if(a)throw a;return s},enabled:p==="admin"});L({queryKey:["service-zones"],queryFn:async()=>{const{data:s,error:a}=await i.from("service_zones").select("*").eq("is_active",!0).order("sort_order");if(a)throw a;return s||[]}});const{data:ve=[]}=L({queryKey:["lead-sources"],queryFn:async()=>{const{data:s,error:a}=await i.from("lead_sources").select("*").eq("is_active",!0).order("sort_order");if(a)throw a;return s||[]}}),{data:ye=[]}=L({queryKey:["all-client-labels"],queryFn:async()=>{const{data:s,error:a}=await i.from("client_labels").select("client_id, lead_labels:label_id(name, color)");if(a)throw a;return s||[]}}),Be=N.useMemo(()=>{var a;const s={};for(const t of ye)t.lead_labels&&(s[a=t.client_id]??(s[a]=[])).push(t.lead_labels);return s},[ye]),{data:be=[]}=L({queryKey:["duplicate-dismissals",D],queryFn:async()=>{if(!D)return[];const{data:s,error:a}=await i.from("duplicate_dismissals").select("client_id_a, client_id_b").eq("tenant_id",D);return a?[]:s||[]},enabled:!!D}),Ze=(s,a)=>be.some(t=>t.client_id_a===s&&t.client_id_b===a||t.client_id_a===a&&t.client_id_b===s),{duplicateIds:Je,duplicatePairs:V}=N.useMemo(()=>{const s=new Set,a=[],t={},n={},d={};for(const l of y)if((l.status||"active")!=="archived"){if(l.phone){const b=l.phone.replace(/\D/g,"");b.length>=7&&(t[b]??(t[b]=[])).push(l.id)}if(l.email){const b=l.email.toLowerCase().trim();(n[b]??(n[b]=[])).push(l.id)}if(l.name&&l.city){const b=`${l.name.toLowerCase().trim()}|${l.city.toLowerCase().trim()}`;(d[b]??(d[b]=[])).push(l.id)}}const q=(l,b)=>{if(!(l.length<2))for(let k=0;k<l.length;k++)for(let P=k+1;P<l.length;P++)Ze(l[k],l[P])||(s.add(l[k]),s.add(l[P]),a.find(le=>le.a===l[k]&&le.b===l[P]||le.a===l[P]&&le.b===l[k])||a.push({a:l[k],b:l[P],reason:b}))};for(const l of Object.values(t))q(l,"phone");for(const l of Object.values(n))q(l,"email");for(const l of Object.values(d))q(l,"name+city");return{duplicateIds:s,duplicatePairs:a}},[y,be]),Ye=s=>{const a=V.find(d=>d.a===s||d.b===s);if(!a)return;const t=y.find(d=>d.id===a.a),n=y.find(d=>d.id===a.b);t&&n&&(re(t),z(n),M(!0))},Ge=Q({mutationFn:async s=>{let a=s.assigned_to||null;if(!a&&p==="manager"){const{data:{user:n}}=await i.auth.getUser();if(n){const{data:d}=await i.from("profiles").select("id").eq("user_id",n.id).single();a=(d==null?void 0:d.id)||null}}const{error:t}=await i.from("clients").insert({name:s.name,company:s.company||null,email:s.email||null,phone:s.phone||null,address:s.address||null,city:s.city||null,state:s.state||null,zip:s.zip||null,notes:s.notes||null,source:s.source||null,assigned_to:a});if(t)throw t},onSuccess:()=>
6{u.invalidateQueries({queryKey:["clients"]}),f({title:"Customer created successfully"}),v(!1),we()},onError:s=>{f({title:"Error creating customer",description:s.message,variant:"destructive"})}}),Xe=Q({mutationFn:async({id:s,data:a})=>{const t={name:a.name,company:a.company||null,email:a.email||null,phone:a.phone||null,address:a.address||null,city:a.city||null,state:a.state||null,zip:a.zip||null,notes:a.notes||null,source:a.source||null};p==="admin"&&(t.assigned_to=a.assigned_to||null);const{error:n}=await i.from("clients").update(t).eq("id",s);if(n)throw n},onSuccess:()=>{u.invalidateQueries({queryKey:["clients"]}),f({title:"Customer updated successfully"}),$(null)},onError:s=>{f({title:"Error updating customer",description:s.message,variant:"destructive"})}}),es=Q({mutationFn:async s=>{const[a,t,n,d]=await Promise.all([i.from("estimates").select("id",{count:"exact",head:!0}).eq("client_id",s),i.from("invoices").select("id",{count:"exact",head:!0}).eq("client_id",s),i.from("leads").select("id",{count:"exact",head:!0}).eq("converted_to_client_id",s),i.from("jobs").select("id",{count:"exact",head:!0}).eq("client_id",s)]),q=[];if((a.count||0)>0&&q.push(`${a.count} estimate(s)`),(t.count||0)>0&&q.push(`${t.count} invoice(s)`),(n.count||0)>0&&q.push(`${n.count} lead(s)`),(d.count||0)>0&&q.push(`${d.count} job(s)`),q.length>0)throw new Error(`FK_LINKED:${q.join(", ")}`);await Promise.all([i.from("activities").delete().eq("client_id",s),i.from("contracts").delete().eq("client_id",s),i.from("customer_communications").delete().eq("customer_id",s),i.from("customer_group_members").delete().eq("client_id",s),i.from("customer_messages").delete().eq("customer_id",s)]);const{error:l}=await i.from("clients").delete().eq("id",s);if(l)throw l},onSuccess:()=>{u.invalidateQueries({queryKey:["clients"]}),f({title:"Customer deleted"}),$(null)},onError:s=>{const a=(s==null?void 0:s.message)||"";if(a.startsWith("FK_LINKED:")){const t=a.replace("FK_LINKED:","");f({title:"Cannot delete customer",description:`This customer has linked records (${t}) and cannot be deleted. Remove their estimates and invoices first, or use Archive instead.`,variant:"destructive"})}else f({title:"Error deleting customer",description:a,variant:"destructive"})}}),Ne=Q({mutationFn:async s=>{for(const a of s){const{error:t}=await i.from("clients").update({status:"archived",updated_at:new Date().toISOString()}).eq("id",a);if(t)throw t}},onSuccess:()=>{u.invalidateQueries({queryKey:["clients"]}),o(new Set),f({title:`${r.size} customer(s) archived`})},onError:s=>f({title:"Error archiving",description:s.message,variant:"destructive"})}),_e=Q({mutationFn:async s=>{const a=[];for(const t of s){const n=y.find(d=>d.id===t);try{const[d,q,l,b]=await Promise.all([i.from("estimates").select("id",{count:"exact",head:!0}).eq("client_id",t),i.from("invoices").select("id",{count:"exact",head:!0}).eq("client_id",t),i.from("leads").select("id",{count:"exact",head:!0}).eq("converted_to_client_id",t),i.from("jobs").select("id",{count:"exact",head:!0}).eq("client_id",t)]),k=[];if((d.count||0)>0&&k.push(`${d.count} estimate(s)`),(q.count||0)>0&&k.push(`${q.count} invoice(s)`),(l.count||0)>0&&k.push(`${l.count} lead(s)`),(b.count||0)>0&&k.push(`${b.count} job(s)`),k.length>0){a.push({id:t,name:(n==null?void 0:n.name)||t,ok:!1,reason:k.join(", ")});continue}await Promise.all([i.from("activities").delete().eq("client_id",t),i.from("contracts").delete().eq("client_id",t),i.from("customer_communications").delete().eq("customer_id",t),i.from("customer_group_members").delete().eq("client_id",t),i.from("customer_messages").delete().eq("customer_id",t)]);const{error:P}=await i.from("clients").delete().eq("id",t);if(P)throw P;a.push({id:t,name:(n==null?void 0:n.name)||t,ok:!0})}catch(d){a.push({id:t,name:(n==null?void 0:n.name)||t,ok:!1,reason:(d==null?void 0:d.message)||"Unknown error"})}}return a},onSuccess:s=>{u.invalidateQueries({queryKey:["clients"]}),o(new Set);const a=s.filter(n=>n.ok).length,t=s.filter(n=>!n.ok);if(t.length===0)f({title:`${a} customer(s) deleted`});else{const n=t.map(d=>`${d.name}: ${d.reason}`).join(`
7`);f({title:`${a} deleted, ${t.length} blocked`,description:n,variant:t.length>0?"destructive":"default"})}},onError:s=>f({title:"Bulk delete error",description:s.message,variant:"destructive"})}),we=()=>
7{w({name:"",company:"",email:"",phone:"",address:"",city:"",state:"WI",zip:"",notes:"",source:"",assigned_to:""})},ss=s=>{w({name:s.name,company:s.company||"",email:s.email||"",phone:s.phone||"",address:s.address||"",city:s.city||"",state:s.state||"WI",zip:s.zip||"",notes:s.notes||"",source:s.source||"",assigned_to:s.assigned_to||""}),$(s)},[ue,ts]=N.useState("all"),[Z,as]=N.useState("all"),[Ce,is]=N.useState("newest"),[ne,rs]=N.useState("all"),ns=y.filter(s=>(s.status||"active")!=="archived").length,ls=y.filter(s=>(s.status||"active")==="active"&&(s.email||s.phone)).length,os=y.filter(s=>(s.status||"active")==="archived").length,J=y.filter(s=>{var l,b;const a=s.name.toLowerCase().includes(F.toLowerCase())||((l=s.company)==null?void 0:l.toLowerCase().includes(F.toLowerCase()))||((b=s.email)==null?void 0:b.toLowerCase().includes(F.toLowerCase())),t=ue==="all"||(s.source||"")===ue,n=Z==="all"||Z==="residential"&&!s.company||Z==="commercial"&&!!s.company||Z==="from_leads"&&(s.source||"").toLowerCase().includes("lead"),d=s.status||"active",q=ne==="all"?d!=="archived":ne==="active"?d==="active"&&(s.email||s.phone):ne==="archived"?d==="archived":!0;return a&&t&&n&&q}).sort((s,a)=>{switch(Ce){case"name_az":return s.name.localeCompare(a.name);case"name_za":return a.name.localeCompare(s.name);case"email_az":return(s.email||"").localeCompare(a.email||"");case"email_za":return(a.email||"").localeCompare(s.email||"");case"oldest":return new Date(s.created_at).getTime()-new Date(a.created_at).getTime();case"newest":default:return new Date(a.created_at).getTime()-new Date(s.created_at).getTime()}}),Se=({onSubmit:s,submitLabel:a})=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"name",children:"Contact Name *"}),e.jsx(K,{id:"name",value:x.name,onChange:t=>w({...x,name:t.target.value}),placeholder:"John Smith",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"company",children:"Company"}),e.jsx(K,{id:"company",value:x.company,onChange:t=>w({...x,company:t.target.value}),placeholder:"Smith Properties LLC"})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"email",children:"Email"}),e.jsx(K,{id:"email",type:"email",value:x.email,onChange:t=>w({...x,email:t.target.value}),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"phone",children:"Phone"}),e.jsx(K,{id:"phone",value:x.phone,onChange:t=>w({...x,phone:t.target.value}),placeholder:"(555) 123-4567"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"address",children:"Address"}),e.jsx(K,{id:"address",value:x.address,onChange:t=>w({...x,address:t.target.value}),placeholder:"123 Main Street"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"city",children:"City"}),e.jsx(K,{id:"city",value:x.city,onChange:t=>w({...x,city:t.target.value}),placeholder:"Milwaukee"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"state",children:"State"}),e.jsx(K,{id:"state",value:x.state,onChange:t=>w({...x,state:t.target.value}),placeholder:"WI"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"zip",children:"ZIP"}),e.jsx(K,{id:"zip",value:x.zip,onChange:t=>w({...x,zip:t.target.value}),placeholder:"53202"})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"source",children:"Lead Source"}),e.jsxs(Y,{value:x.source||"__none__",onValueChange:t=>w({...x,source:t==="__none__"?"":t}),children:[e.jsx(G,{children:e.jsx(X,{placeholder:"Select source"})}),e.jsxs(ee,{children:[e.jsx(C,{value:"__none__",children:"None"}),ve.map(t=>e.jsx(C,{value:t.name,children:t.name},t.id))]})]})]}),p==="admin"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"assigned_to",children:"Assigned To"}),e.jsxs(Y,{value:x.assigned_to||"__none__",onValueChange:t=>w({...x,assigned_to:t==="__none__"?"":t}),children:[e.jsx(G,{children:e.jsx(X,{placeholder:"Select team member"})}),e.jsxs(ee,{children:[e.jsx(C,{value:"__none__",children:"Unassigned"}),We.map(t=>e.jsx(C,{value:t.id,children:t.full_name||"Unnamed User"},t.id))]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"notes",children:"Notes"}),e.jsx(Ie,{id:"notes",value:x.notes,onChange:t=>w({...x,notes:t.target.value}),placeholder:"Additional notes about this customer...",rows:3})]}),e.jsx(S,{className:"w-full",onClick:s,disabled:!x.name.trim(),children:a})]});return e.jsx(vs,{title:"My Customers",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(oe,{children:[e.jsxs(xe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(he,{className:"text-sm font-medium",children:"Total Customers"}),e.jsx(ys,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(ce,{children:e.jsx("div",{className:"text-2xl font-bold",children:y.length})})]}),e.jsxs(oe,{children:[e.jsxs(xe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(he,{className:"text-sm font-medium",children:"With Email"}),e.jsx(ie,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(ce,{children:e.jsx("div",{className:"text-2xl font-bold",children:y.filter(s=>s.email).length})})]}),e.jsxs(oe,{children:[e.jsxs(xe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(he,{className:"text-sm font-medium",children:"With Phone"}),e.jsx(pe,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(ce,{children:e.jsx("div",{className:"text-2xl font-bold",children:y.filter(s=>s.phone).length})})]})]}),V.length>0&&e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 bg-amber-50 dark:bg-amber-950/20 border border-amber-200 dark:border-amber-800 rounded-lg text-sm",children:[e.jsx(je,{className:"h-4 w-4 text-amber-600 dar
7k:text-amber-400 shrink-0"}),e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:V.length})," possible duplicate customer",V.length!==1?"s":""," found"]}),e.jsx("button",{className:"ml-1 text-amber-700 dark:text-amber-300 underline hover:no-underline text-sm font-medium",onClick:()=>{if(V.length>0){const s=V[0],a=y.find(n=>n.id===s.a),t=y.find(n=>n.id===s.b);a&&t&&(re(a),z(t),M(!0))}},children:"— Review"})]}),e.jsx("div",{className:"flex items-center gap-1 border-b",children:[{key:"all",label:"All",count:ns},{key:"active",label:"Active",count:ls},{key:"archived",label:"Archived",count:os}].map(s=>e.jsxs("button",{onClick:()=>rs(s.key),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${ne===s.key?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:[s.label," ",e.jsx(ae,{variant:"secondary",className:"ml-1 text-xs",children:s.count})]},s.key))}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 flex-wrap",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-sm",children:[e.jsx(bs,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(K,{placeholder:"Search customers...",value:F,onChange:s=>I(s.target.value),className:"pl-9"})]}),e.jsxs(Y,{value:Z,onValueChange:as,children:[e.jsx(G,{className:"w-[160px]",children:e.jsx(X,{placeholder:"Customer Type"})}),e.jsxs(ee,{className:"bg-popover z-50",children:[e.jsx(C,{value:"all",children:"All Types"}),e.jsx(C,{value:"residential",children:"Residential"}),e.jsx(C,{value:"commercial",children:"Commercial"}),e.jsx(C,{value:"from_leads",children:"From Leads"})]})]}),e.jsxs(Y,{value:ue,onValueChange:ts,children:[e.jsx(G,{className:"w-[160px]",children:e.jsx(X,{placeholder:"All Sources"})}),e.jsxs(ee,{className:"bg-popover z-50",children:[e.jsx(C,{value:"all",children:"All Sources"}),ve.map(s=>e.jsx(C,{value:s.name,children:s.name},s.id))]})]}),e.jsxs(Y,{value:Ce,onValueChange:is,children:[e.jsx(G,{className:"w-[180px]",children:e.jsx(X,{placeholder:"Sort by"})}),e.jsxs(ee,{className:"bg-popover z-50",children:[e.jsx(C,{value:"newest",children:"Date Added: Newest"}),e.jsx(C,{value:"oldest",children:"Date Added: Oldest"}),e.jsx(C,{value:"name_az",children:"Name: A to Z"}),e.jsx(C,{value:"name_za",children:"Name: Z to A"}),e.jsx(C,{value:"email_az",children:"Email: A to Z"}),e.jsx(C,{value:"email_za",children:"Email: Z to A"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ds,{label:"Export Customers",onExport:async()=>{if(!y.length)throw new Error("No customers to export");const s=["Name","Company","Email","Phone","Address","City","State","ZIP","Source","Notes"],a=y.map(t=>[t.name,t.company||"",t.email||"",t.phone||"",t.address||"",t.city||"",t.state||"",t.zip||"",t.source||"",t.notes||""]);Fs(s,a,`clients-report_${new Date().toISOString().slice(0,10)}.csv`)}}),E&&e.jsxs(e.Fragment,{children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>
7{_("push",y),u.invalidateQueries({queryKey:["clients"]})},disabled:h,children:[h?e.jsx(H,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Ee,{className:"mr-2 h-4 w-4"}),"Push to QB"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>{_("pull"),u.invalidateQueries({queryKey:["clients"]})},disabled:h,children:[h?e.jsx(H,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Ee,{className:"mr-2 h-4 w-4"}),"Pull from QB"]})]}),e.jsxs(Ae,{open:c,onOpenChange:v,children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(S,{onClick:we,children:[e.jsx(_s,{className:"mr-2 h-4 w-4"}),"Add Customer"]})}),e.jsxs(Ke,{className:"max-w-lg",children:[e.jsx($e,{children:e.jsx(Re,{children:"Add New Customer"})}),e.jsx(Se,{onSubmit:()=>Ge.mutate(x),submitLabel:"Create Customer"})]})]})]})]}),r.size>0&&e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 bg-accent/50 border border-border rounded-lg",children:[e.jsxs("span",{className:"text-sm font-medium text-foreground",children:[r.size," customer",r.size>1?"s":""," selected"]}),e.jsx("div",{className:"flex-1"}),e.jsxs(S,{size:"sm",variant:"outline",className:"text-xs",onClick:()=>Ne.mutate(Array.from(r)),disabled:Ne.isPending,children:[e.jsx(Ks,{className:"w-3.5 h-3.5 mr-1.5"})," Archive Selected"]}),e.jsxs(S,{size:"sm",variant:"destructive",className:"text-xs",onClick:()=>_e.mutate(Array.from(r)),disabled:_e.isPending,children:[e.jsx(qe,{className:"w-3.5 h-3.5 mr-1.5"})," Delete Selected"]}),e.jsx(S,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>o(new Set),children:"Clear"})]}),e.jsx(oe,{children:e.jsx(ce,{className:"p-0",children:e.jsxs(qs,{children:[e.jsx(ks,{children:e.jsxs(de,{children:[e.jsx(O,{className:"w-10",children:e.jsx(ke,{checked:J.length>0&&J.every(s=>r.has(s.id)),onCheckedChange:s=>{o(s?new Set(J.map(a=>a.id)):new Set)}})}),e.jsx(O,{children:"Name"}),e.jsx(O,{children:"Company"}),e.jsx(O,{children:"Contact"}),e.jsx(O,{children:"Location"}),p==="admin"&&e.jsx(O,{children:"Assigned To"}),e.jsx(O,{children:"Last Comm"}),e.jsx(O,{className:"w-20"})]})}),e.jsx(Ts,{children:U?e.jsx(de,{children:e.jsx(A,{colSpan:p==="admin"?8:7,className:"text-center py-8",children:"Loading customers..."})}):J.length===0?e.jsx(de,{children:e.jsx(A,{colSpan:p==="admin"?8:7,className:"text-center py-8 text-muted-foreground",children:"No customers found. Add your first customer to get started."})}):J.map(s=>e.jsxs(de,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>j(`/clients/${s.id}`),children:[e.jsx(A,{onClick:a=>a.stopPropagation(),children:e.jsx(ke,{checked:r.has(s.id),onCheckedChange:a=>{const t=new Set(r);a?t.add(s.id):t.delete(s.id),o(t)}})}),e.jsx(A,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ws,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:s.name}),(Be[s.id]||[]).map((a,t)=>e.jsxs(Te,{children:[e.jsx(De,{asChild:!0,children:e.jsx("div",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{backgroundColor:a.color}})}),e.jsx(Fe,{children:a.name})]},t)),Je.has(s.id)&&e.jsxs(Te,{children:[e.jsx(De,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-bold bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400 hover:bg-amber-200 dark:hover:bg-amber-900/50 transition-colors",onClick:a=>{a.stopPropagation(),Ye(s.id)},children:[e.jsx(je,{className:"w-3 h-3 mr-0.5"})," DUP"]})}),e.jsx(Fe,{children:"Possible duplicate detected — click to review"})]})]})}),e.jsx(A,{children:s.company||"—"}),e.jsx(A,{children:e.jsxs("div",{className:"space-y-1",children:[s.email&&e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(ie,{className:"h-3 w-3"}),s.email]}),s.phone&&e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(pe,{className:"h-3 w-3"}),s.phone]})]})}),e.jsx(A,{children:s.city&&s.state?e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(Cs,{className:"h-3 w-3"}),s.city,", ",s.state]}):"—"}),p==="admin"&&e.jsx(A,{children:s.profiles?e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx($s,{className:"h-3 w-3 text-primary"}),s.profiles.full_name||"Unnamed"]}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"Unassigned"})}),e.jsx(A,{children:B[s.id]?e.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[e.jsx(Ss,{className:"h-3 w-3"}),me(new Date(B[s.id]),"MMM d")]}):e.jsx("span",{className:"text-muted-foreground text-xs",children:"—"})}),e.jsx(A,{children:e.jsx(S,{variant:"ghost",size:"icon",onClick:a=>{a.stopPropagation(),ss(s)},children:e.jsx(Rs,{className:"h-4 w-4"})})})]},s.id))})]})})}),e.jsx(Oe,{open:!!m,onOpenChange:()=>$(null),children:e.jsxs(Qe,{className:"sm:max-w-xl overflow-y-auto",children:[e.jsx(Ue,{children:e.jsx(Ve,{children:m==null?void 0:m.name})}),e.jsx("div",{className:"mt-4",children:e.jsxs(Ms,{defaultValue:"details",children:[e.jsxs(Ps,{className:"w-full",children:[e.jsx(se,{value:"details",className:"flex-1",children:"Details"}),e.jsx(se,{value:"estimates",className:"flex-1",children:"Estimates"}),e.jsx(se,{value:"history",className:"flex-1",children:"History"}),e.jsx(se,{value:"comms",className:"flex-1",children:"Comms"}),e.jsx(se,{value:"files",className:"flex-1",children:"Files"})]}),e.jsxs(te,{value:"details",className:"mt-4 space-y-4",children:[e.jsx(Se,{onSubmit:()=>m&&Xe.mutate({id:m.id,data:x}),submitLabel:"Save Changes"}),e.jsxs(S,{variant:"destructive",className:"w-full",onClick:()=>m&&es.mutate(m.id),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"}),"Delete Customer"]})]}),e.jsx(te,{value:"estimates",className:"mt-4",children:m&&e.jsx(zs,{clientId:m.id,clientName:m.name,clientAddress:m.address,clientPhone:m.phone,clientEmail:m.email})}),e.jsx(te,{value:"history",className:"mt-4",children:m&&e.jsx(Vs,{clientId:m.id})}),e.jsx(te,{value:"comms",className:"mt-4",children:m&&e.jsx(Us,{customerId:m.id,customerEmail:m.email||void 0,customerName:m.name})}),e.jsx(te,{value:"files",className:"mt-4",children:m&&e.jsx(Ls,{entityType:"client",entityId:m.id,title:"Customer Files"})})]})})]})}),e.jsx(Hs,{open:R,onOpenChange:M,clientA:W,clientB:g,orgId:D})]})})}export{ht 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.