1import{r as b,j as e,V as D,a5 as I,B as l,P,W as A,X as F,Y as _,ak as B,I as R,S as d,Q as C,_ as z,a8 as M,e as H,a9 as E,C as O,g as V,h as W,f as $}from"./index-DYqv-g2L.js";import{T as Q,a as X,b as w,c as j,d as Y,e as u}from"./table-DgCsttuC.js";import{C as q}from"./checkbox-D4E4LdZ3.js";import{c as L,d as G}from"./queries-CHxJFcY1.js";import{c as J,e as K,f as U}from"./mutations-fAQn3LB9.js";import{I as Z}from"./ImportCsvWizard-DUEkOW87.js";import{C as ee}from"./chevron-left-BJ-9Gcb8.js";import{T as y}from"./trash-2-CqORIkbQ.js";import"./index-DpHe5njO.js";import"./useMutation-Cm0kQ_TT.js";import"./effectiveOwner-b6YuPRQn.js";import"./select-_aI_JWyz.js";function se({listId:m}){const[p,a]=b.useState(!1),[x,i]=b.useState(""),[n,r]=b.useState(new Set),{data:o,fetchNextPage:f,hasNextPage:g,isFetchingNextPage:c,isLoading:t}=L({search:x}),N=J(),v=((o==null?void 0:o.pages)??[]).flatMap(s=>s.rows),S=s=>{r(T=>{const h=new Set(T);return h.has(s)?h.delete(s):h.add(s),h})},k=async()=>{await N.mutateAsync({listId:m,contactIds:Array.from(n)}),a(!1),r(new Set),i("")};return e.jsxs(D,{open:p,onOpenChange:s=>{a(s),s||(r(new Set),i(""))},children:[e.jsx(I,{asChild:!0,children:e.jsxs(l,{children:[e.jsx(P,{className:"mr-2 h-4 w-4"})," Add members"]})}),e.jsxs(A,{className:"max-w-xl",children:[e.jsx(F,{children:e.jsx(_,{children:"Add contacts to list"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(B,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(R,{className:"pl-9",placeholder:"Search by name, email, company",value:x,onChange:s=>i(s.target.value)})]}),e.jsx("div",{className:"max-h-[400px] space-y-1 overflow-y-auto rounded-md border p-2",children:t?e.jsxs(e.Fragment,{children:[e.jsx(d,{className:"h-8 w-full"}),e.jsx(d,{className:"h-8 w-full"}),e.jsx(d,{className:"h-8 w-full"})]}):v.length===0?e.jsx("p",{className:"p-6 text-center text-sm text-muted-foreground",children:"No contacts found."}):e.jsxs(e.Fragment,{children:[v.map(s=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-3 rounded-md p-2 hover:bg-muted/50",children:[e.jsx(q,{checked:n.has(s.id),onCheckedChange:()=>S(s.id)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"truncate text-sm",children:[s.first_name,s.last_name].filter(Boolean).join(" ")||s.email||s.id}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:s.email??s.phone??""})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.company??""})]},s.id)),g&&e.jsxs(l,{variant:"ghost",className:"w-full",onClick:()=>f(),disabled:c,children:[c?e.jsx(C,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Load more"]})]})})]}),e.jsxs(z,{children:[e.jsxs("span",{className:"mr-auto text-sm text-muted-foreground",children:[n.size," selected"]}),e.jsx(l,{variant:"ghost",onClick:()=>a(!1),children:"Cancel"}),e.jsxs(l,{onClick:k,disabled:n.size===0||N.isPending,children:[N.isPending&&e.jsx(C,{className:"mr-2 h-4 w-4 animate-spin"}),"Add to list"]})]})]})]})}function je(){const{id:m}=M(),p=H(),{data:a,isLoading:x}=G(m),{data:i,fetchNextPage:n,hasNextPage:r,isFetchingNextPage:o}=L({listId:m}),f=K(),g=U();if(x||!a)return e.jsxs("div",{className:"space-y-4",children:[e.jsx(d,{className:"h-8 w-64"}),e.jsx(d,{className:"h-32 w-full"})]});const c=((i==null?void 0:i.pages)??[]).flatMap(t=>t.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(E,{to:"/contacts/lists",className:"inline-flex items-center text-xs text-muted-foreground hover:text-foreground",children:[e.jsx(ee,{className:"mr-1 h-3 w-3"})," Back to lists"]}),e.jsx("h2",{className:"mt-1 text-2xl font-semibold",children:a.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a.member_count," member",a.member_count===1?"":"s",a.description?` â ${a.description}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{presetListId:a.id}),e.jsx(se,{listId:a.id}),e.jsx(l,{variant:"outline",size:"icon",onClick:()=>{confirm(`Delete list "${a.name}"? Memberships will be removed; contacts stay.`)&&f.mutate(a.id,{onSuccess:()=>p("/contacts/lists")})},"aria-label":"Delete list",children:e.jsx(y,{className:"h-4 w-4"})})]})]}),e.jsxs(O,{children:[e.jsx(V,{children:e.jsx(W,{className:"text-base",children:"Members"})}),e.jsx($,{className:"p-0",children:c.length?e.jsxs(Q,{children:[e.jsx(X,{children:e.jsxs(w,{children:[e.jsx(j,{children:"Name"}),e.jsx(j,{children:"Email"}),e.jsx(j,{children:"Company"}),e.jsx(j,{className:"text-right"})]})}),e.jsx(Y,{children:c.map(t=>e.jsxs(w,{children:[e.jsx(u,{className:"font-medium",children:[t.first_name,t.last_name].filter(
1Boolean).join(" ")||"â"}),e.jsx(u,{className:"font-mono text-xs",children:t.email??"â"}),e.jsx(u,{children:t.company??"â"}),e.jsx(u,{className:"text-right",children:e.jsx(l,{variant:"ghost",size:"icon",onClick:()=>g.mutate({listId:a.id,contactIds:[t.id]}),"aria-label":"Remove from list",children:e.jsx(y,{className:"h-4 w-4"})})})]},t.id))})]}):e.jsx("p",{className:"p-12 text-center text-sm text-muted-foreground",children:'No members yet â click "Add members" or import a CSV directly into this list.'})}),r&&e.jsx("div",{className:"border-t p-3 text-center",children:e.jsx(l,{variant:"ghost",onClick:()=>n(),disabled:o,children:"Load more"})})]})]})}export{je 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.