1import{a as E,u as K,b as q,j as e}from"./query-vendor-DVmmQ-ki.js";import{r as u,L as B}from"./react-vendor-BURXZ51T.js";import{supabase as j}from"./client-BXzYhP5O.js";import{u as g}from"./index-Rp47IaA2.js";import{B as o}from"./index-DpP3iEYK.js";import{I as z}from"./input-Bx2apBJb.js";import{B as O}from"./badge-BrFuXnAq.js";import{C as i,b as p,c as f,a as N}from"./card-DwBoygcx.js";import{T as P,a as Q,b as d,c as l,d as I,e as n}from"./table-DGTNs8pb.js";import{S as R,b as $,c as G,d as V,e as W}from"./sheet-BeJtqytd.js";import{A as Z,h as J,a as X,b as Y,c as ee,d as se,e as ae,f as re,g as te}from"./alert-dialog-B3w2S2tj.js";import{A as ne}from"./arrow-left-DrlG9OEE.js";import{U as le}from"./upload-B6QS-LUa.js";import{S as ce}from"./search-gwTUQi-V.js";import{C as oe}from"./calendar-BTOsELIB.js";import{E as ie}from"./eye-BOQecZvW.js";import{U as de}from"./user-CZ-Nb2LJ.js";import{M as me}from"./mail-B34Ue2PM.js";import{P as he}from"./phone-Bv9OMO_N.js";import{M as xe}from"./message-square-BRTYjeg0.js";import{F as ue}from"./file-text-UJur6P3r.js";import{D as je}from"./download-BqrsYkRJ.js";import{T as ge}from"./trash-2-B9W2MJEE.js";import{f as pe}from"./date-vendor-sl2uXp01.js";import{d as fe}from"./de-C5AT29KS.js";import"./supabase-DxfZiqN5.js";import"./radix-slot-BTvEbTmE.js";import"./ui-radix-LBOF5AHa.js";import"./x-CrVVxRiw.js";function Ve(){var D,y;const C=E(),[b,A]=u.useState(""),[r,w]=u.useState(null),[S,m]=u.useState(!1),{data:t,isLoading:_}=K({queryKey:["document-uploads"],queryFn:async()=>{const{data:s,error:a}=await j.from("document_uploads").select("*").order("created_at",{ascending:!1});if(a)throw a;return s}}),T=q({mutationFn:async s=>{const{error:a}=await j.from("document_uploads").delete().eq("id",s);if(a)throw a},onSuccess:()=>{C.invalidateQueries({queryKey:["document-uploads"]}),g.success("Upload gelöscht"),m(!1),w(null)},onError:()=>{g.error("Fehler beim Löschen")}}),c=t==null?void 0:t.filter(s=>{const a=b.toLowerCase();return s.customer_name.toLowerCase().includes(a)||s.customer_email.toLowerCase().includes(a)||s.customer_phone.toLowerCase().includes(a)}),h=new Date;h.setHours(0,0,0,0);const x=new Date(h);x.setDate(x.getDate()-7);const U=(t==null?void 0:t.filter(s=>new Date(s.created_at)>=h).length)||0,H=(t==null?void 0:t.filter(s=>new Date(s.created_at)>=x).length)||0,L=async s=>{try{const{data:a,error:k}=await j.storage.from("self-disclosure-documents").createSignedUrl(s,3600);if(k)throw k;window.open(a.signedUrl,"_blank")}catch{g.error("Fehler beim Herunterladen")}},M=s=>{w(s),m(!0)},v=s=>pe(new Date(s),"dd.MM.yyyy, HH:mm",{locale:fe}),F=s=>{const a=s.split("/");return a[a.length-1]};return e.jsxs("div",{className:"min-h-screen",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx(B,{to:"/admin/kunden",children:e.jsxs(o,{variant:"ghost",size:"sm",className:"mb-4 -ml-2",children:[e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Zurück zum Kundenmanagement"]})}),e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(le,{className:"h-8 w-8 text-primary"}),e.jsx("h1",{className:"text-3xl font-bold text-foreground",children:"Dokumenten-Uploads"})]}),e.jsx("p",{className:"text-muted-foreground",children:"Alle von Kunden hochgeladenen Dokumente verwalten."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4 mb-8",children:[e.jsxs(i,{className:"bg-card/50 backdrop-blur-sm border-border/50",children:[e.jsx(p,{className:"pb-2",children:e.jsx(f,{className:"text-sm font-medium text-muted-foreground",children:"Gesamt"})}),e.jsx(N,{children:e.jsx("div",{className:"text-2xl font-bold",children:(t==null?void 0:t.length)||0})})]}),e.jsxs(i,{className:"bg-card/50 backdrop-blur-sm border-border/50",children:[e.jsx(p,{className:"pb-2",children:e.jsx(f,{className:"text-sm font-medium text-muted-foreground",children:"Heute"})}),e.jsx(N,{children:e.jsx("div",{className:"text-2xl font-bold text-green-500",children:U})})]}),e.jsxs(i,{className:"bg-card/50 backdrop-blur-sm border-border/50",children:[e.jsx(p,{className:"pb-2",children:e.jsx(f,{className:"text-sm font-medium text-muted-foreground",children:"Diese Woche"})}),e.jsx(N,{children:e.jsx("div",{className:"text-2xl font-bold",children:H})})]})]}),e.jsx("div",{className:"mb-6",children:e.jsxs("div",{className:"relative max-w-md",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(z,{placeholder:"Nach Name, E-Mail oder Telefon suchen...",value:b,onChange:s=>A(s.target.value),className:"pl-10"})]})}),e.jsx(i,{className:"bg-card/50 backdrop-blur-sm border-border/50",children:e.jsxs(P,{children:[e.jsx(Q,{children:e.jsxs(d,{children:[e.jsx(l,{children:"Datum"}),e.jsx(l,{children:"Kundenname"}),e.jsx(l,{children:"E-Mail"}),e.jsx(l,{children:"Telefon"}),e.jsx(l,{children:"Dokumente"}),e.jsx(l,{children:"Nachricht"}),e.jsx(l,{className:"text-right",children:"Aktionen"})]})}),e.jsx(I,{children:_?e.jsx(d,{children:e.jsx(n,{colSpan:7,className:"text-center py-8",children:"Laden..."})}):(c==null?void 0:c.length)===0?e.jsx(d,{children:e.jsx(n,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"Keine Uploads gefunden"})}):c==null?void 0:c.map(s=>{var a;return e.jsxs(d,{children:[e.jsx(n,{className:"whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"h-4 w-4 text-muted-foreground"}),v(s.created_at)]})}),e.jsx(n,{className:"font-medium",children:s.customer_name}),e.jsx(n,{children:s.customer_email}),e.jsx(n,{children:s.customer_phone}),e.jsx(n,{children:e.jsxs(O,{variant:"secondary",children:[((a=s.documents)==null?void 0:a.length)||0," Dokumente"]})}),e.jsx(n,{className:"max-w-[200px] truncate",children:s.message||"-"}),e.jsx(n,{className:"text-right",children:e.jsxs(o,{variant:"ghost",size:"sm",onClick:()=>M(s),children:[e.jsx(ie,{className:"h-4 w-4 mr-1"}),"Details"]}
1)})]},s.id)})})]})}),e.jsx(R,{open:S,onOpenChange:m,children:e.jsxs($,{className:"w-full sm:max-w-lg overflow-y-auto",children:[e.jsxs(G,{children:[e.jsx(V,{children:"Upload-Details"}),e.jsxs(W,{children:["Hochgeladen am"," ",r&&v(r.created_at)]})]}),r&&e.jsxs("div",{className:"mt-6 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"font-semibold text-sm text-muted-foreground uppercase tracking-wide",children:"Kundendaten"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(de,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:r.customer_name})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(me,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("a",{href:`mailto:${r.customer_email}`,className:"text-primary hover:underline",children:r.customer_email})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(he,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("a",{href:`tel:${r.customer_phone}`,className:"text-primary hover:underline",children:r.customer_phone})]})]})]}),r.message&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"font-semibold text-sm text-muted-foreground uppercase tracking-wide",children:"Nachricht"}),e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-muted/30 rounded-lg",children:[e.jsx(xe,{className:"h-4 w-4 text-muted-foreground mt-0.5"}),e.jsx("p",{className:"text-sm",children:r.message})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"font-semibold text-sm text-muted-foreground uppercase tracking-wide",children:["Dokumente (",((D=r.documents)==null?void 0:D.length)||0,")"]}),e.jsx("div",{className:"space-y-2",children:(y=r.documents)==null?void 0:y.map((s,a)=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(ue,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-sm truncate",children:s.name||F(s.path)})]}),e.jsx(o,{variant:"ghost",size:"sm",onClick:()=>L(s.path),children:e.jsx(je,{className:"h-4 w-4"})})]},a))})]}),e.jsx("div",{className:"pt-4 border-t",children:e.jsxs(Z,{children:[e.jsx(J,{asChild:!0,children:e.jsxs(o,{variant:"destructive",className:"w-full",children:[e.jsx(ge,{className:"h-4 w-4 mr-2"}),"Upload löschen"]})}),e.jsxs(X,{children:[e.jsxs(Y,{children:[e.jsx(ee,{children:"Upload löschen?"}),e.jsx(se,{children:"Diese Aktion kann nicht rückgängig gemacht werden. Alle Daten und Dokumente werden dauerhaft gelöscht."})]}),e.jsxs(ae,{children:[e.jsx(re,{children:"Abbrechen"}),e.jsx(te,{onClick:()=>T.mutate(r.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Löschen"})]})]})]})})]})]})})]})}export{Ve 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.