1import{au as B,u as I,y as H,s as n,r as w,j as e,L as b,t as c}from"./index-BjROZu-y.js";import{u as k}from"./useQuery-BKwbzsdF.js";import{u as z}from"./use-current-workspace-CeVx6BzL.js";import{B as m}from"./button-jAwp458t.js";import{I as Q}from"./input-D8ltPcu6.js";import{L as x}from"./label-CCIEJ2c4.js";import{T as L}from"./textarea-jhq894k2.js";import{S as F}from"./switch-BLdD-I5N.js";import{B as M}from"./badge-CdrzAnT5.js";import{C as v,a as y,b as _,d as N,c as R}from"./card-1tQB7wJr.js";import{S as G,a as P,b as V,c as W,d as Z}from"./select-Bb-5yMUy.js";import{T as U,a as X,b as D,c as h,d as $,e as p}from"./table-BaYmr2Jw.js";import{A as J,f as O,a as Y,b as ee,c as se,d as te,e as ae,g as ie,h as re}from"./alert-dialog-BvcttIfA.js";import{A as ne}from"./arrow-left-CDPeqelg.js";import{T as ce}from"./trash-2-CVOOUYxW.js";import{X as le}from"./x-CuRVTk-Y.js";import"./index-BO-M6IvO.js";import"./index-LHNt3CwB.js";import"./utils-BQHNewu7.js";import"./index-BlGddTbp.js";import"./index-CcnB0opD.js";import"./index-C8xkTz-G.js";import"./index-Bmt-34PV.js";import"./index-3lTj5ZWs.js";import"./index-LwKlC5vL.js";import"./index-ayD4ZR3x.js";import"./index-CkRaa6EE.js";import"./chevron-down-D5hea2Fu.js";import"./createLucideIcon-DRj5qHaH.js";import"./check-CtRWDpXd.js";import"./index-BP8JKLDr.js";import"./index-B6e5pELl.js";function Me(){const{listId:i}=B.useParams(),S=I(),f=H(),{data:l}=z(),{data:a,isLoading:q}=k({queryKey:["list",i],queryFn:async()=>{const{data:s,error:t}=await n.from("lists").select("*").eq("id",i).maybeSingle();if(t)throw t;const{data:u}=await n.from("contact_lists").select("id, status, added_at, contacts(id, email, first_name, last_name, status)").eq("list_id",i).order("added_at",{ascending:!1});return{list:s,members:u??[]}}}),{data:C}=k({queryKey:["list-candidates",i,l?.id],enabled:!!l,queryFn:async()=>{const{data:s}=await n.from("contact_lists").select("contact_id").eq("list_id",i),t=new Set((s??[]).map(g=>g.contact_id)),{data:u}=await n.from("contacts").select("id, email").eq("workspace_id",l.id).neq("source","admin_manual").order("email").limit(500);return(u??[]).filter(g=>!t.has(g.id))}}),[r,d]=w.useState({name:"",description:"",default_consent_text:"",active:!0});if(w.useEffect(()=>{a?.list&&d({name:a.list.name??"",description:a.list.description??"",default_consent_text:a.list.default_consent_text??"",active:a.list.active})},[a?.list]),q)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"Wird geladen â¦"});if(!a?.list)return e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{children:"Liste nicht gefunden."}),e.jsx(m,{asChild:!0,variant:"outline",children:e.jsx(b,{to:"/lists/",children:"Zurück"})})]});const j=()=>{f.invalidateQueries({queryKey:["list",i]}),f.invalidateQueries({queryKey:["list-candidates",i]}),f.invalidateQueries({queryKey:["lists"]})},o=a.members.reduce((s,t)=>(s.total++,t.status==="pending"?s.pending++:t.status==="confirmed"?s.confirmed++:t.status==="unsubscribed"&&s.unsubscribed++,t.contacts?.status==="blocked"&&s.blocked++,s),{total:0,pending:0,confirmed:0,unsubscribed:0,blocked:0}),A=async s=>{s.preventDefault();const{error:t}=await n.from("lists").update({name:r.name,description:r.description||null,default_consent_text:r.default_consent_text||null,active:r.active}).eq("id",i);if(t)return t.code==="23505"?c.error("Name bereits vergeben."):c.error(t.message);c.success("Gespeichert."),j()},T=async()=>{const{error:s}=await n.from("lists").delete().eq("id",i);if(s)return c.error(s.message);c.success("Liste gelöscht."),S({to:"/lists/"})},K=async s=>{if(!l)return;const{error:t}=await n.from("contact_lists").insert({workspace_id:l.id,list_id:i,contact_id:s,status:"pending"});if(t)return c.error(t.message);j()},E=async s=>{const{error:t}=await n.from("contact_lists").delete().eq("id",s);if(t)return c.error(t.message);j()};return e.jsxs("div",{className:"mx-auto max-w-4xl space-y-6",children:[e.jsx(m,{asChild:!0,variant:"ghost",size:"sm",children:e.jsxs(b,{to:"/lists/",children:[e.jsx(ne,{className:"mr-2 h-4 w-4"})," Zurück"]})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:a.list.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Erstellt ",new Date(a.list.created_at).toLocaleStr
1ing("de-DE")]})]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-5",children:[{l:"Gesamt",v:o.total},{l:"Pending",v:o.pending},{l:"Confirmed",v:o.confirmed},{l:"Unsubscribed",v:o.unsubscribed},{l:"Blocked",v:o.blocked}].map(s=>e.jsxs(v,{children:[e.jsx(y,{className:"pb-2",children:e.jsx(_,{className:"text-sm text-muted-foreground",children:s.l})}),e.jsx(N,{children:e.jsx("div",{className:"text-2xl font-semibold",children:s.v})})]},s.l))}),e.jsxs(v,{children:[e.jsx(y,{children:e.jsx(_,{children:"Eigenschaften"})}),e.jsx(N,{children:e.jsxs("form",{onSubmit:A,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Name"}),e.jsx(Q,{value:r.name,onChange:s=>d(t=>({...t,name:s.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Beschreibung"}),e.jsx(L,{value:r.description,onChange:s=>d(t=>({...t,description:s.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{children:"Standard-Einwilligungstext"}),e.jsx(L,{value:r.default_consent_text,onChange:s=>d(t=>({...t,default_consent_text:s.target.value}))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{checked:r.active,onCheckedChange:s=>d(t=>({...t,active:s}))}),e.jsx(x,{children:"Aktiv"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(m,{type:"submit",children:"Speichern"}),e.jsxs(J,{children:[e.jsx(O,{asChild:!0,children:e.jsxs(m,{variant:"destructive",type:"button",children:[e.jsx(ce,{className:"mr-2 h-4 w-4"})," Liste löschen"]})}),e.jsxs(Y,{children:[e.jsxs(ee,{children:[e.jsx(se,{children:"Liste löschen?"}),e.jsx(te,{children:"Mitgliedschaften aller Kontakte in dieser Liste werden entfernt. Kontakte selbst bleiben erhalten."})]}),e.jsxs(ae,{children:[e.jsx(ie,{children:"Abbrechen"}),e.jsx(re,{onClick:T,children:"Löschen"})]})]})]})]})]})})]}),e.jsxs(v,{children:[e.jsxs(y,{children:[e.jsx(_,{children:"Kontakte in dieser Liste"}),e.jsx(R,{children:"Hinzufügen oder entfernen."})]}),e.jsxs(N,{className:"space-y-4",children:[(C?.length??0)>0&&e.jsxs(G,{onValueChange:K,children:[e.jsx(P,{className:"max-w-md",children:e.jsx(V,{placeholder:"Kontakt hinzufügen â¦"})}),e.jsx(W,{children:C.map(s=>e.jsx(Z,{value:s.id,children:s.email},s.id))})]}),a.members.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Keine Kontakte in dieser Liste."}):e.jsxs(U,{children:[e.jsx(X,{children:e.jsxs(D,{children:[e.jsx(h,{children:"E-Mail"}),e.jsx(h,{children:"Listen-Status"}),e.jsx(h,{children:"Hinzugefügt"}),e.jsx(h,{})]})}),e.jsx($,{children:a.members.map(s=>e.jsxs(D,{children:[e.jsx(p,{children:e.jsx(b,{to:"/contacts/$contactId/",params:{contactId:s.contacts?.id??""},className:"font-medium underline",children:s.contacts?.email})}),e.jsx(p,{children:e.jsx(M,{variant:"secondary",children:s.status})}),e.jsx(p,{className:"text-xs text-muted-foreground",children:new Date(s.added_at).toLocaleDateString("de-DE")}),e.jsx(p,{className:"text-right",children:e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>E(s.id),children:e.jsx(le,{className:"h-4 w-4"})})})]},s.id))})]})]})]})]})}export{Me as component};
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.