1import{c as Y,a as ee,r as l,s as te,j as e,X as B}from"./index-DHSMMgQP.js";import{utils as k,writeFile as se}from"./xlsx-B6sNpj_1.js";import{A as ae}from"./arrow-left-LNDHISHj.js";import{P as ne}from"./package-BpJx5bIZ.js";import{D as le}from"./download-Dq7nvc-O.js";import{S as re}from"./search-B0peVaqQ.js";import{F as oe}from"./filter-Dzm2QSIU.js";import{F as H}from"./flame-C20EtBQO.js";import{M as ce}from"./mail-BEoBOvDe.js";import{S as ie}from"./send-BuYb1XH7.js";import{U as de}from"./user-plus-C6RfgARi.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 ue=Y("Repeat",[["path",{d:"m17 2 4 4-4 4",key:"nntrym"}],["path",{d:"M3 11v-1a4 4 0 0 1 4-4h14",key:"84bu3i"}],["path",{d:"m7 22-4-4 4-4",key:"1wqhfi"}],["path",{d:"M21 13v1a4 4 0 0 1-4 4H3",key:"1rx37r"}]]);function C(c){const r=`${c.quelle||""} ${c.source_type||""}`.toLowerCase();return r.includes("whatsapp")||r.includes("wa")?"whatsapp":r.includes("mail")||r.includes("email")||r.includes("gmail")?"mail":r.includes("web")||r.includes("form")||r.includes("chat")||r.includes("site")?"web":"other"}const S=100;function ve(){var R;const c=ee(),[r,G]=l.useState([]),[K,E]=l.useState(!0),[f,F]=l.useState(""),[i,A]=l.useState(""),[d,M]=l.useState(""),[u,z]=l.useState(""),[m,P]=l.useState(""),[o,L]=l.useState("all"),[x,D]=l.useState("all"),[p,$]=l.useState("all"),[g,w]=l.useState(1),[b,I]=l.useState(!1),[v,_]=l.useState(null);l.useEffect(()=>{(async()=>{E(!0);const t=5e4,s=1e3,a=[];for(let n=0;n<t;n+=s){const N=Math.min(n+s-1,t-1),{data:y,error:J}=await te.from("customer_inquiries").select("id, created_at, customer_name, company_name, customer_email, customer_phone, product_name, manufacturer, quantity, delivery_zip, status, sell_price, potenzialwert, kundentyp, is_sent, inquiry_number, quelle, source_type").is("deleted_at",null).order("created_at",{ascending:!1}).range(n,N);if(J||!y||y.length===0||(a.push(...y),y.length<s))break}G(a),E(!1)})()},[]);const Q=l.useMemo(()=>{const t=new Set;return r.forEach(s=>{s.manufacturer&&t.add(s.manufacturer)}),[...t].sort()},[r]),h=l.useMemo(()=>{const t=f.trim().toLowerCase();return r.filter(s=>{if(t&&!`${s.product_name||""} ${s.manufacturer||""} ${s.customer_email||""} ${s.customer_name||""} ${s.company_name||""}`.toLowerCase().includes(t)||i&&s.manufacturer!==i||d&&!(s.product_name||"").toLowerCase().includes(d.toLowerCase())||u&&s.created_at<u||m&&s.created_at>m+"T23:59:59")return!1;if(o!=="all"){const a=(s.kundentyp||"").toLowerCase();if(o==="b2b"&&!a.includes("b2b")&&!a.includes("gewerb")||o==="b2c"&&!a.includes("b2c")&&!a.includes("privat"))return!1}return!(x==="sent"&&!s.is_sent||x==="open"&&s.is_sent||p!=="all"&&C(s)!==p)})},[r,f,i,d,u,m,o,x,p]),W=l.useMemo(()=>{const t={};return r.forEach(s=>{const a=(s.product_name||"").trim().toLowerCase();a&&(t[a]=(t[a]||0)+1)}),t},[r]),Z=l.useMemo(()=>{const t={};return r.forEach(s=>{const a=(s.customer_email||"").trim().toLowerCase();a&&(t[a]=(t[a]||0)+1)}),t},[r]),T=l.useMemo(()=>{if(!b)return[];const t={};return h.forEach(s=>{const a=(s.product_name||"Unbekannt").trim();t[a]||(t[a]={product_name:a,count:0,volume:0,rows:[]}),t[a].count++,t[a].volume+=Number(s.sell_price||s.potenzialwert||0),t[a].rows.push(s)}),Object.values(t).sort((s,a)=>a.count-s.count)},[h,b]),j=Math.max(1,Math.ceil(h.length/S)),q=h.slice((g-1)*S,g*S);l.useEffect(()=>{w(1)},[f,i,d,u,m,o,x,p]);const U=()=>{const t=h.map(n=>{var N;return{ID:n.inquiry_number||n.id,Datum:((N=n.created_at)==null?void 0:N.slice(0,10))||"",Name:n.customer_name||"",Firma:n.company_name||"","E-Mail":n.customer_email||"",Telefon:n.customer_phone||"",Produkt:n.product_name||"",Hersteller:n.manufacturer||"",Menge:n.quantity||"",PLZ:n.delivery_zip||"",Status:n.is_sent?"Gesendet":n.status||"Offen",Preis:n.sell_price||n.potenzialwert||"",Quelle:C(n)}}),s=k.json_to_sheet(t),a=k.book_new();k.book_append_sheet(a,s,"Anfragen"),se(a,`produktanfragen-${new Date().toISOString().slice(0,10)}.xlsx`)},X=t=>{t.customer_email&&(window.location.href=`mailto:${t.customer_email}?subject=Ihre Anfrage zu ${t.product_name||""}`)},V=t=>c(`/kundenanfragen?open=${t.id}`),O=t=>
6t?`${Number(t).toLocaleString("de-DE",{maximumFractionDigits:0})} â¬`:"â";return e.jsxs("div",{className:"min-h-screen bg-[#F7F8FC]",children:[e.jsx("header",{className:"sticky top-0 z-40 bg-white border-b",children:e.jsxs("div",{className:"px-6 md:px-10 py-4 flex items-center gap-4",children:[e.jsx("button",{onClick:()=>c("/"),className:"p-2 -ml-2 rounded-lg hover:bg-accent",children:e.jsx(ae,{size:20})}),e.jsx("h1",{className:"text-xl font-bold tracking-tight",children:"Produktanfragen · Quote Database"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h.length.toLocaleString("de-DE")," Treffer"]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>I(t=>!t),className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium border transition ${b?"bg-[#0E3A5A] text-white border-[#0E3A5A]":"bg-white hover:bg-accent"}`,children:[e.jsx(ne,{size:16}),b?"Liste anzeigen":"Nach Produkt gruppieren"]}),e.jsxs("button",{onClick:U,className:"flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-semibold bg-[#95C23D] text-white hover:opacity-90",children:[e.jsx(le,{size:16}),"Export E-Mails (XLS)"]})]})]})}),e.jsxs("main",{className:"px-6 md:px-10 py-6 space-y-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(re,{size:20,className:"absolute left-4 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{value:f,onChange:t=>F(t.target.value),placeholder:"Produkt, Hersteller, Modell oder E-Mail suchenâ¦",className:"w-full pl-12 pr-4 h-14 text-lg rounded-2xl border-2 bg-white focus:border-[#0E3A5A] focus:outline-none"})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-4 flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-sm font-medium",children:[e.jsx(oe,{size:16})," Filter:"]}),e.jsxs("select",{value:i,onChange:t=>A(t.target.value),className:"h-10 px-3 rounded-lg border text-sm bg-white",children:[e.jsx("option",{value:"",children:"Alle Hersteller"}),Q.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsx("input",{value:d,onChange:t=>M(t.target.value),placeholder:"Produkt enthältâ¦",className:"h-10 px-3 rounded-lg border text-sm w-44"}),e.jsx("input",{type:"date",value:u,onChange:t=>z(t.target.value),className:"h-10 px-3 rounded-lg border text-sm"}),e.jsx("input",{type:"date",value:m,onChange:t=>P(t.target.value),className:"h-10 px-3 rounded-lg border text-sm"}),e.jsxs("select",{value:o,onChange:t=>L(t.target.value),className:"h-10 px-3 rounded-lg border text-sm bg-white",children:[e.jsx("option",{value:"all",children:"B2B & B2C"}),e.jsx("option",{value:"b2b",children:"Nur B2B"}),e.jsx("option",{value:"b2c",children:"Nur B2C"})]}),e.jsxs("select",{value:x,onChange:t=>D(t.target.value),className:"h-10 px-3 rounded-lg border text-sm bg-white",children:[e.jsx("option",{value:"all",children:"Alle Status"}),e.jsx("option",{value:"sent",children:"Angebot gesendet"}),e.jsx("option",{value:"open",children:"Offen"})]}),e.jsxs("select",{value:p,onChange:t=>$(t.target.value),className:"h-10 px-3 rounded-lg border text-sm bg-white",children:[e.jsx("option",{value:"all",children:"Alle Quellen"}),e.jsx("option",{value:"web",children:"Web"}),e.jsx("option",{value:"mail",children:"Mail"}),e.jsx("option",{value:"whatsapp",children:"WhatsApp"})]}),(f||i||d||u||m||o!=="all"||x!=="all"||p!=="all")&&e.jsxs("button",{onClick:()=>{F(""),A(""),M(""),z(""),P(""),L("all"),D("all"),$("all")},className:"h-10 px-3 rounded-lg text-sm text-muted-foreground hover:bg-accent flex items-center gap-1",children:[e.jsx(B,{size:14})," Reset"]})]}),K?e.jsx("div",{className:"text-center py-20 text-muted-foreground",children:"Ladenâ¦"}):b?e.jsx("div",{className:"bg-white rounded-2xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-[#F7F8FC] text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold",children:"Produkt"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold",children:"Anfragen"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold",children:"Volumen"}),e.jsx("th",{className:"px-4 py-3"})]})}),e.jsx("tbody",{children:T.map(t=>e.jsxs("tr",{className:"border-t",children:[e.jsxs("td",{className:"px-4 py-3 font-medium flex items-center gap-2",children:[t.product_name,t.count>=3&&e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-red-50 text-red-600 text-xs font-bold flex items-center gap-1",children:[e.jsx(H,{size:12})," HOT PRODUCT"]})]}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums font-semibold",children:t.count}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums",children:O(t.volume)}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx("button",{onClick:()=>_(t.product_name),className:"px-3 py-1.5 rounded-lg bg-[#0E3A5A] text-white text-xs font-semibold hover:opacity-90",children:"Kontakte anzeigen"})})]},t.product_name))})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-white rounded-2xl overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-[#F7F8FC] text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-3 py-3 font-semibold whitespace-nowrap",children:"Datum"}),e.jsx("th",{className:"text-left px-3 py-3 font-semibold",children:"Kunde"}),e.jsx("th",{className:"text-left px-3 py-3 font-semibold",children:"E-Mail"}),e.jsx("th",{className:"text-left px-3 py-3 font-semibold",children:"Telefon"}),e.jsx("th",{className:"text-left px-3 py-3 font-semibold",children:"Produkt"}),e.jsx("th",{className:"text-left px-3 py-3 font-semibold",children:"Hersteller"}),e.jsx("th",{className:"text-right px-3 py-3 font-semibold",children:"Menge"}),e.jsx("th",{className:"text-left px-3 py-3 font-semibold",children:"PLZ"}),e.jsx("th",{className:"text-left px-3 py-3 font-semibold",children:"Status"}),e.jsx("th",{className:"text-right px-3 py-3 font-semibold",children:"Wert"}),e.jsx("th",{className:"text-left px-3 py-3 font-semibold",children:"Quelle"}),e.jsx("th",{className:"text-right px-3 py-3 font-semibold",children:"Aktionen"})]})}),e.jsxs("tbody",{children:[q.map(t=>{var n;const s=W[(t.product_name||"").trim().toLowerCase()]>=3,a=Z[(t.customer_email||"").trim().toLowerCase()]>=2;return e.jsxs("tr",{className:"border-t hover:bg-[#F7F8FC]/50",children:[e.jsx("td",{className:"px-3 py-2 whitespace-nowrap tabular-nums",children:(n=t.created_at)==null?void 0:n.slice(0,10)}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("div",{className:"font-medium",children:t.company_name||t.customer_name||"â"}),t.company_name&&t.customer_name&&e.jsx("div",{className:"text-xs text-muted-foreground",children:t.customer_name}),a&&e.jsxs("span",{className:"inline-flex items-center gap-1 mt-1 px-1.5 py-0.5 rounded bg-blue-50 text-blue-700 text-[10px] font-semibold",children:[e.jsx(ue,{size:10})," Wiederkehrend"]})]}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground",children:t.customer_email}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground whitespace-nowrap",children:t.customer_phone||"â"}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:t.product_name}),s&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-red-50 text-red-600 text-[10px] font-bold flex items-center gap-1",children:[e.jsx(H,{size:10})," HOT"]})]})}),e.jsx("td",{className:"px-3 py-2",children:t.manufacturer}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:t.quantity||"â"}),e.jsx("td",{className:"px-3 py-2",children:t.delivery_zip||"â"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs ${t.is_sent?"bg-green-50 text-green-700":"bg-amber-50 text-amber-700"}`,children:t.is_sent?"Gesendet":t.status||"Offen"})}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:O(t.sell_price||t.potenzialwert)}),e.jsx("td",{className:"px-3 py-2 text-xs uppercase text-muted-foreground",children:C(t)}),e.jsxs("td",{className:"px-3 py-2 text-right whitespace-nowrap",children:[e.jsx("button",{onClick:()=>X(t),title:"Erneut kontaktieren",className:"p-1.5 rounded hover:bg-accent text-muted-foreground hover:text-[#0E3A5A]",children:e.jsx(ce,{size:14})}),e.jsx("button",{onClick:()=>V(t),title:"Angebot senden",className:"p-1.5 rounded hover:bg-accent text-muted-foreground hover:text-[#95C23D]",children:e.jsx(ie,{size:14})}),e.jsx("button",{onClick:()=>c(`/kundenanfragen?open=${t.id}`),title:"Zu CRM",className:"p-1.5 rounded hover:bg-accent text-muted-foreground hover:text-[#0E3A5A]",children:e.jsx(de,{size:14})})]})]},t.id)}),q.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:12,className:"text-center py-12 text-muted-foreground",children:"Keine Treffer"})})]})]})})}),j>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("button",{onClick:()=>w(t=>Math.max(1,t-1)),disabled:g===1,className:"px-3 py-1.5 rounded-lg border bg-white text-sm disabled:opacity-40",children:"Zurück"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Seite ",g," / ",j]}),e.jsx("button",{onClick:()=>w(t=>Math.min(j,t+1)),disabled:g===j,className:"px-3 py-1.5 rounded-lg border bg-white text-sm disabled:opacity-40",children:"Weiter"})]})]})]}),v&&e.jsx("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center p-4",onClick:()=>_(null),children:e.jsxs("div",{className:"bg-white rounded-2xl max-w-3xl w-full max-h-[80vh] overflow-hidden flex flex-col",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"p-4 border-b flex items-center justify-between",children:[e.jsxs("h3",{className:"font-bold",children:["Kontakte â ",v]}),e.jsx("button",{onClick:()=>_(null),className:"p-1 rounded hover:bg-accent",children:e.jsx(B,{size:18})})]}),e.jsx("div",{className:"overflow-auto p-4",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left py-2",children:"Datum"}),e.jsx("th",{className:"text-left py-2",children:"Kunde"}),e.jsx("th",{className:"text-left py-2",children:"E-Mail"}),e.jsx("th",{className:"text-right py-2",children:"Menge"})]})}),e.jsx("tbody",{children:(R=T.find(t=>t.product_name===v))==null?void 0:R.rows.map(t=>{var s;return e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"py-2",children:(s=t.created_at)==null?void 0:s.slice(0,10)}),e.jsx("td",{className:"py-2",children:t.company_name||t.customer_name}),e.jsx("td",{className:"py-2",children:t.customer_email}),e.jsx("td",{className:"py-2 text-right",children:t.quantity||"â"})]},t.id)})})]})})]})})]})}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.