1import{a as T,d as A,r as d,j as e,s as N,t as v}from"./index-DHSMMgQP.js";import{u as I,g as M}from"./useCustomerInquiries-CXa8NjiX.js";import{B as _}from"./button-BeDbJ6T4.js";import{I as L}from"./input-BMnPnPtI.js";import{B as z}from"./badge-D6fetf0E.js";import{S as q,a as B,b as V,c as F,d as h}from"./select-Cbv6k_OL.js";import{T as $,a as E,b as g,c as n,d as K,e as a}from"./table-CKs-qlD9.js";import{C as m,c as u}from"./card-SmBWIJ6J.js";import{u as G}from"./useLeadScores-BzMT1c8h.js";import{L as H}from"./LeadScoreBadge-B-2SgfXm.js";import{A as O}from"./arrow-left-LNDHISHj.js";import{S as P}from"./search-B0peVaqQ.js";import{P as R}from"./phone-DWEz2I38.js";import{f as U}from"./format-CODRHYvz.js";import"./useQuery-DJmFlesn.js";import"./useMutation-DDSrxGAQ.js";import"./useAutoMapping-BIdn2MCi.js";import"./brandNormalization-DqbDVEFp.js";import"./useManufacturers-CnRo2xv9.js";import"./index-CVsHSYzX.js";import"./index-Dp4vWfqQ.js";import"./index-DUWHinBq.js";import"./chevron-down-fIbqdpIG.js";import"./chevron-up-BWc9ZWPf.js";import"./check-BAqgBbKk.js";import"./flame-C20EtBQO.js";import"./en-US-BKA1EAZ_.js";import"./differenceInCalendarDays-D2PiOMpk.js";function Z(i){if(!i)return{color:"ð¡",label:"Unbekannt",className:"bg-warning/15 text-warning border-warning/30"};const l=(new Date(i).getTime()-Date.now())/(1e3*60*60);return l>24?{color:"ð¢",label:`${Math.round(l)}h`,className:"bg-success/15 text-success border-success/30"}:l>0?{color:"ð¡",label:`${Math.round(l)}h`,className:"bg-warning/15 text-warning border-warning/30"}:{color:"ð´",label:`${Math.abs(Math.round(l))}h überfällig`,className:"bg-destructive/15 text-destructive border-destructive/30"}}function _e(){const i=T(),{isAdmin:l,isLeadErfassung:y}=A(),{data:b,update:f}=I(),[c,k]=d.useState(""),{data:j=[]}=G(),S=d.useMemo(()=>{const s=new Map;return j.forEach(t=>s.set(t.inquiry_id,{score:t.score,tier:t.tier})),s},[j]),o=d.useMemo(()=>{const s=b.filter(r=>r.status==="Angebot versendet");if(!c)return s;const t=c.toLowerCase();return s.filter(r=>r.customer_name.toLowerCase().includes(t)||r.product_name.toLowerCase().includes(t)||(r.angebotsnummer||"").toLowerCase().includes(t))},[b,c]),x=d.useMemo(()=>[...o].sort((s,t)=>{const r=s.follow_up_due?new Date(s.follow_up_due).getTime():1/0,p=t.follow_up_due?new Date(t.follow_up_due).getTime():1/0;return r-p}),[o]);if(!l&&!y)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx("p",{className:"text-muted-foreground",children:"Kein Zugriff auf diesen Bereich."})});const w=o.filter(s=>{const t=s.follow_up_due;return t&&new Date(t).getTime()<Date.now()}).length,D=async s=>{const t=new Date,r=new Date(t.getTime()+48*60*60*1e3);await f({id:s,last_followup_date:t.toISOString(),follow_up_due:r.toISOString(),last_activity_at:t.toISOString()}),await N.from("inquiry_history").insert({inquiry_id:s,event_type:"followup",description:"ð Nachgefasst â neuer Follow-up in 48h"}),v({title:"ð Nachgefasst",description:"Nächster Follow-up in 48h"})},C=async(s,t)=>{await f({id:s,status:t,last_activity_at:new Date().toISOString()}),await N.from("inquiry_history").insert({inquiry_id:s,event_type:"status_change",description:`â
Kunde entschieden: ${t}`}),v({title:`Status: ${t}`})};return e.jsx("div",{className:"min-h-screen bg-background",children:e.jsxs("div",{className:"w-full px-6 xl:px-8 py-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>i("/kundenanfragen"),children:e.jsx(O,{size:18})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold tracking-tight",children:"ð Angebote nachfassen"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[x.length," Angebote versendet · ",w," überfällig"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(m,{className:"bg-blue-50 dark:bg-blue-950/30 border-blue-200 dark:border-blue-800",children:e.jsxs(u,{className:"pt-4 pb-3",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground uppercase tracking-wider",children:"Gesamt"}),e.jsx("p",{className:"text-2xl font-bold text-blue-700 dark:text-blue-400",children:o.length})]})}),e.jsx(m,{className:"bg-destructive/5 border-destructive/20",children:e.jsxs(u,{className:"pt-4 pb-3",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground uppercase tracking-wider",children:"ð´ Ãberfällig"}),e.jsx("p",{className:"text-2xl font-bold text-destructive",children:w})]})}),e.jsx(m,{className:"bg-warning/5 border-warning/20",children:e.jsxs(u,{className:"pt-4 pb-3",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground uppercase tracking-wider",children:"ð¡ Bald fällig"}),e.jsx("p",{className:"text-2xl font-bold text-warning",children:o.filter(s=>{const t=s.follow_up_due;if(!t)return!1;const r=(new Date(t).getTime()-Date.now())/(1e3*60*60);return r>0&&r<=24}).length})]})}),e.jsx(m,{className:"bg-blue-50 dark:bg-blue-950/30 border-blue-200 dark:border-blue-800",children:e.jsxs(u,{className:"pt-4 pb-3",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground uppercase tracking-wider",children:"Volumen"}),e.jsxs("p",{className:"text-2xl font-bold text-blue-700 dark:text-blue-400",children:["â¬",(o.reduce((s,t)=>s+(t.potenzialwert??0),0)/1e3).toFixed(0),"k"]})]})})]}),e.jsxs("div",{className:"relative max-w-md",children:[e.jsx(P,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground",size:16}),e.jsx(L,{placeholder:"Kunde, Produkt oder Angebotsnr. suchen...",value:c,onChange:s=>k(s.target.value),className:"pl-9"})]}),e.jsx("div",{className:"bg-card rounded-xl shadow-card overflow-hidden border border-blue-200/50 dark:border-blue-800/50",children:e.jsxs($,{children:[e.jsx(E,{children:e.jsxs(g,{className:"bg-blue-50/50 dark:bg-blue-950/20",children:[e.jsx(n,{className:"text-[11px] font-semibold uppercase",children:"Nr"}),e.jsx(n,{className:"text-[11px] font-semibold uppercase",children:"Kunde"}),e.jsx(n,{className:"text-[11px] font-semibold uppercase",children:"Angebotsnr."}),e.jsx(n,{className:"text-[11px] font-semibold uppercase",children:"Produkt"}),e.jsx(n,{className:"text-[11px] font-semibold uppercase",children:"Volumen"}),e.jsx(n,{className:"text-[11px] font-semibold uppercase",children:"ð¥ Score"}),e.jsx(n,{className:"text-[11px] font-semibold uppercase",children:"Gesendet"}),e.jsx(n,{className:"text-[11px] font-semibold uppercase",children:"Follow-up"}),e.jsx(n,{className:"text-[11px] font-semibold uppercase",children:"Aktionen"})]})}),e.jsx(K,{children:x.length===0?e.jsx(g,{children:e.jsx(a,{colSpan:9,className:"text-center py-8 text-muted-foreground",children:"Keine Angebote im Follow-up."})}):x.map(s=>{const t=Z(s.follow_up_due),r=S.get(s.id);return e.jsxs(g,{className:"hover:bg-blue-50/30 dark:hover:bg-blue-950/10",children:[e.jsx(a,{className:"font-mono text-xs",children:M(s)}),e.jsx(a,{className:"font-medium text-sm",children:s.customer_name}),e.jsx(a,{className:"text-sm font-mono",children:s.angebotsnummer||"â"}),e.jsx(a,{className:"text-sm max-w-[200px] truncate",children:s.product_name}),e.jsx(a,{className:"text-sm font-medium",children:s.potenzialwert?`â¬${(s.potenzialwert/1e3).toFixed(0)}k`:"â"}),e.jsx(a,{children:r?e.jsx(H,{score:r.score,tier:r.tier,size:"sm"}):e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"â"})}),e.jsx(a,{className:"text-xs text-muted-foreground whitespace-nowrap",children:s.angebot_versendet_am?U(new Date(s.angebot_versendet_am),"dd.MM.yyyy HH:mm"):"â"}),e.jsx(a,{children:e.jsxs(z,{variant:"outline",className:`text-[10px] ${t.className}`,children:[t.color," ",t.label]})}),e.jsx(a,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(_,{size:"sm",variant:"outline",className:"h-7 text-[11px] gap-1",onClick:()=>D(s.id),children:[e.jsx(R,{size:12})," Nachgefasst"]}),e.jsxs(q,{onValueChange:p=>C(s.id,p),children:[e.jsx(B,{className:"h-7 text-[11px] w-[130px]",children:e.jsx(V,{placeholder:"Entschieden..."})}),e.jsxs(F,{children:[e.jsx(h,{value:"Gewonnen",children:"â
Gewonnen"}),e.jsx(h,{value:"Verloren",children:"â Verloren"}),e.jsx(h,{value:"Verhandlung",children:"ð In Verhandlung"})]})]})]})})]},s.id)})})]})})]})})}export{_e 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.