1import{r as _,a as S,N as A,j as e,B as x,L as m,I as T,p as d,v as c}from"./index-q2YJS4pS.js";import{u as J}from"./useQuery-CAJd21JB.js";import{u as j}from"./useMutation-D4rVg8sF.js";import{M,A as z,b as B,c as P}from"./MainLayout-DsGfQDmV.js";import{C as f,a as y}from"./card-DWhzDoLf.js";import{B as p}from"./badge-DlXuaCNn.js";import{T as O,a as E,b as g,c as N}from"./tabs-zuRHd0ne.js";import{S as G}from"./SyncJobsPanel-BDOYNIJo.js";import{R as v}from"./refresh-cw-C5vbiSDC.js";import{U as Q,B as Y}from"./dropdown-menu-BWCTFs0e.js";import{A as $}from"./activity-BFFw8Am8.js";import{S as U}from"./search-BkUO0lyx.js";import{M as V}from"./mail-BCFcprQQ.js";import{P as F}from"./phone-BZ0tgbIH.js";import{V as R}from"./video-Xz3R8AK8.js";import{M as X}from"./mail-open-Bz8WJPEQ.js";import{a as Z}from"./index-CH7RrW7d.js";import"./briefcase-CFgDSMv1.js";import"./send-DbNDsGrE.js";import"./index-doeUptMI.js";import"./table-D_oFBkTS.js";import"./clock-B9AOh9rD.js";import"./circle-check-4JL0f7Lk.js";import"./circle-x-cVoCa6gt.js";import"./format-BFJAwhGe.js";function ge(){const[r,w]=_.useState(""),k=S(),u=A(),{data:n,isLoading:I}=J({queryKey:["people",r],queryFn:async()=>{let s=d.from("people").select("*").order("last_synced_at",{ascending:!1}).limit(500);if(r.trim()){const i=`%${r.trim()}%`;s=s.or(`first_name.ilike.${i},last_name.ilike.${i},company_name.ilike.${i},email_addresses.cs.{${r.trim()}}`)}const{data:a,error:t}=await s;if(t)throw t;return a}}),o=j({mutationFn:async()=>{var a;const s=await fetch("https://lojmvxgssletvnpdlvuw.supabase.co/functions/v1/sync-attio-people",{method:"POST",headers:{Authorization:`Bearer ${(a=(await d.auth.getSession()).data.session)==null?void 0:a.access_token}`,apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imxvam12eGdzc2xldHZucGRsdnV3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzA0NzkwMjYsImV4cCI6MjA4NjA1NTAyNn0.PTKOUCvWBkgQkTYTGQrgMX7JTpiOmtuE6ie4GYkBCS4","Content-Type":"application/json"}});if(!s.ok){const t=await s.json();throw new Error(t.error||"Sync failed")}return s.json()},onSuccess:s=>{c.success(`Synced ${s.upserted} people from Attio`),u.invalidateQueries({queryKey:["people"]})},onError:s=>{c.error(s.message)}}),l=j({mutationFn:async()=>{var a;const s=await fetch("https://lojmvxgssletvnpdlvuw.supabase.co/functions/v1/sync-people-counts",{method:"POST",headers:{Authorization:`Bearer ${(a=(await d.auth.getSession()).data.session)==null?void 0:a.access_token}`,apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imxvam12eGdzc2xldHZucGRsdnV3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzA0NzkwMjYsImV4cCI6MjA4NjA1NTAyNn0.PTKOUCvWBkgQkTYTGQrgMX7JTpiOmtuE6ie4GYkBCS4","Content-Type":"application/json"}});if(!s.ok){const t=await s.json();throw new Error(t.error||"Sync counts failed")}return s.json()},onSuccess:s=>{c.success(`Updated counts for ${s.updated} people`),u.invalidateQueries({queryKey:["people"]})},onError:s=>{c.error(s.message)}}),C=s=>{var i,h;const a=((i=s.first_name)==null?void 0:i[0])||"",t=((h=s.last_name)==null?void 0:h[0])||"";return(a+t).toUpperCase()||"?"},b=s=>{var t;const a=[s.first_name,s.last_name].filter(Boolean);return a.length>0?a.join(" "):((t=s.email_addresses)==null?void 0:t[0])||"Unknown"};return e.jsx(M,{children:e.jsxs("div",{className:"container py-8 max-w-5xl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"People"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Contacts synced from Attio"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>l.mutate(),disabled:l.isPending,children:[l.isPending?e.jsx(m,{className:"h-4 w-4 mr-1.5 animate-spin"}):e.jsx(v,{className:"h-4 w-4 mr-1.5"}),"Sync Counts"]}),e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>o.mutate(),disabled:o.isPending,children:[o.isPending?e.jsx(m,{className:"h-4 w-4 mr-1.5 animate-spin"}):e.jsx(v,{className:"h-4 w-4 mr-1.5"}),"Sync from Attio"]})]})]}),e.jsxs(O,{defaultValue:"people",className:"space-y-4",children:[e.jsxs(E,{children:[e.jsxs(g,{value:"people",className:"gap-1.5",children:[e.jsx(Q,{className:"h-4 w-4"}),"People"]}),e.jsxs(g,{value:"sync-jobs",className:"gap-1.5",children:[e.jsx($,{className:"h-4 w-4"}),"Sync Jobs"]})]}),e.jsxs(N,{value:"people",children:[e.jsxs("div",{className:"relative mb-6",children:[e.jsx(U,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(T,{placeholder:"Search by name, email, or company...",value:r,onChange:s=>w(s.target.value),className:"pl-10"})]}),I&&e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(m,{className:"h-8 w-8 animate-spin text-primary"})}),n&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm text-muted-foreground mb-3",children:[n.length," people"]}),n.length===0&&e.jsx(f,{children:e.jsx(y,{className:"pt-6 text-center text-muted-foreground",children:'No people found. Click "Sync from Attio" to import contacts.'})}),n.map(s=>{var a,t;return e.jsx(f,{className:"cursor-pointer transition-colors hover:bg-muted/50",onClick:()=>k(`/people/${s.attio_record_id}`),children:e.jsxs(y,{className:"flex items-center gap-4 py-3",children:[e.jsxs(z,{className:"h-10 w-10",children:[s.avatar_url&&e.jsx(B,{src:s.avatar_url}),e.jsx(P,{className:"text-xs bg-primary/10 text-primary",children:C(s)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:b(s)}),e.jsxs("div",{className:"flex items-center gap-3 mt-0.5 text-sm text-muted-foreground",children:[((a=s.email_addresses)==null?void 0:a[0])&&e.jsxs("span",{className:"flex items-center gap-1 truncate",children:[e.jsx(V,{className:"h-3.5 w-3.5 shrink-0"}),s.email_addresses[0]]}),s.company_name&&e.jsxs("span",{className:"flex items-center gap-1 truncate",children:[e.jsx(Y,{className:"h-3.5 w-3.5 shrink-0"}),s.company_name]}),s.phone&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(F,{className:"h-3.5 w-3.5 shrink-0"}),s.phone]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[(s.meeting_count??0)>0&&e.jsxs(p,{variant:"outline",className:"shrink-0 gap-1",children:[e.jsx(R,{className:"h-3 w-3"}),s.meeting_count]}),(s.gmail_thread_count??0)>0&&e.jsxs(p,{variant:"outline",className:"shrink-0 gap-1",children:[e.jsx(X,{className:"h-3 w-3"}),s.gmail_thread_count]}),((t=s.email_addresses)==null?void 0:t.length)>1&&e.jsxs(p,{variant:"outline",className:"shrink-0",children:[s.email_addresses.length," emails"]})]}),e.jsx(Z,{className:"h-5 w-5 text-muted-foreground shrink-0"})]})},s.id)})]})]}),e.jsx(N,{value:"sync-jobs",children:e.jsx(G,{})})]})]})})}export{ge 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.