1import{a as c,j as e}from"./trpc-vendor-Bta84Nsh.js";import{u as ee,t as i}from"./index-_3-B0itT.js";import{t as x,ax as te,z as re,cz as se,s as ne,aX as I,F as V,aj as C,X as ae,ci as de,bB as ie,bE as oe,aZ as le}from"./ui-vendor-NEZNvIbV.js";import"./react-vendor-DpXpH6G7.js";const ce=["Was ist heute am wichtigsten?","Welches Studio hinkt dem Ziel hinterher?","Wo kommen weniger Leads rein?","Was läuft gerade richtig gut?"];function je(){const{user:v}=ee(),o=v?.role==="admin",r=i.agent.briefing.useQuery(void 0,{staleTime:12e4,enabled:o}).data??null,a=i.useUtils(),u=i.agent.getMemory.useQuery(void 0,{staleTime:6e4,enabled:o}).data??{memory:[],repeated:[]},p=i.agent.forgetMemory.useMutation({onSuccess:()=>a.agent.getMemory.invalidate()}),l=(u.repeated??[]).map(t=>typeof t=="string"?t:t?.q).filter(Boolean),P=[...new Set([...l,...ce])].slice(0,6),k=i.agent.myTasks.useQuery(void 0,{staleTime:3e4,enabled:o}).data??[],q=i.agent.setTaskDone.useMutation({onSuccess:()=>a.agent.myTasks.invalidate()}),D=i.agent.pendingApprovals.useQuery(void 0,{enabled:o,refetchInterval:3e4}).data??[],$=i.agent.approveAction.useMutation({onSuccess:()=>{a.agent.pendingApprovals.invalidate(),a.agent.getMemory.invalidate(),x.success("Freigegeben")}}),L=i.agent.rejectAction.useMutation({onSuccess:()=>{a.agent.pendingApprovals.invalidate(),x.success("Abgelehnt")}}),[S,z]=c.useState([]),[A,B]=c.useState(""),[G,U]=c.useState(!1),b=i.agent.chat.useMutation(),Q=i.agent.transcribe.useMutation(),[N,K]=c.useState(!1),Z=c.useRef(null),E=c.useRef([]),W=c.useRef(null),[f,F]=c.useState([]),[j,H]=c.useState(!1),M=c.useRef(null),X=i.tasks.uploadAttachment.useMutation(),J=async t=>{if(!(!t||t.length===0)){H(!0);try{for(const s of Array.from(t)){if(s.size>50*1024*1024){x.error(`${s.name} ist gröÃer als 50 MB`);continue}const n=new Uint8Array(await s.arrayBuffer());let g="";for(let d=0;d<n.length;d++)g+=String.fromCharCode(n[d]);const h=await X.mutateAsync({fileBase64:btoa(g),fileName:s.name,mimeType:s.type||"application/octet-stream"});F(d=>[...d,h])}}catch(s){x.error(s?.message??"Upload fehlgeschlagen")}finally{H(!1),M.current&&(M.current.value="")}}},_=t=>F(s=>s.filter(n=>n.url!==t)),O=async()=>{try{const t=await navigator.mediaDevices.getUserMedia({audio:!0}),s=new MediaRecorder(t);E.current=[],s.ondataavailable=n=>{n.data.size&&E.current.push(n.data)},s.onstop=async()=>{t.getTracks().forEach(d=>d.stop());const n=new Blob(E.current,{type:s.mimeType||"audio/webm"});if(n.size<400){x.error("Aufnahme zu kurz");return}const g=new Uint8Array(await n.arrayBuffer());let h="";for(let d=0;d<g.length;d++)h+=String.fromCharCode(g[d]);Q.mutate({audioBase64:btoa(h),mimeType:n.type},{onSuccess:d=>B(m=>(m?m+" ":"")+(d?.text||"")),onError:d=>x.error(d?.message??"Transkription fehlgeschlagen")})},s.start(),Z.current=s,K(!0)}catch{x.error("Mikrofon nicht verfügbar / nicht erlaubt")}},Y=()=>{try{Z.current?.stop()}catch{}K(!1)};c.useEffect(()=>{W.current?.scrollTo({top:W.current.scrollHeight,behavior:"smooth"})},[S,b.isPending]);const R=t=>{const s=t.trim();if(!s&&f.length===0||b.isPending||j)return;const n=f,g=s||(n.length?"Bitte an das Team / eine Aufgabe geben.":""),h=[...S,{role:"user",content:g,attachments:n.length?n:void 0}];z(h),B(""),F([]);const d=h.map(m=>({role:m.role,content:m.content}));b.mutate({messages:d,attachments:n.length?n:void 0},{onSuccess:m=>{z(y=>[...y,{role:"assistant",content:m?.reply||"â"}]),(m?.actions??[]).forEach(y=>x.success(y)),m?.actions?.length&&(a.agent.getMemory.invalidate(),a.agent.briefing.invalidate(),a.agent.myTasks.invalidate())},onError:m=>{x.error(m?.message??"Fehler"),z(y=>[...y,{role:"assistant",content:`â ${m?.message??"Konnte nicht antworten."}`}])}})};return["admin","manager","marketing"].includes(v?.role)?e.jsx("div",{className:"agency-cockpit-dark -m-4 min-h-screen p-4 sm:p-6",children:e.jsxs("div",{className:"max-w-5xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 ring-1 ring-primary/30 flex items-center justify-center",children:e.jsx(re,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-foreground tracking-tight",children:"KI-Morgen-Agent"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r?.date??"Dein Geschäft am Ziel orientiert â fragen & handeln"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("a",{href:"/admin/ki-agent/chat",title:"Schlanke Handy-Ansicht â nur Chat, überall bestätigen",className:"inline-flex items-center gap-1.5 rounded-md border border-primary/40 bg-primary/10 text-sm px-3 py-1.5 text-foreground",children:"ð± Handy-Chat"}),o&&e.jsxs("button",{onClick:()=>U(t=>
1!t),className:"inline-flex items-center gap-1.5 rounded-md border border-border text-sm px-3 py-1.5 text-foreground",children:[e.jsx(se,{className:"w-4 h-4"})," Schwellen"]})]})]}),o&&G&&e.jsx(me,{onClose:()=>U(!1)}),!o&&e.jsxs("div",{className:"rounded-xl border border-amber-500/40 bg-amber-500/5 p-3 mb-4 text-xs text-amber-700 dark:text-amber-300",children:['ð Du kannst Aufgaben direkt anlegen lassen. Andere Aktionen (z. B. âmerken") gehen zur ',e.jsx("b",{children:"Freigabe an den Admin"}),", bevor sie ausgeführt werden."]}),o&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-3 mb-4",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-card p-3.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:"Verträge Monat"}),e.jsxs("div",{className:"text-2xl font-bold mt-1 text-foreground",children:[r?r.goals.contractsMonth:"â",r?.goals.monthlyGoal?e.jsxs("span",{className:"text-sm text-muted-foreground",children:[" / ",r.goals.monthlyGoal]}):null]}),e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-1",children:["Monat ",r?.monthProgressPct??"â"," % um"]})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card p-3.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:"Leads (7 Tage)"}),e.jsx("div",{className:`text-2xl font-bold mt-1 ${r&&r.leadsTrend.thisWeek>=r.leadsTrend.prevWeek?"text-emerald-400":"text-red-400"}`,children:r?r.leadsTrend.thisWeek:"â"}),e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-1",children:["Vorwoche ",r?.leadsTrend.prevWeek??"â"]}
1)]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card p-3.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:"LeadâVertrag"}),e.jsx("div",{className:`text-2xl font-bold mt-1 ${r&&r.conversion.thisWeekPct>=r.conversion.prevWeekPct?"text-emerald-400":"text-red-400"}`,children:r?`${r.conversion.thisWeekPct} %`:"â"}),e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-1",children:["Vorwoche ",r?.conversion.prevWeekPct??"â"," %"]})]})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 mb-4",children:[e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/[0.05] p-3.5",children:[e.jsx("div",{className:"text-sm font-bold text-red-400 mb-2",children:"â² Jetzt ranschauen"}),r&&r.warnings.length?e.jsx("ul",{className:"space-y-1",children:r.warnings.map((t,s)=>e.jsxs("li",{className:"text-xs text-foreground/90 leading-relaxed",children:["⢠",t]},s))}):e.jsx("div",{className:"text-xs text-muted-foreground",children:"Keine Warnungen â Quoten & Trends stabil."})]}),e.jsxs("div",{className:"rounded-xl border border-emerald-500/30 bg-emerald-500/[0.05] p-3.5",children:[e.jsx("div",{className:"text-sm font-bold text-emerald-400 mb-2",children:"â Läuft gut â nicht anfassen"}),r&&r.positives.length?e.jsx("ul",{className:"space-y-1",children:r.positives.map((t,s)=>e.jsxs("li",{className:"text-xs text-foreground/90 leading-relaxed",children:["⢠",t]},s))}):e.jsx("div",{className:"text-xs text-muted-foreground",children:"Noch keine Highlights im Zeitraum."})]})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 mb-4",children:[e.jsxs("div",{className:"text-sm font-bold text-foreground mb-2",children:["Meine offenen Aufgaben",k.length?` (${k.length})`:""]}),k.length===0?e.jsx("div",{className:"text-xs text-muted-foreground",children:"Nichts offen für dich â alles erledigt â"}):e.jsx("div",{className:"space-y-1.5",children:k.map(t=>e.jsxs("div",{className:"flex items-center gap-2.5 text-sm",children:[e.jsx("button",{onClick:()=>q.mutate({id:t.id}),title:"Als erledigt abhaken",className:"w-4 h-4 rounded border border-border hover:border-primary hover:bg-primary/20 flex-shrink-0 transition-colors"}),e.jsx("span",{className:"flex-1 text-foreground",children:t.title}),(t.priority==="urgent"||t.priority==="high")&&e.jsx("span",{className:"text-[10px] font-bold text-red-400 uppercase",children:t.priority==="urgent"?"dringend":"hoch"}),t.dueDate?e.jsx("span",{className:"text-[11px] text-muted-foreground whitespace-nowrap",children:new Date(Number(t.dueDate)).toLocaleDateString("de-DE")}):null]},t.id))})]})]}),o&&D.length>0&&e.jsxs("div",{className:"rounded-xl border border-amber-500/40 bg-amber-500/5 p-4 mb-4",children:[e.jsxs("div",{className:"text-sm font-bold text-amber-600 dark:text-amber-400 mb-2",children:["ð KI-Freigaben (",D.length,")"]}),e.jsx("div",{className:"space-y-2",children:D.map(t=>e.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-foreground",children:t.tool==="remember"?e.jsxs(e.Fragment,{children:["â",t.input?.note,'" merken']}):`${t.tool}`}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["von ",t.requestedByName??"?",t.createdAt?` · ${new Date(Number(t.createdAt)).toLocaleDateString("de-DE")}`:""]})]}),e.jsx("button",{onClick:()=>$.mutate({id:t.id}),disabled:$.isPending,className:"text-xs font-bold px-2.5 py-1 rounded-md bg-emerald-600 text-white",children:"Freigeben"}),e.jsx("button",{onClick:()=>L.mutate({id:t.id}),disabled:L.isPending,className:"text-xs font-bold px-2.5 py-1 rounded-md border border-border text-muted-foreground",children:"Ablehnen"})]},t.id))})]}),u.memory?.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Merkt sich für dich:"}),u.memory.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs rounded-full border border-border bg-card px-2.5 py-1 text-foreground",children:["ð§ ",t,e.jsx("button",{onClick:()=>p.mutate({note:t}),title:"Vergessen",className:"text-muted-foreground hover:text-red-400",children:"â"})]},t))]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card flex flex-col",style:{height:460},children:[e.jsxs("div",{ref:W,className:"flex-1 overflow-y-auto p-4 space-y-3",children:[S.length===0&&e.jsxs("div",{className:"text-center py-6",children:[e.jsx(ne,{className:"w-6 h-6 text-primary mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Frag mich zu deinen Zahlen, Studios, Kampagnen oder was heute dran ist."}),e.jsx("div",{className:"flex flex-wrap gap-2 justify-center",children:P.map(t=>e.jsx("button",{onClick:()=>R(t),className:"text-xs rounded-full border border-border px-3 py-1.5 text-foreground hover:bg-muted/40",children:t},t))})]}),S.map((t,s)=>e.jsx("div",{className:`flex ${t.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[82%] rounded-2xl px-3.5 py-2.5 text-sm leading-relaxed whitespace-pre-wrap ${t.role==="user"?"bg-primary text-primary-foreground rounded-br-sm":"bg-muted/50 text-foreground rounded-bl-sm border border-border"}`,children:[t.content,t.attachments&&t.attachments.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:t.attachments.map(n=>e.jsxs("a",{href:n.url,target:"_blank",rel:"noreferrer",className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] ${t.role==="user"?"bg-primary-foreground
1/15":"bg-background border border-border"}`,children:[n.mimeType.startsWith("image/")?e.jsx(I,{className:"w-3 h-3"}):e.jsx(V,{className:"w-3 h-3"}),e.jsx("span",{className:"max-w-[140px] truncate",children:n.name})]},n.url))})]})},s)),b.isPending&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"rounded-2xl px-3.5 py-2.5 bg-muted/50 border border-border",children:e.jsx(C,{className:"w-4 h-4 animate-spin text-muted-foreground"})})})]}),e.jsxs("div",{className:"border-t border-border p-3",children:[(f.length>0||j)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-2",children:[f.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border bg-muted/40 px-2 py-1 text-[11px] text-foreground",children:[t.mimeType.startsWith("image/")?e.jsx(I,{className:"w-3 h-3"}):e.jsx(V,{className:"w-3 h-3"}),e.jsx("span",{className:"max-w-[160px] truncate",children:t.name}),e.jsx("button",{onClick:()=>_(t.url),title:"Entfernen",className:"text-muted-foreground hover:text-foreground",children:e.jsx(ae,{className:"w-3 h-3"})})]},t.url)),j&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(C,{className:"w-3 h-3 animate-spin"})," lädt hochâ¦"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{ref:M,type:"file",multiple:!0,accept:"image/*,.pdf,.doc,.docx,.xls,.xlsx,.csv,.txt",className:"hidden",onChange:t=>J(t.target.files)}),e.jsx("button",{onClick:()=>M.current?.click(),disabled:j||b.isPending,title:"Datei oder Foto anhängen",className:"inline-flex items-center justify-center rounded-lg w-9 h-9 shrink-0 border border-border text-foreground hover:bg-muted/40 transition-colors disabled:opacity-50",children:j?e.jsx(C,{className:"w-4 h-4 animate-spin"}):e.jsx(de,{className:"w-4 h-4"})}),e.jsx("button",{onClick:N?Y:O,disabled:Q.isPending,title:N?"Aufnahme stoppen & übertragen":"Sprachnachricht aufnehmen",className:`inline-flex items-center justify-center rounded-lg w-9 h-9 shrink-0 border transition-colors disabled:opacity-50 ${N?"bg-red-500/20 border-red-500/50 text-red-400 animate-pulse":"border-border text-foreground hover:bg-muted/40"}`,children:Q.isPending?e.jsx(C,{className:"w-4 h-4 animate-spin"}):N?e.jsx(ie,{className:"w-4 h-4"}):e.jsx(oe,{className:"w-4 h-4"})}),e.jsx("input",{value:A,onChange:t=>B(t.target.value),onKeyDown:t=>{t.key==="Enter"&&R(A)},placeholder:N?"Sprich jetzt⦠(Stopp zum Ãbertragen)":f.length?"Wem geben? z.B. an die Assistenzâ¦":"Frag den Agenten oder sprichâ¦",className:"flex-1 text-sm px-3 py-2 rounded-lg border border-border bg-background text-foreground outline-none focus:border-primary"}),e.jsx("button",{onClick:()=>R(A),disabled:b.isPending||j||!A.trim()&&f.length===0,className:"inline-flex items-center gap-1.5 rounded-lg bg-primary text-primary-foreground text-sm font-medium px-3.5 py-2 disabled:opacity-50",children:e.jsx(le,{className:"w-4 h-4"})})]})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-3",children:"Der Agent nutzt nur echte CRM-Zahlen (heutiger Stand). Das Morgen-Briefing geht zusätzlich täglich per Mail an den Admin."})]})}):e.jsx("div",{className:"max-w-4xl mx-auto p-6",children:e.jsxs("div",{className:"rounded-xl border border-dashed border-border bg-muted/20 py-14 text-center",children:[e.jsx(te,{className:"w-8 h-8 text-muted-foreground/50 mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Kein Zugriff â nur für Admin / Marketing-Lead."})]})})}function me({onClose:v}){const o=i.useUtils(),w=i.agent.getThresholds.useQuery(void 0,{staleTime:6e4}),r=i.agent.setThresholds.useMutation({onSuccess:()=>{o.agent.getThresholds.invalidate(),o.agent.briefing.invalidate(),x.success("Schwellen gespeichert"),v()},onError:l=>x.error(l?.message??"Fehler")}),[a,T]=c.useState(null);if(c.useEffect(()=>{w.data&&!a&&T({...w.data})},[w.data,a]),!a)return e.jsx("div",{className:"rounded-xl border border-border bg-card p-4 mb-4 text-sm text-muted-foreground",children:"Ladenâ¦"});const u="w-20 text-sm px-2 py-1.5 rounded-md border border-border bg-background text-foreground outline-none focus:border-primary",p=(l,P)=>T({...a,[l]:Number(P.replace(/[^0-9]/g,"")||0)});return e.jsxs("div",{className:"rounded-xl border border-primary/30 bg-card p-4 mb-4",children:[e.jsx("div",{className:"text-sm font-bold text-foreground mb-3",children:"Schwellen â ab wann der Agent Alarm schlägt"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("label",{className:"flex items-center justify-between gap-2 text-xs text-foreground",children:["Leads-Einbruch ab (â%)",e.jsx("input",{value:a.leadDropPct,onChange:l=>p("leadDropPct",l.target.value),className:u,inputMode:"numeric"})]}),e.jsxs("label",{className:"flex items-center justify-between gap-2 text-xs text-foreground",children:["Quoten-Einbruch ab (â%)",e.jsx("input",{value:a.convDropPct,onChange:l=>p("convDropPct",l.target.value),className:u,inputMode:"numeric"})]}),e.jsxs("label",{className:"flex items-center justify-between gap-2 text-xs text-foreground",children:['âHinter Ziel" ab (< % vom Soll)',e.jsx("input",{value:a.goalBehindPct,onChange:l=>p("goalBehindPct",l.target.value),className:u,inputMode:"numeric"})]}),e.jsxs("label",{className:"flex items-center justify-between gap-2 text-xs text-foreground",children:["Brief
1ing-Uhrzeit (Std)",e.jsx("input",{value:a.sendHour,onChange:l=>p("sendHour",l.target.value),className:u,inputMode:"numeric"})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx("button",{onClick:v,className:"text-sm px-3 py-1.5 rounded-md border border-border text-foreground",children:"Abbrechen"}),e.jsx("button",{onClick:()=>r.mutate(a),disabled:r.isPending,className:"text-sm font-medium px-3.5 py-1.5 rounded-md bg-primary text-primary-foreground disabled:opacity-50",children:r.isPending?"Speichertâ¦":"Speichern"})]})]})}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.