1import{j as e,a as M}from"./trpc-vendor-Bta84Nsh.js";import{u as Ke}from"./react-vendor-DpXpH6G7.js";import{t as C,D as be,a as je,b as fe,c as Ne,B as F,d as Be,L as _,I as K,C as V,e as B,f as Q,g as re,h as I,u as Me,S as at,i as ce}from"./index-_3-B0itT.js";import{W as nt}from"./WebsiteFunnelCard-76_uKmII.js";import{S as Qe,a as We,b as _e,c as Ge,d as me}from"./select-DqcHU93A.js";import{t as te,j as Ce,a_ as lt,ap as Te,a$ as dt,m as ue,b0 as ot,W as it,b1 as ct,v as Ve,aE as Ue,aa as xt,a7 as Ze,K as He,b2 as mt,b3 as ut,aZ as ht,A as Ye,aP as pt,b4 as he,b5 as gt,b6 as bt,b7 as jt,b8 as pe,b9 as ft,ba as Le,bb as $e,bc as Fe,bd as Ae,be as J,p as Ee,o as Nt,bf as Se,bg as ee,l as De,n as yt,F as qe,bh as ye,bi as ve,bj as vt,aC as kt,bk as Re,U as wt,_ as Ct,aD as Je,a8 as Tt,as as St,ar as Dt}from"./ui-vendor-NEZNvIbV.js";import{T as Mt,a as Lt,b as ae,c as ne}from"./tabs-YRkpqMYJ.js";function $t({brandId:a}){const{data:u,isLoading:h}=C.dashboard.appointmentsTodayYesterday.useQuery({brandId:a},{staleTime:6e4});if(h||!u)return e.jsxs("div",{className:"bg-card rounded-xl border border-border p-5 animate-pulse",children:[e.jsx("div",{className:"h-5 bg-muted/40 rounded w-1/3 mb-4"}),e.jsx("div",{className:"h-32 bg-muted/30 rounded"})]});const c=t=>new Date(t).toLocaleTimeString("de-DE",{timeZone:"Europe/Berlin",hour:"2-digit",minute:"2-digit"}),p={closed:"Vertrag",follow_up:"Folgetermin",no_show:"No-Show",not_interested:"Kein Interesse",thinking:"Ãberlegt"},m=u.today??[],n=u.yesterday??[],j=u.tomorrow??[],d=Date.now(),g=m.filter(t=>t.scheduledAt<d&&!t.hasFeedback).length,r=n.filter(t=>!t.hasFeedback).length,b=g+r,N=t=>{const s=t.feedbackOutcome?p[t.feedbackOutcome]??t.feedbackOutcome:null,i=t.feedbackOutcome==="closed"?"bg-emerald-500/20 text-emerald-300 border-emerald-500/30":t.feedbackOutcome==="follow_up"?"bg-blue-500/20 text-blue-300 border-blue-500/30":t.feedbackOutcome==="no_show"?"bg-rose-500/20 text-rose-300 border-rose-500/30":t.feedbackOutcome==="not_interested"?"bg-gray-500/20 text-gray-300 border-gray-500/30":"bg-amber-500/20 text-amber-300 border-amber-500/30";return s?e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded border shrink-0 ${i}`,children:s}):e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-orange-500/15 text-orange-300 border border-orange-500/30 shrink-0",children:"â kein Feedback"})};return e.jsxs("div",{className:"bg-card rounded-xl border border-border p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("h2",{className:"font-semibold flex items-center gap-2 text-sm",children:["ð
Termine gestern · heute · morgen",!a&&e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:"markenübergreifend"})]}),b>0&&e.jsxs("span",{className:"text-xs px-2 py-1 rounded-full bg-orange-500/15 text-orange-300 border border-orange-500/30",children:[b," offene Feedback",b===1?"":"s"]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-purple-500/20 bg-purple-500/5 p-3",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("h3",{className:"text-xs font-semibold text-purple-300 uppercase tracking-wide",children:["Gestern (",n.length,")"]})}),n.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:"Keine Termine gestern."}):e.jsx("div",{className:"space-y-1.5 max-h-[400px] overflow-y-auto",children:n.map(t=>e.jsxs("div",{className:"text-xs flex items-center gap-2 py-1.5 border-b border-border/30 last:border-0",children:[e.jsx("span",{className:"font-mono text-purple-400 shrink-0 w-12",children:c(t.scheduledAt)}),e.jsx("span",{className:"font-medium text-foreground truncate flex-1",children:t.leadName}),!a&&t.brandName&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted/40 text-muted-foreground shrink-0",children:t.brandName}),N(t)]},t.id))})]}),e.jsxs("div",{className:"rounded-lg border border-blue-500/20 bg-blue-500/5 p-3",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("h3",{className:"text-xs font-semibold text-blue-300 uppercase tracking-wide",children:["Heute (",m.length,")"]})}),m.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:"Keine Termine heute."}):e.jsx("div",{className:"space-y-1.5 max-h-[400px] overflow-y-auto",children:m.map(t=>{const s=t.scheduledAt<d;return e.jsxs("div",{className:"text-xs flex items-center gap-2 py-1.5 border-b border-border/30 last:border-0",children:[e.jsx("span",{className:`font-mono shrink-0 w-12 ${s?"text-muted-foreground line-through":"text-blue-400"}`,children:c(t.scheduledAt)}),e.jsx("span",{className:"font-medium text-foreground truncate flex-1",children:t.leadName}),!a&&t.brandName&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted/40 text-muted-foreground shrink-0",children:t.brandName}),s?N(t):t.assignedName?e.jsxs("span",{className:"text-[10px] text-muted-foreground shrink-0",children:["â ",t.assignedName]}):null]},t.id)})})]}),e.jsxs("div",{className:"rounded-lg border border-emerald-500/20 bg-emerald-500/5 p-3",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("h3",{className:"text-xs font-semibold text-emerald-300 uppercase tracking-wide",children:["Morgen (",j.length,")"]})}),j.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:"Keine Termine morgen."}):e.jsx("div",{className:"space-y-1.5 max-h-[400px] overflow-y-auto",children:j.map(t=>e.jsxs("div",{className:"text-xs flex items-center gap-2 py-1.5 border-b border-border/30 last:border-0",children:[e.jsx("span",{className:"font-mono text-emerald-400 shrink-0 w-12",children:c(t.scheduledAt)}),e.jsx("span",{className:"font-medium text-foreground truncate flex-1",children:t.leadName}),!a&&t.brandName&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted/40 text-muted-foreground shrink-0",children:t.brandName}),t.assignedName&&e.jsxs("span",{className:"text-[10px] text-muted-foreground shrink-0",children:["â ",t.assignedName]})]},t.id))})]})]})]})}const Xe={ad_budget:"Werbe-Budget (extern)",promoter:"Promoter-Lohn",flyer_print:"Flyer-Druck",agency_fee:"Agentur-Fee",software:"Software / Tools",staff:"Personal",rent:"Miete",other:"Sonstiges"},et={one_time:"Einmalig",monthly:"Monatlich",sprint:"Pro Sprint"},tt=[{value:"",label:"Overhead (nicht zugeordnet)"},{value:"ads",label:"â Ads"},{value:"flyer",label:"â Flyer"},{value:"sprint_promoter",label:"â Promoter"},{value:"referral",label:"â Empfehlung"},{value:"online",label:"â Online"}],ke={ad_budget:"ads",promoter:"sprint_promoter",flyer_print:"flyer"};function Ft({open:a,onOpenChange:u,brandId:h,sprintId:c,defaultStartDate:p,defaultEndDate:m}){const n=C.useUtils(),j=C.costs.list.useQuery({brandId:h,sprintId:c},{enabled:a}
1),[d,g]=M.useState(null),[r,b]=M.useState(!1),N=C.costs.delete.useMutation({onSuccess:()=>{te.success("Kosten gelöscht"),n.costs.list.invalidate({brandId:h,sprintId:c}),n.costs.summary.invalidate()},onError:i=>te.error(i.message)}),t=j.data??[],s=i=>(i/100).toLocaleString("de-DE",{style:"currency",currency:"EUR"});return e.jsx(be,{open:a,onOpenChange:u,children:e.jsxs(je,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[e.jsx(fe,{children:e.jsx(Ne,{children:c?"Sprint-Kosten verwalten":"Studio-Kosten verwalten"})}),e.jsxs("div",{className:"py-2 space-y-3",children:[!r&&e.jsxs(F,{size:"sm",onClick:()=>{g(null),b(!0)},className:"bg-orange-500 hover:bg-orange-600 text-white",children:[e.jsx(Ce,{className:"w-4 h-4 mr-1"})," Neue Kostenposition"]}),r&&e.jsx(At,{initial:d,brandId:h,sprintId:c,defaultStartDate:p,defaultEndDate:m,onCancel:()=>{b(!1),g(null)},onSaved:()=>{b(!1),g(null),n.costs.list.invalidate({brandId:h,sprintId:c}),n.costs.summary.invalidate()}}),e.jsx("div",{className:"text-xs text-muted-foreground uppercase mt-4",children:"Ãbersicht"}),t.length===0?e.jsx("div",{className:"text-sm text-muted-foreground py-4 text-center",children:"Noch keine Kosten eingetragen."}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted-foreground uppercase border-b border-border",children:[e.jsx("th",{className:"text-left py-2",children:"Kategorie"}),e.jsx("th",{className:"text-left py-2",children:"Betrag"}),e.jsx("th",{className:"text-left py-2",children:"Periode"}),e.jsx("th",{className:"text-left py-2",children:"Zeitraum"}),e.jsx("th",{className:"text-left py-2",children:"Notiz"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:t.map(i=>e.jsxs("tr",{className:"border-b border-border",children:[e.jsxs("td",{className:"py-2",children:[e.jsx("div",{className:"font-medium",children:Xe[i.category]??i.category}),i.linkedSource&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["â ",tt.find(l=>l.value===i.linkedSource)?.label.replace(/^â /,"")??i.linkedSource]})]}),e.jsx("td",{className:"py-2 font-semibold",children:s(Number(i.amountCents))}),e.jsx("td",{className:"py-2 text-xs",children:et[i.period]??i.period}),e.jsxs("td",{className:"py-2 text-xs",children:[typeof i.startDate=="string"?i.startDate:new Date(i.startDate).toISOString().slice(0,10),i.endDate&&e.jsxs(e.Fragment,{children:[" â ",typeof i.endDate=="string"?i.endDate:new Date(i.endDate).toISOString().slice(0,10)]})]}),e.jsx("td",{className:"py-2 text-xs text-muted-foreground truncate max-w-[140px]",children:i.note??""}),e.jsxs("td",{className:"py-2 text-right whitespace-nowrap",children:[e.jsx(F,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:()=>{g(i),b(!0)},children:e.jsx(lt,{className:"w-3.5 h-3.5"})}),e.jsx(F,{size:"sm",variant:"ghost",className:"h-7 px-2 text-red-400",onClick:()=>{confirm("Kostenposition wirklich löschen?")&&N.mutate({id:i.id})},children:e.jsx(Te,{className:"w-3.5 h-3.5"})})]})]},i.id))})]})]}),e.jsx(Be,{children:e.jsx(F,{variant:"outline",onClick:()=>u(!1),children:"SchlieÃen"})})]})})}function At({initial:a,brandId:u,sprintId:h,defaultStartDate:c,defaultEndDate:p,onCancel:m,onSaved:n}){const j=new Date().toISOString().slice(0,10),[d,g]=M.useState(a?.category??"promoter"),[r,b]=M.useState(a?.linkedSource??ke[a?.category??"promoter"]??""),[N,t]=M.useState(a?.amountCents!=null?(Number(a.amountCents)/100).toString():""),[s,i]=M.useState(a?.period??(h?"sprint":"one_time")),[l,y]=M.useState(a?.startDate?typeof a.startDate=="string"?a.startDate:new Date(a.startDate).toISOString().slice(0,10):c??j),[w,S]=M.useState(a?.endDate?typeof a.endDate=="string"?a.endDate:new Date(a.endDate).toISOString().slice(0,10):p??""),[v,P]=M.useState(a?.note??""),[D,E]=M.useState(a?a.sprintId!=null:h!=null),R=C.costs.upsert.useMutation({onSuccess:()=>{te.success("Kosten gespeichert"),n()},onError:f=>te.error(f.message)}),x=f=>{g(f),ke[f]&&b(ke[f])};return e.jsxs("div",{className:"rounded-lg border border-orange-500/30 bg-
1orange-500/5 p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Kategorie"}),e.jsx("select",{value:d,onChange:f=>x(f.target.value),className:"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm",children:Object.entries(Xe).map(([f,L])=>e.jsx("option",{value:f,children:L},f))})]}),e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Betrag (â¬)"}),e.jsx(K,{type:"number",step:"0.01",value:N,onChange:f=>t(f.target.value),placeholder:"z.B. 150",className:"mt-1"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Periode"}),e.jsx("select",{value:s,onChange:f=>i(f.target.value),className:"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm",children:Object.entries(et).map(([f,L])=>e.jsx("option",{value:f,children:L},f))})]}),e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Quelle (CPL/CAC-Zuordnung)"}),e.jsx("select",{value:r,onChange:f=>b(f.target.value),className:"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm",children:tt.map(f=>e.jsx("option",{value:f.value,children:f.label},f.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Start"}),e.jsx(K,{type:"date",value:l,onChange:f=>y(f.target.value),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Ende (optional)"}),e.jsx(K,{type:"date",value:w,onChange:f=>S(f.target.value),className:"mt-1"})]})]}),e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Notiz"}),e.jsx(K,{value:v,onChange:f=>P(f.target.value),placeholder:"z.B. Lohn Promoter Müller April",className:"mt-1"})]}),h&&e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:f=>E(f.target.checked)}),"An diesen Sprint binden (sonst Brand-weite Kosten)"]}),e.jsxs("div",{className:"flex gap-2 justify-end pt-2 border-t border-border",children:[e.jsx(F,{variant:"outline",size:"sm",onClick:m,children:"Abbrechen"}),e.jsx(F,{size:"sm",disabled:!N||R.isPending,onClick:()=>R.mutate({id:a?.id,brandId:u,sprintId:D&&h?h:null,category:d,linkedSource:r||null,amountCents:Math.round(parseFloat(N)*100)||0,period:s,startDate:l,endDate:w||null,note:v||null}),className:"bg-orange-500 hover:bg-orange-600 text-white",children:R.isPending?"Speichert...":a?"Aktualisieren":"Anlegen"})]})]})}function Et({open:a,onOpenChange:u,sprint:h}){const c=C.useUtils(),{data:p=[]}=C.contractTypes.list.useQuery({activeOnly:!1}),[m,n]=M.useState(h.commissionMode??"none"),[j,d]=M.useState(()=>{const s=h.commissionTiers??[];return s.length>0?s.map(i=>({minContracts:Number(i.minContracts??0),perContractCents:Number(i.perContractCents??0),bonusCents:Number(i.bonusCents??0),label:String(i.label??"")})):[{minContracts:0,perContractCents:4e3,bonusCents:0,label:"Bronze"}]}),[g,r]=M.useState(()=>(h.commissionByContractType??[]).map(i=>({contractTypeId:Number(i.contractTypeId),perContractCents:Number(i.perContractCents??0),label:String(i.label??"")})));M.useEffect(()=>{a&&n(h.commissionMode??"none")},[a,h.commissionMode]);const b=C.costs.saveCommissionConfig.useMutation({onSuccess:()=>{te.success("Provisions-Konfig gespeichert"),c.sprints.get.invalidate({id:h.id}),c.costs.summary.invalidate(),u(!1)},onError:s=>te.error(s.message)}),N=()=>{b.mutate({sprintId:h.id,commissionMode:m,commissionTiers:m==="tiered_retroactive"||m==="tiered_progressive"?j.map(s=>({minContracts:s.minContracts,perContractCents:s.perContractCents,bonusCents:s.bonusCents,label:s.label||void 0})):void 0,commissionByContractType:m==="per_contract_type"?g.map(s=>({contractTypeId:s.contractTypeId,perContractCents:s.perContractCents,label:s.label||void 0})):void 0})},t=p.filter(s=>s.brandId===h.brandId||s.brandId==null||s.sprintId===h.id);return e.jsx(be,{open:a,onOpenChange:u,children:e.jsxs(je,{className:"max-w-2xl",children:[e.jsx(fe,{children:e.jsx(Ne,{children:"Provisions-Modell"})}),e.jsxs("div",{className:"py-2 space-y-4",children:[e.jsxs("div",{children:[e.jsx(_,{className:"text-xs uppercase",children:"Modell"}),e.jsx("div",{className:"grid grid-cols-2 gap-2 mt-1",children:[["none","Keine Provision","Sprint ohne Vergütung tracken"],["tiered_retroactive","Retroaktiv (Schwelle)","Bei 50 â ALLE rückwirkend zur höheren Rate"],["tiered_progressive","Progressiv (Treppe)","Pro Tier nur die Verträge ab Schwelle"],["per_contract_type","Pro Vertragstyp","Fix je Laufzeit (12/24/36 Monate)"]].map(([s,i,l])=>e.jsxs("button",{type:"button",onClick:()=>n(s),className:`px-3 py-2 rounded-md border text-left ${m===s?"border-orange-500 bg-orange-500/10":"border-border hover:border-orange-500/40"}`,children:[e.jsx("div",{className:"text-sm font-medium",children:i}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l})]},s))})]}),(m==="tiered_retroactive"||m==="tiered_progressive")&&e.jsxs("div",{children:[e.jsx(_,{className:"text-xs uppercase",children:"Provisions-Stufen"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 mb-2",children:m==="tiered_retroactive"?"Sobald minContracts erreicht, gilt diese Rate für ALLE Verträge inkl. der bisherigen (rückwirkend). Bonu
1s wird einmalig addiert.":"Pro Stufe nur die Verträge ab minContracts zur jeweiligen Rate (Treppe)."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"grid grid-cols-12 gap-2 text-xs text-muted-foreground uppercase px-2",children:[e.jsx("div",{className:"col-span-3",children:"Ab Vertrag #"}),e.jsx("div",{className:"col-span-3",children:"Rate (â¬/Vertrag)"}),e.jsx("div",{className:"col-span-2",children:"Bonus (â¬)"}),e.jsx("div",{className:"col-span-3",children:"Label"}),e.jsx("div",{})]}),j.map((s,i)=>e.jsxs("div",{className:"grid grid-cols-12 gap-2 items-center",children:[e.jsx(K,{type:"number",min:0,value:s.minContracts,onChange:l=>{const y=parseInt(l.target.value)||0;d(w=>w.map((S,v)=>v===i?{...S,minContracts:y}:S))},className:"col-span-3 h-8"}),e.jsx(K,{type:"number",step:"0.01",min:0,value:(s.perContractCents/100).toString(),onChange:l=>{const y=Math.round(parseFloat(l.target.value)*100)||0;d(w=>w.map((S,v)=>v===i?{...S,perContractCents:y}:S))},className:"col-span-3 h-8"}),e.jsx(K,{type:"number",step:"0.01",min:0,value:(s.bonusCents/100).toString(),onChange:l=>{const y=Math.round(parseFloat(l.target.value)*100)||0;d(w=>w.map((S,v)=>v===i?{...S,bonusCents:y}:S))},className:"col-span-2 h-8"}),e.jsx(K,{value:s.label,onChange:l=>d(y=>y.map((w,S)=>S===i?{...w,label:l.target.value}:w)),className:"col-span-3 h-8",placeholder:"z.B. Bronze"}),e.jsx(F,{size:"sm",variant:"ghost",className:"h-8 px-1 text-red-400",onClick:()=>d(l=>l.filter((y,w)=>w!==i)),children:e.jsx(Te,{className:"w-3.5 h-3.5"})})]},i)),e.jsxs(F,{size:"sm",variant:"outline",onClick:()=>d(s=>[...s,{minContracts:s.length>0?Number(s[s.length-1].minContracts)+50:0,perContractCents:s.length>0?Number(s[s.length-1].perContractCents)+2e3:4e3,bonusCents:0,label:""}]),children:[e.jsx(Ce,{className:"w-4 h-4 mr-1"})," Stufe hinzufügen"]})]})]}),m==="per_contract_type"&&e.jsxs("div",{children:[e.jsx(_,{className:"text-xs uppercase",children:"Fix-Provision pro Vertragstyp"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 mb-2",children:"Trage pro Vertragstyp die Fix-Provision ein (typisch: 12-Monate â¬40, 24-Monate â¬80, 36-Monate â¬120)."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"grid grid-cols-12 gap-2 text-xs text-muted-foreground uppercase px-2",children:[e.jsx("div",{className:"col-span-5",children:"Vertragstyp"}),e.jsx("div",{className:"col-span-3",children:"Provision (â¬)"}),e.jsx("div",{className:"col-span-3",children:"Label"}),e.jsx("div",{})]}),g.map((s,i)=>e.jsxs("div",{className:"grid grid-cols-12 gap-2 items-center",children:[e.jsxs("select",{value:s.contractTypeId,onChange:l=>r(y=>y.map((w,S)=>S===i?{...w,contractTypeId:parseInt(l.target.value)}:w)),className:"col-span-5 h-8 rounded-md border border-border bg-background px-2 text-sm",children:[e.jsx("option",{value:0,children:"Bitte wählen..."}),t.map(l=>e.jsxs("option",{value:l.id,children:[l.name," · ",l.price," â¬"]},l.id))]}),e.jsx(K,{type:"number",step:"0.01",min:0,value:(s.perContractCents/100).toString(),onChange:l=>{const y=Math.round(parseFloat(l.target.value)*100)||0;r(w=>w.map((S,v)=>v===i?{...S,perContractCents:y}:S))},className:"col-span-3 h-8"}),e.jsx(K,{value:s.label,onChange:l=>r(y=>y.map((w,S)=>S===i?{...w,label:l.target.value}:w)),className:"col-span-3 h-8",placeholder:"z.B. 12 Monate"}),e.jsx(F,{size:"sm",variant:"ghost",className:"h-8 px-1 text-red-400",onClick:()=>r(l=>l.filter((y,w)=>w!==i)),children:e.jsx(Te,{className:"w-3.5 h-3.5"})})]},i)),e.jsxs(F,{size:"sm",variant:"outline",onClick:()=>r(s=>[...s,{contractTypeId:0,perContractCents:4e3,label:""}]),children:[e.jsx(Ce,{className:"w-4 h-4 mr-1"})," Vertragstyp hinzufügen"]})]})]})]}),e.jsxs(Be,{children:[e.jsx(F,{variant:"outline",onClick:()=>u(!1),children:"Abbrechen"}),e.jsxs(F,{onClick:N,disabled:b.isPending,className:"bg-orange-500 hover:bg-orange-600 text-white",children:[e.jsx(dt,{className:"w-4 h-4 mr-1"})," ",b.isPending?"Speichert...":"Speichern"]})]})]})})}function Rt({brandId:a,sprint:u,defaultRange:h="sprint"}){const[c,p]=M.useState(u?"sprint":h==="sprint"?"30d":h),[m,n]=M.useState(!1),[j,d]=M.useState(!1),[g,r]=M.use
1State(!1),{from:b,to:N,label:t}=M.useMemo(()=>Pt(c,u),[c,u]),s=C.costs.summary.useQuery({brandId:a,sprintId:u?.id,from:b,to:N},{refetchInterval:6e4}),i=v=>(v/100).toLocaleString("de-DE",{style:"currency",currency:"EUR",maximumFractionDigits:0}),l=s.data,y=!!u,w=l?l.netProfitCents>0?"text-green-400":l.netProfitCents<0?"text-red-400":"text-muted-foreground":"",S=l?l.netProfitCents>=0?ue:ot:null;return e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 flex-wrap gap-2",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:[e.jsx(it,{className:"w-4 h-4 text-orange-400"}),y?"Sprint-Profit":"Studio-Kosten"]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[!y&&e.jsxs("select",{value:c,onChange:v=>p(v.target.value),className:"text-xs rounded-md border border-border bg-background px-2 py-1",children:[e.jsx("option",{value:"7d",children:"7 Tage"}),e.jsx("option",{value:"30d",children:"30 Tage"}),e.jsx("option",{value:"90d",children:"90 Tage"}),e.jsx("option",{value:"year",children:"Dieses Jahr"})]}),e.jsxs(F,{size:"sm",variant:"outline",onClick:()=>d(!0),children:[e.jsx(ct,{className:"w-3.5 h-3.5 mr-1"})," Kosten eintragen"]}),y&&e.jsxs(F,{size:"sm",variant:"outline",onClick:()=>r(!0),children:[e.jsx(Ve,{className:"w-3.5 h-3.5 mr-1"})," Provisions-Modell"]})]})]}),l?e.jsxs(e.Fragment,{children:[y&&l.commission&&l.sprint?.commissionMode&&l.sprint.commissionMode!=="none"&&e.jsxs("div",{className:`rounded-lg border p-4 mb-4 ${l.netProfitCents>=0?"border-green-500/30 bg-green-500/5":"border-red-500/30 bg-red-500/5"}`,children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[e.jsx(q,{label:"Investiert",value:i(l.totalSpendCents),sub:`davon FB Ads ${i(l.fbAdsSpendCents)}`}),e.jsx(q,{label:"Provision verdient",value:i(l.commission.totalCents),sub:l.commissionBasisMode==="net"?`Netto-Stamm ${l.netMemberGrowth>=0?"+":""}${l.netMemberGrowth??0}`+(l.netSignups!=null?` (${l.netSignups} Zugang, ${l.netCancellations} Abgang)`:""):l.commission.currentTier?`Tier: ${l.commission.currentTier.label||`ab ${l.commission.currentTier.minContracts}`}`:"â"}),e.jsx(q,{label:"Reingewinn",value:i(l.netProfitCents),valueClass:w,icon:S?e.jsx(S,{className:`w-5 h-5 ${w}`}):void 0})]}),e.jsxs("div",{className:"border-t border-border/50 mt-3 pt-3 grid grid-cols-1 md:grid-cols-2 gap-3 text-xs",children:[l.cacCents!=null&&e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:"CAC:"})," ",i(l.cacCents)," pro Vertrag",l.marginPerContractCents!=null&&e.jsxs(e.Fragment,{children:[" · ",e.jsxs("span",{className:`font-semibold ${l.marginPerContractCents>=0?"text-green-400":"text-red-400"}`,children:["Marge ",i(l.marginPerContractCents)]})]})]}),l.commission.nextTier&&l.commission.contractsToNextTier!=null&&l.commission.contractsToNextTier>0&&e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:"Nächste Tier:"})," noch ",l.commission.contractsToNextTier," Verträge",l.cacCents!=null&&e.jsxs(e.Fragment,{children:[" · ca. ",i(l.cacCents*l.commission.contractsToNextTier)," Invest nötig"]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-3",children:[e.jsx(q,{label:"Gesamt-Ausgaben",value:i(l.totalSpendCents),sub:t}),e.jsx(q,{label:"Pro Lead",value:l.cplCents!=null?i(l.cplCents):"â",sub:`${l.leads} Leads`}),e.jsx(q,{label:"Pro Vertrag",value:l.cacCents!=null?i(l.cacCents):"â",sub:`${l.contracts} Verträge`}),e.jsx(q,{label:"FB Ads",value:i(l.fbAdsSpendCents),sub:`Studio-Kosten ${i(l.studioCostsCents)}`})]}),e.jsxs("button",{onClick:()=>n(v=>!v),className:"w-full flex items-center gap-2 px-3 py-2 rounded-md hover:bg-muted/30 text-sm",children:[m?e.jsx(Ue,{className:"w-4 h-4"}):e.jsx(xt,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium",children:"Aufschlüsselung nach Lead-Quelle"}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[l.perSource.length," Quellen"]})]}),m&&e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted-foreground uppercase border-b border-border",children:[e.jsx("th",{className:"text-left py-2",children:"Quelle"}),e.jsx("th",{className:"text-right py-2",children:"Kosten"}),e.jsx("th",{className:"text-right py-2",children:"Leads"}),e.jsx("th",{className:"text-right py-2",children:"Verträge"}),e.jsx("th",{className:"text-right py-2",children:"CPL"}),e.jsx("th",{className:"text-right py-2",children:"CAC"})]})}),e.jsx("tbody",{children:l.perSource.map(v=>e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("td",{className:"py-2",children:v.label}),e.jsx("td",{className:"py-2 text-right font-semibold",children:i(v.costsCents)}),e.jsx("td",{className:"py-2 text-right",children:v.leads}),e.jsx("td",{className:"py-2 text-right",children:v.contracts}),e.jsx("td",{className:"py-2 text-right",children:v.cpl!=null?i(v.cpl):"â"}),e.jsx("td",{className:"py-2 text-right",children:v.cac!=null?i(v.cac):"â"})]},v.source))})]})}),y&&(!l.sprint?.commissionMode||l.sprint.commissionMode==="none")&&e.jsxs("div",{className:"mt-3 p-3 rounded-md bg-orange-500/10 text-xs text-orange-400 flex items-center gap-2",children:[e.jsx(Ve,{className:"w-3.5 h-3.5"}),"Provisions-Modell ist nicht konfiguriert â Reingewinn wird nicht berechnet.",e.jsx(F,{size:"sm",variant:"ghost",className:"ml-auto h-6 text-orange-400",onClick:()=>r(!0),children:"Jetzt einrichten"})]})]}):e.jsx("div",{className:"text-sm text-muted-foreground py-6 text-center",children:s.isLoading?"Lade...":"Keine Daten"}
1),e.jsx(Ft,{open:j,onOpenChange:d,brandId:a,sprintId:u?.id,defaultStartDate:u?new Date(Number(u.startsAt)).toISOString().slice(0,10):void 0,defaultEndDate:u?new Date(Number(u.endsAt)).toISOString().slice(0,10):void 0}),u&&e.jsx(Et,{open:g,onOpenChange:r,sprint:u})]})}function q({label:a,value:u,sub:h,valueClass:c,icon:p}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:a}),e.jsxs("div",{className:`text-2xl font-bold mt-0.5 flex items-center gap-2 ${c??"text-foreground"}`,children:[p,u]}),h&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:h})]})}function Pt(a,u){const h=Date.now();if(a==="sprint"&&u)return{from:Number(u.startsAt),to:Number(u.endsAt),label:"Sprint-Zeitraum"};if(a==="year"){const p=new Date;return p.setMonth(0,1),p.setHours(0,0,0,0),{from:p.getTime(),to:h,label:"Dieses Jahr"}}const c=a==="7d"?7:a==="30d"?30:90;return{from:h-c*864e5,to:h,label:`Letzte ${c} Tage`}}function X(a){return a==null||isNaN(a)?"â":`${a.toFixed(1)}%`}function we(a){return a?new Date(a).toLocaleString("de-DE",{day:"2-digit",month:"2-digit",year:"2-digit",hour:"2-digit",minute:"2-digit"}):"â"}function xe({label:a,value:u,sub:h,icon:c,tone:p="default"}){const m={default:"bg-muted/40 border-border text-foreground",blue:"bg-blue-500/10 border-blue-500/20 text-blue-400",green:"bg-emerald-500/10 border-emerald-500/20 text-emerald-400",purple:"bg-purple-500/10 border-purple-500/20 text-purple-400",amber:"bg-amber-500/10 border-amber-500/20 text-amber-400"};return e.jsxs("div",{className:`rounded-xl border p-4 ${m[p]}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider opacity-70",children:a}),e.jsx(c,{className:"h-4 w-4 opacity-80"})]}),e.jsx("p",{className:"text-2xl font-bold leading-tight",children:u}),h&&e.jsx("p",{className:"text-xs opacity-70 mt-0.5",children:h})]})}function Y({rate:a}){const u=a>=50?"text-emerald-400":a>=30?"text-amber-400":a>=15?"text-orange-400":"text-rose-400";return e.jsx("span",{className:`font-semibold ${u}`,children:X(a)})}function zt({brandId:a,dateFrom:u,dateTo:h}){const c=M.useMemo(()=>({brandId:a,dateFrom:u,dateTo:h}),[a,u,h]),{data:p}=C.messagingAnalytics.summary.useQuery(c,{staleTime:3e4}),{data:m=[]}=C.messagingAnalytics.transactional.useQuery(c,{staleTime:3e4}),{data:n=[]}=C.messagingAnalytics.emailFlows.useQuery(c,{staleTime:3e4}),{data:j=[]}=C.messagingAnalytics.newsletters.useQuery(c,{staleTime:3e4}),{data:d=[]}=C.messagingAnalytics.whatsappTemplates.useQuery(c,{staleTime:3e4}),{data:g=[]}=C.messagingAnalytics.whatsappFlows.useQuery(c,{staleTime:3e4}),r=p?.emails,b=p?.whatsapp,N=p?.flows;return e.jsxs(V,{className:"bg-card border-border",children:[e.jsx(B,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(Q,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Ze,{className:"h-4 w-4 text-primary"}),"Messaging-Analytics",a==null&&e.jsx(re,{variant:"outline",className:"text-[10px] ml-1",children:"markenübergreifend"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"E-Mail-Flows · Templates · WhatsApp · Transaktional"})]})}),e.jsxs(I,{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(xe,{label:"Mails gesendet",value:r?.sent??0,sub:`${r?.opened??0} geöffnet · ${r?.clicked??0} geklickt`,icon:He,tone:"blue"}),e.jsx(xe,{label:"E-Mail Ãffnungsrate",value:X(r?.openRate??0),sub:`Klickrate ${X(r?.clickRate??0)}`,icon:mt,tone:"green"}),e.jsx(xe,{label:"WhatsApp gesendet",value:b?.outbound??0,sub:`${b?.delivered??0} zugestellt · ${b?.read??0} gelesen`,icon:ut,tone:"purple"}),e.jsx(xe,{label:"WhatsApp Antwortrate",value:X(b?.replyRate??0),sub:`${b?.inbound??0} eingehend`,icon:ht,tone:"amber"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-muted/20 p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Aktive Flow-Enrollments"}),e.jsx("p",{className:"text-lg font-bold text-foreground",children:N?.activeEnrollments??
10})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-muted/20 p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Flow-Mails gesendet"}),e.jsx("p",{className:"text-lg font-bold text-foreground",children:N?.sent??0})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-muted/20 p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Flow-Ãffnungsrate"}),e.jsx("p",{className:"text-lg font-bold text-foreground",children:X(N?.openRate??0)})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-muted/20 p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"WA-Zustellrate"}),e.jsx("p",{className:"text-lg font-bold text-foreground",children:X(b?.deliveryRate??0)})]})]}),e.jsxs(Mt,{defaultValue:"transactional",className:"w-full",children:[e.jsxs(Lt,{className:"flex flex-wrap h-auto",children:[e.jsx(ae,{value:"transactional",children:"Transaktional"}),e.jsx(ae,{value:"email_flows",children:"E-Mail Flows"}),e.jsx(ae,{value:"newsletters",children:"Newsletter"}),e.jsx(ae,{value:"wa_templates",children:"WA Templates"}),e.jsx(ae,{value:"wa_flows",children:"WA Flows"})]}),e.jsxs(ne,{value:"transactional",className:"mt-3",children:[m.length===0?e.jsx(le,{text:"Keine transaktionalen Mails im Zeitraum."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left font-medium py-2",children:"Mailtyp"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Gesendet"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Geöffnet"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Open-Rate"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Geklickt"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Click-Rate"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Letzte"})]})}),e.jsx("tbody",{children:m.map(t=>e.jsxs("tr",{className:"border-b border-border/40 hover:bg-muted/20",children:[e.jsx("td",{className:"py-2.5 font-medium text-foreground",children:t.label}),e.jsx("td",{className:"py-2.5 text-right",children:t.sent}),e.jsx("td",{className:"py-2.5 text-right",children:t.opened}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(Y,{rate:t.openRate})}),e.jsx("td",{className:"py-2.5 text-right",children:t.clicked}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(Y,{rate:t.clickRate})}),e.jsx("td",{className:"py-2.5 text-right text-xs text-muted-foreground",children:we(t.lastSent)})]},t.emailType))})]})}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-2",children:"Open-Tracking via 1Ã1-Pixel (kann durch Mail-Clients wie Apple Mail künstlich erhöht oder durch Image-Blocker reduziert werden)."})]}),e.jsx(ne,{value:"email_flows",className:"mt-3",children:n.length===0?e.jsx(le,{text:"Keine E-Mail-Flows konfiguriert oder keine Sends im Zeitraum."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left font-medium py-2",children:"Flow"}),e.jsx("th",{className:"text-left font-medium py-2",children:"Trigger"}),a==null&&e.jsx("th",{className:"text-left font-medium py-2",children:"Marke"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Aktive"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Gesendet"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Geöffnet"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Open-Rate"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Click-Rate"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Status"})]})}),e.jsx("tbody",{children:n.map(t=>e.jsxs("tr",{className:"border-b border-border/40 hover:bg-muted/20",children:[e.jsx("td",{className:"py-2.5 font-medium text-foreground",children:t.name}),e.jsx("td",{className:"py-2.5 text-xs text-muted-foreground",children:t.triggerType}),a==null&&e.jsx("td",{className:"py-2.5 text-xs",children:t.brandName}),e.jsx("td",{className:"py-2.5 text-right",children:t.activeEnrollments}),e.jsx("td",{className:"py-2.5 text-right",children:t.sent}),e.jsx("td",{className:"py-2.5 text-right",children:t.opened}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(Y,{rate:t.openRate})}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(Y,{rate:t.clickRate})}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(re,{variant:t.isActive?"default":"outline",className:"text-[10px]",children:t.isActive?"aktiv":"pausiert"})})]},t.id))})]})})}),e.jsx(ne,{value:"newsletters",className:"mt-3",children:j.length===0?e.jsx(le,{text:"Keine Newsletter-Sends im Zeitraum."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left font-medium py-2",children:"Newsletter / Kampagne"}),a==null&&e.jsx("th",{className:"text-left font-medium py-2",children:"Marke"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Empfänger"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Gesendet"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Geöffnet"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Open-Rate"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Geklickt"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Versendet"})]})}),e.jsx("tbody",{children:j.map(t=>e.jsxs("tr",{className:"border-b border-border/40 hover:bg-muted/20",children:[e.jsxs("td",{className:"py-2.5",children:[e.jsx("div",{className:"font-medium text-foreground line-clamp-1",children:t.name}),t.subject&&t.subject!==t.name&&e.jsx("div",{className:"text-xs text-muted-foreground line-clamp-1",children:t.subject}),e.jsx(re,{variant:"outline",className:"text-[10px] mt-0.5",children:t.kind==="newsletter"?"Newsletter":t.kind==="nl_campaign"?"Multi-Brand":"Broadcast"})]}),a==null&&e.jsx("td",{className:"py-2.5 text-xs",children:t.brandName}),e.jsx("td",{className:"py-2.5 text-right",children:t.recipients}),e.jsx("td",{className:"py-2.5 text-right",children:t.sent}),e.jsx("td",{className:"py-2.5 text-right",children:t.opened}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(Y,{rate:t.openRate})}),e.jsx("td",{className:"py-2.5 text-right",children:t.clicked}),e.jsx("td",{className:"py-2.5 text-right text-xs text-muted-foreground",children:we(t.sentAt)})]},t.id))})]})})}),e.jsx(ne,{value:"wa_templates",className:"mt-3",children:d.length===0?e.jsx(le,{text:"Keine WhatsApp-Template-Sends im Zeitraum."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left font-medium py-2",children:"Template"}),a==null&&e.jsx("th",{className:"text-left font-medium py-2",children:"Marke"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Gesendet"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Zugestellt"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Gelesen"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Read-Rate"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Fehler"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Status"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Letzte"})]})}),e.jsx("tbody",{children:d.map(t=>e.jsxs("tr",{className:"border-b border-border/40 hover:bg-muted/20",children:[e.jsxs("td",{className:"py-2.5",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.templateName}),e.jsx("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide",children:t.category})]}),a==null&&e.jsx("td",{className:"py-2.5 text-xs",children:t.brandName}),e.jsx("td",{className:"py-2.5 text-right",children:t.sent}),e.jsx("td",{className:"py-2.5 text-right",children:t.delivered}),e.jsx("td",{className:"py-2.5 text-right",children:t.read}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(Y,{rate:t.readRate})}),e.jsx("td",{className:`py-2.5 text-right ${t.failed>0?"text-rose-400 font-semibold":""}`,children:t.failed}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(re,{variant:t.status==="approved"?"default":"outline",className:"text-[10px]",children:t.status})}),e.jsx("td",{className:"py-2.5 text-right text-xs text-muted-foreground",children:we(t.lastSent)}
1)]},`${t.brandId}-${t.templateName}`))})]})})}),e.jsx(ne,{value:"wa_flows",className:"mt-3",children:g.length===0?e.jsx(le,{text:"Keine WhatsApp-Flows konfiguriert oder keine Jobs im Zeitraum."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left font-medium py-2",children:"Flow"}),e.jsx("th",{className:"text-left font-medium py-2",children:"Trigger"}),a==null&&e.jsx("th",{className:"text-left font-medium py-2",children:"Marke"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Steps"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Versendet"}),e.jsx("th",{className:"text-right font-medium py-2",title:"Distinct Empfaenger im Zeitraum",children:"Empfänger"}),e.jsx("th",{className:"text-right font-medium py-2",title:"Empfaenger die geantwortet haben",children:"Antworten"}),e.jsx("th",{className:"text-right font-medium py-2",title:"Reply-Rate (Antworten / Empfaenger)",children:"Reply"}),e.jsx("th",{className:"text-right font-medium py-2",title:"Empfaenger mit Status appointment/closed",children:"Termine"}),e.jsx("th",{className:"text-right font-medium py-2",title:"Empfaenger mit Status closed (Vertrag)",children:"Verträge"}),e.jsx("th",{className:"text-right font-medium py-2",title:"Conversion-Rate Vertrag / Empfaenger",children:"CR"}),e.jsx("th",{className:"text-right font-medium py-2",children:"Status"})]})}),e.jsx("tbody",{children:g.map(t=>e.jsxs("tr",{className:"border-b border-border/40 hover:bg-muted/20",children:[e.jsx("td",{className:"py-2.5 font-medium text-foreground",children:t.name}),e.jsx("td",{className:"py-2.5 text-xs text-muted-foreground",children:t.triggerType}),a==null&&e.jsx("td",{className:"py-2.5 text-xs",children:t.brandName}),e.jsx("td",{className:"py-2.5 text-right",children:t.stepCount}),e.jsx("td",{className:"py-2.5 text-right",children:t.sent}),e.jsx("td",{className:"py-2.5 text-right text-blue-400",children:t.recipients??0}),e.jsx("td",{className:"py-2.5 text-right text-amber-400",children:t.responded??0}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(Y,{rate:t.responseRate??0})}),e.jsx("td",{className:"py-2.5 text-right text-purple-400",children:t.appointments??0}),e.jsx("td",{className:"py-2.5 text-right text-emerald-400",children:t.contracts??0}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(Y,{rate:t.contractRate??0})}),e.jsx("td",{className:"py-2.5 text-right",children:e.jsx(re,{variant:t.active?"default":"outline",className:"text-[10px]",children:t.active?"aktiv":"pausiert"})})]},t.id))})]})})})]})]})]})}function le({text:a}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Ye,{className:"h-6 w-6 text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a})]})}const U={hot:{label:"Hot",color:"#ef4444",emoji:"ð¥",desc:"Open/Click â¤7 Tage"},warm:{label:"Warm",color:"#f97316",emoji:"âï¸",desc:"Open/Click â¤30 Tage"},lukewarm:{label:"Lukewarm",color:"#eab308",emoji:"ð¥ï¸",desc:"Open/Click â¤90 Tage"},cold:{label:"Cold",color:"#3b82f6",emoji:"âï¸",desc:"90+ Tage ohne Engagement"},dormant:{label:"Dormant",color:"#6b7280",emoji:"ð",desc:"180+ Tage ohne Engagement"},new:{label:"New",color:"#a1a1aa",emoji:"ð",desc:"Noch keine Mail bekommen"}},Ie=["hot","warm","lukewarm","new","cold","dormant"];function Vt({brandId:a}){const{data:u,isLoading:h}=C.leads.engagementTierBreakdown.useQuery({brandId:a}),{data:c}=C.leads.engagementTierTimeline.useQuery({brandId:a,weeks:12}),p=u?.tiers??{hot:0,warm:0,lukewarm:0,cold:0,dormant:0,new:0},m=u?.total??0,n=Ie.map(r=>({tier:r,name:U[r].label,value:p[r]??0,color:U[r].color})).filter(r=>r.value>0),j=(p.hot??0)+(p.warm??0)+(p.lukewarm??0)+(p.new??0),d=m>0?Math.round(j/m*100):0,g=(c?.points??[]).map(r=>({date:new Date(r.snapshotAt).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit"}),hot:r.hot,warm:r.warm,lukewarm:r.lukewarm,cold:r.cold,dormant:r.dormant,new:r.new}));return e.jsxs(V,{className:"bg-card border-border",children:[e.jsx(B,{className:"pb-2",children:e.jsxs(Q,{className:"text-base flex items-center gap-2",children:[e.jsx(pt,{className:"w-4 h-4 text-orange-400"}),"Engagement-Tier-Verteilung",e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-auto",children:[m," Leads"]})]})}),e.jsx(I,{className:"space-y-4",children:h?e.jsx("div",{className:"h-48 bg-muted/30 rounded animate-pulse"}):m===0?e.jsx("div",{className:"text-sm text-muted-foreground text-center py-8",children:"Noch keine Tier-Daten"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx("div",{className:"h-48",children:e.jsx(he,{width:"100%",height:"100%",children:e.jsxs(gt,{children:[e.jsx(bt,{data:n,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",innerRadius:45,outerRadius:75,paddingAngle:2,children:n.map((r,b)=>
1e.jsx(jt,{fill:r.color},b))}),e.jsx(pe,{contentStyle:{background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:6,fontSize:12},formatter:(r,b,N)=>[`${r} Leads (${m>0?Math.round(r/m*100):0}%)`,N.payload.name]})]})})}),e.jsxs("div",{className:"space-y-1.5 text-xs",children:[Ie.map(r=>{const b=U[r],N=p[r]??0,t=m>0?Math.round(N/m*100):0;return e.jsxs("div",{className:"flex items-center justify-between gap-2 py-0.5",title:b.desc,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm shrink-0",style:{background:b.color}}),e.jsxs("span",{className:"text-foreground/90",children:[b.emoji," ",b.label]})]}),e.jsxs("div",{className:"text-muted-foreground tabular-nums",children:[e.jsx("span",{className:"font-medium text-foreground",children:N}),e.jsxs("span",{className:"ml-1.5 opacity-60",children:["(",t,"%)"]})]})]},r)}),e.jsxs("div",{className:"pt-2 mt-2 border-t border-border/40 text-[11px] text-muted-foreground",children:[e.jsx("strong",{className:"text-green-400",children:j})," aktiv erreichbar (",d,"%) · ",e.jsx("strong",{className:"text-muted-foreground",children:(p.cold??0)+(p.dormant??0)})," Frequenz-gedrosselt"]})]})]}),g.length>1&&e.jsxs("div",{className:"pt-4 border-t border-border/40",children:[e.jsxs("div",{className:"text-xs text-muted-foreground mb-2 flex items-center gap-2",children:[e.jsx("span",{children:"Verlauf der Tier-Verteilung"}),e.jsx("span",{className:"opacity-50",children:"·"}),e.jsxs("span",{children:[g.length," Snapshots"]})]}),e.jsx("div",{className:"h-44",children:e.jsx(he,{width:"100%",height:"100%",children:e.jsxs(ft,{data:g,margin:{top:5,right:5,bottom:5,left:-10},children:[e.jsx(Le,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",opacity:.4}),e.jsx($e,{dataKey:"date",stroke:"hsl(var(--muted-foreground))",fontSize:10}),e.jsx(Fe,{stroke:"hsl(var(--muted-foreground))",fontSize:10}),e.jsx(pe,{contentStyle:{background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:6,fontSize:12}}),e.jsx(Ae,{wrapperStyle:{fontSize:11},iconSize:10}),e.jsx(J,{type:"monotone",dataKey:"hot",stroke:U.hot.color,dot:!1,strokeWidth:2}),e.jsx(J,{type:"monotone",dataKey:"warm",stroke:U.warm.color,dot:!1,strokeWidth:2}),e.jsx(J,{type:"monotone",dataKey:"lukewarm",stroke:U.lukewarm.color,dot:!1,strokeWidth:2}),e.jsx(J,{type:"monotone",dataKey:"cold",stroke:U.cold.color,dot:!1,strokeWidth:2}),e.jsx(J,{type:"monotone",dataKey:"dormant",stroke:U.dormant.color,dot:!1,strokeWidth:2}),e.jsx(J,{type:"monotone",dataKey:"new",stroke:U.new.color,dot:!1,strokeWidth:2})]})})})]}),g.length<=1&&e.jsx("div",{className:"pt-4 border-t border-border/40 text-[11px] text-muted-foreground italic",children:'Verlaufs-Graph braucht â¥2 tägliche Snapshots â kommt automatisch nach den ersten Recompute-Läufen (3 Uhr nachts) oder via System-Health â "Engagement-Tier neu berechnen".'})]})})]})}function Z({label:a,value:u,color:h,bg:c}){return e.jsxs("div",{className:`relative overflow-hidden rounded-lg p-4 border ${c}`,children:[e.jsx("div",{className:`text-3xl font-bold ${h}`,children:typeof u=="number"?u.toLocaleString("de-DE"):u}),e.jsx("div",{className:"text-xs text-muted-foreground mt-2",children:a})]})}function It({dateFrom:a,dateTo:u}){const h=Math.max(7,Math.min(365,Math.round((u-a)/864e5))),{data:c,isLoading:p}=C.analytics.channelConversionsByBrand.useQuery({dateFrom:a,dateTo:u,lookbackDays:h},{staleTime:5*6e4,refetchOnWindowFocus:!1,retry:1}),m=c?.brands??[],n=d=>(d/100).toLocaleString("de-DE",{style:"currency",currency:"EUR",maximumFractionDigits:0}),j=d=>d==null?"text-muted-foreground":d>=15?"text-emerald-600 dark:text-emerald-400 font-semibold":d>=5?"text-yellow-600 dark:text-yellow-400":"text-red-600 dark:text-red-400";return e.jsxs(V,{className:"bg-card border-border",children:[e.jsxs(B,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(Q,{className:"text-base flex items-center gap-2",children:[e.jsx(Re,{className:"w-4 h-4 text-primary"}),"Kanal-Conversion pro Studio"]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["Touch-Fenster folgt Hauptfilter (",h,"d)"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["'Personen' = distincte Leads die im Touch-Fenster ueber diesen Kanal kontaktiert wurden (egal wie oft). 'Termin' = davon einen Termin gebucht (mit Termin-Quote in Klammern). 'Vertrag' = davon Vertrag gemacht. Quote = Vertrag / Personen. Ein Lead darf in mehreren Kanaelen zaehlen â diese Kanal-Spalten addieren sich daher NICHT. Die Gruppe ",e.jsx("span",{className:"text-foreground font-medium",children:"ð¯ Eindeutig (Last-Touch)"})," ordnet jeden Vertrag genau EINEM Kanal zu (der letzte Touch vor Absc
1hluss) bzw. 'Direkt' ohne Touch â DIESE Zahlen summieren sich sauber zur Gesamt-Vertragszahl."]})]}),e.jsx(I,{children:p?e.jsx("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"Lade Studio-Datenâ¦"}):m.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"Keine aktiven Studios mit Kanal-Daten."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsxs("thead",{children:[e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-left px-3 py-2 font-medium",children:"Studio"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium",rowSpan:2,title:"Alle Leads die im Zeitraum bei dieser Brand neu angelegt wurden (createdAt im Filter)",children:"Leads gesamt"}),e.jsx("th",{className:"text-center px-3 py-2 font-medium",colSpan:4,children:"ð Telefon"}),e.jsx("th",{className:"text-center px-3 py-2 font-medium",colSpan:4,children:"ð¬ WhatsApp"}),e.jsx("th",{className:"text-center px-3 py-2 font-medium",colSpan:4,children:"ð§ Newsletter"}),e.jsx("th",{className:"text-center px-3 py-2 font-medium border-l border-border",colSpan:5,title:"Eindeutige Zuordnung: jeder Vertrag genau 1 Kanal (letzter Touch vor Abschluss) â Summe = Gesamt-Verträge",children:"ð¯ Eindeutig (Last-Touch)"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"Σ Provision"})]}),e.jsxs("tr",{className:"border-b border-border text-[10px] text-muted-foreground uppercase tracking-wide",children:[e.jsx("th",{}),e.jsx("th",{className:"text-right px-2 py-1",children:"Personen"}),e.jsx("th",{className:"text-right px-2 py-1",title:"Distincte Leads die einen Termin gebucht haben und vorher in diesem Kanal beruehrt wurden",children:"Termin"}),e.jsx("th",{className:"text-right px-2 py-1",children:"Vertrag"}),e.jsx("th",{className:"text-right px-2 py-1",children:"Quote"}),e.jsx("th",{className:"text-right px-2 py-1",children:"Personen"}),e.jsx("th",{className:"text-right px-2 py-1",title:"Distincte Leads die einen Termin gebucht haben und vorher in diesem Kanal beruehrt wurden",children:"Termin"}),e.jsx("th",{className:"text-right px-2 py-1",children:"Vertrag"}),e.jsx("th",{className:"text-right px-2 py-1",children:"Quote"}),e.jsx("th",{className:"text-right px-2 py-1",children:"Personen"}),e.jsx("th",{className:"text-right px-2 py-1",title:"Distincte Leads die einen Termin gebucht haben und vorher in diesem Kanal beruehrt wurden",children:"Termin"}),e.jsx("th",{className:"text-right px-2 py-1",children:"Vertrag"}),e.jsx("th",{className:"text-right px-2 py-1",children:"Quote"}),e.jsx("th",{className:"text-right px-2 py-1 border-l border-border text-blue-500",title:"Verträge mit Telefon als letztem Touch",children:"Tel"}),e.jsx("th",{className:"text-right px-2 py-1 text-emerald-500",title:"Verträge mit WhatsApp als letztem Touch",children:"WA"}),e.jsx("th",{className:"text-right px-2 py-1 text-purple-500",title:"Verträge mit Newsletter als letztem Touch",children:"NL"}),e.jsx("th",{className:"text-right px-2 py-1 text-amber-500",title:"Verträge ohne getrackten Touch (Walk-in / Studio-Abschluss)",children:"Direkt"}),e.jsx("th",{className:"text-right px-2 py-1 text-foreground",title:"Gesamt-Verträge im Zeitraum",children:"Σ"}),e.jsx("th",{})]})]}),e.jsx("tbody",{children:m.map(d=>{const g=(d.phone?.commissionCents??0)+(d.whatsapp?.commissionCents??0)+(d.newsletter?.commissionCents??0),r=(b,N)=>{const t=b??null,s=N??0;return s===0?e.jsx("span",{className:"text-muted-foreground",children:"0"}):e.jsxs("span",{title:`Termin-Quote: ${t}%`,children:[s,t!=null&&e.jsxs("span",{className:"text-[10px] text-muted-foreground ml-1",children:["(",t,"%)"]})]})};return e.jsxs("tr",{className:"border-b border-border/40 hover:bg-muted/20 transition-colors",children:[e.jsx("td",{className:"px-3 py-2 font-medium text-foreground",children:d.brandName}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums font-semibold text-foreground",children:d.totalLeads??0}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums text-blue-600 dar
1k:text-blue-400",children:d.phone?.touched??0}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums text-violet-600 dark:text-violet-400",children:r(d.phone?.apptRate,d.phone?.apptConverted)}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums",children:d.phone?.converted??0}),e.jsx("td",{className:`px-2 py-2 text-right tabular-nums ${j(d.phone?.conversionRate??null)}`,children:d.phone?.conversionRate==null?"â":`${d.phone.conversionRate}%`}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums text-emerald-600 dark:text-emerald-400",children:d.whatsapp?.touched??0}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums text-violet-600 dark:text-violet-400",children:r(d.whatsapp?.apptRate,d.whatsapp?.apptConverted)}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums",children:d.whatsapp?.converted??0}),e.jsx("td",{className:`px-2 py-2 text-right tabular-nums ${j(d.whatsapp?.conversionRate??null)}`,children:d.whatsapp?.conversionRate==null?"â":`${d.whatsapp.conversionRate}%`}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums text-purple-600 dark:text-purple-400",children:d.newsletter?.touched??0}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums text-violet-600 dark:text-violet-400",children:r(d.newsletter?.apptRate,d.newsletter?.apptConverted)}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums",children:d.newsletter?.converted??0}),e.jsx("td",{className:`px-2 py-2 text-right tabular-nums ${j(d.newsletter?.conversionRate??null)}`,children:d.newsletter?.conversionRate==null?"â":`${d.newsletter.conversionRate}%`}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums border-l border-border text-blue-600 dark:text-blue-400",children:d.lastTouch?.phone??0}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums text-emerald-600 dark:text-emerald-400",children:d.lastTouch?.whatsapp??0}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums text-purple-600 dark:text-purple-400",children:d.lastTouch?.newsletter??0}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums text-amber-600 dark:text-amber-400",children:d.lastTouch?.direct??0}),e.jsx("td",{className:"px-2 py-2 text-right tabular-nums font-bold text-foreground",children:d.lastTouch?.total??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-pink-600 dark:text-pink-400 font-semibold",children:n(g)})]},d.brandId)})})]})})})]})}function Ot({brandId:a,dateFrom:u,dateTo:h}){const{data:c,isLoading:p}=C.analytics.referralKpis.useQuery({brandId:a,dateFrom:u,dateTo:h,qrThreshold:5},{staleTime:3e5,refetchOnWindowFocus:!1,retry:1}),m=c?.friendsInvited??0,n=c?.contractsWithRef??0,j=c?.qrPowerReferrers??0,d=c?.qrThreshold??5;c?.flyerLeadsTotal,c?.topFlyerCampaign;const g=({icon:r,value:b,label:N,color:t,bg:s,sub:i})=>{const l=r;return e.jsxs("div",{className:`rounded-lg border p-3 flex items-center gap-3 ${s}`,children:[e.jsx(l,{className:`w-5 h-5 shrink-0 ${t}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:`text-xl font-black leading-none ${t}`,children:p?"â¦":b}),e.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5 truncate",children:N}),i&&e.jsx("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:i})]})]})};return e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:[e.jsx(g,{icon:De,value:m,label:"Freunde an Terminen",color:"text-sky-500 dark:text-sky-400",bg:"bg-sky-500/5 border-sky-500/20",sub:"vom Lead oder Mitarbeiter mit-eingetragen"}),e.jsx(g,{icon:Re,value:n,label:"Verträge mit Ref-Code",color:"text-purple-500 dark:text-purple-400",bg:"bg-purple-500/5 border-purple-500/20",sub:"aus Empfehlungs-Mitgliedern"}),e.jsx(g,{icon:Dt,value:j,label:`QR-Power-Werber (â¥${d})`,color:"text-amber-500 dark:text-amber-400",bg:"bg-amber-500/5 border-amber-500/20",sub:`Mitglieder mit ${d}+ erfolgreichen Empfehlungen`})]})}function Kt({brandId:a,dateFrom:u,dateTo:h,rangeLabel:c}){const p=Math.max(7,Math.min(365,Math.round((h-u)/864e5))),{data:m,isLoading:n}=C.analytics.channelConversions.useQuery({brandId:a,dateFrom:u,dateTo:h,lookbackDays:p},{staleTime:5*6e4,refetchOnWindowFocus:!1,retry:1}),j={phone:{label:"Telefon",icon:St,color:"text-blue-400",bg:"bg-blue-500/10 border-blue-500/20",accent:"text-blue-300"},whatsapp:{label:"WhatsApp",icon:Tt,color:"text-emerald-400",bg:"bg-emerald-500/10 border-emerald-500/20",accent:"text-emerald-300"},newsletter:{label:"Newsletter",icon:He,color:"text-purple-400",bg:"bg-purple-500/10 border-purple-500/20",accent:"text-purple-300"}},d=t=>
1(t/100).toLocaleString("de-DE",{style:"currency",currency:"EUR",maximumFractionDigits:0}),g=t=>t.toLocaleString("de-DE",{style:"currency",currency:"EUR",maximumFractionDigits:0}),r=m?.channels??[],b=m?.prevChannels??[],N=t=>{const s=r.find(w=>w.channel===t)?.converted??0,i=b.find(w=>w.channel===t)?.converted??0;if(s===0&&i===0)return null;const l=s-i,y=i>0?Math.round(l/i*100):s>0?100:0;return{abs:l,pct:y}};return e.jsxs(V,{className:"bg-card border-border",children:[e.jsxs(B,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(Q,{className:"text-base flex items-center gap-2",children:[e.jsx(Je,{className:"w-4 h-4 text-pink-400"}),"Provision & Kanal-Conversion (",c,")"]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["Touch-Fenster folgt Hauptfilter (",p,"d)"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Multi-Touch: ein Lead zaehlt in jedem Kanal mit dem er beruehrt wurde. Vertraege werden attributiert wenn der Touch in den ",p," Tagen VOR Vertrag-Abschluss lag. Kanal-Spalten addieren sich NICHT zur Gesamt-Vertragszahl."]})]}),e.jsxs(I,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3",children:[e.jsx(de,{brandId:a,metric:"commission",label:"Meine Provision im Monat",color:"text-pink-400",bg:"bg-pink-500/10 border-pink-500/20",accentRgb:"#f472b6",format:g}),n?[0,1,2].map(t=>e.jsx("div",{className:"rounded-xl border p-4 bg-muted/10 border-border",children:e.jsx("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"Ladeâ¦"})},t)):r.map(t=>{const s=j[t.channel];if(!s)return null;const i=s.icon,l=t.conversionRate==null?"text-muted-foreground":t.conversionRate>=15?"text-green-400":t.conversionRate>=5?"text-yellow-400":"text-red-400",y=N(t.channel),w=b.find(S=>S.channel===t.channel)?.converted??0;return e.jsxs("div",{className:`rounded-xl border p-4 ${s.bg}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(i,{className:`w-4 h-4 ${s.color}`}),e.jsx("span",{className:`text-sm font-semibold ${s.color}`,children:s.label}),y&&y.abs!==0&&e.jsxs("span",{className:`ml-auto flex items-center gap-0.5 text-[11px] font-semibold px-1.5 py-0.5 rounded-full ${y.abs>0?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,title:`Vergleichs-Zeitraum: ${w} Vertraege durch ${s.label}`,children:[y.abs>0?e.jsx(ye,{className:"w-3 h-3"}):e.jsx(ve,{className:"w-3 h-3"}),y.abs>0?"+":"",y.pct,"%"]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-2 text-center",children:[e.jsxs("div",{children:[e.jsx("div",{className:`text-xl font-black ${s.color}`,title:"Distincte Leads die im Lookback ueber diesen Kanal kontaktiert wurden â egal wie oft.",children:t.touched}),e.jsx("div",{className:"text-[10px] text-muted-foreground mt-0.5 uppercase tracking-wide",children:"Personen"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl font-black text-violet-500 dark:text-violet-400",title:`Distincte Leads die einen Termin gebucht haben und vorher in diesem Kanal beruehrt wurden${t.apptRate!=null?` â ${t.apptRate}%`:""}`,children:t.apptConverted??0}),e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-0.5 uppercase tracking-wide",children:["Termin ",t.apptRate!=null&&e.jsxs("span",{className:"text-violet-500/70",children:["(",t.apptRate,"%)"]})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl font-black text-foreground",children:t.converted}),e.jsx("div",{className:"text-[10px] text-muted-foreground mt-0.5 uppercase tracking-wide",children:"Vertrag"})]}),e.jsxs("div",{children:[e.jsx("div",{className:`text-xl font-black ${l}`,children:t.conversionRate==null?"â":`${t.conversionRate}%`}),e.jsx("div",{className:"text-[10px] text-muted-foreground mt-0.5 uppercase tracking-wide",children:"Quote"})]})]}),e.jsxs("div",{className:"mt-3 pt-3 border-t border-border/50 flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Provision"}),e.jsx("span",{className:`font-semibold ${s.accent}`,children:d(t.commissionCents)})]})]},t.channel)})]}),!n&&m?.lastTouch&&(()=>{const t=m.lastTouch,s=[{key:"phone",label:"Telefon",val:t.phone,color:"text-blue-400"},{key:"whatsapp",label:"WhatsApp",val:t.whatsapp,color:"text-emerald-400"},{key:"newsletter",label:"Newsletter",val:t.newsletter,color:"text-purple-400"},{key:"direct",label:"Direkt (ohne Touch)",val:t.direct,color:"text-amber-400"}];return e.jsxs("div",{className:"mt-4 pt-3 border-t border-border/60",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-1 mb-2",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground",children:"Eindeutige Zuordnung (Last-Touch)"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["Jeder Vertrag genau 1 Kanal â Summe = ",t.total," Verträge"]})]}
1),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-5 gap-2",children:[s.map(i=>e.jsxs("div",{className:"rounded-lg border border-border bg-muted/10 px-2 py-1.5 text-center",children:[e.jsx("div",{className:`text-lg font-black ${i.color}`,children:i.val}),e.jsx("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide leading-tight",children:i.label})]},i.key)),e.jsxs("div",{className:"rounded-lg border border-border bg-foreground/5 px-2 py-1.5 text-center",children:[e.jsx("div",{className:"text-lg font-black text-foreground",children:t.total}),e.jsx("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide leading-tight",children:"Gesamt"})]})]})]})})()]})]})}function de({brandId:a,metric:u,label:h,color:c,bg:p,accentRgb:m,format:n}){const{data:j,isLoading:d}=C.analytics.monthlyMetricTrend.useQuery({brandId:a,metric:u},{staleTime:12e4,refetchOnWindowFocus:!1,retry:1}),g=j?.series??[],r=j?.current??0,b=j?.forecast??0,N=j?.prevSame??0,t=r-N,s=N>0?Math.round(t/N*100):r>0?100:0,i=j?.dayOfMonth??0,l=j?.daysInMonth??0,y=j?.denominator,w=u==="shows"&&y!=null&&y>0?Math.round(r/y*1e3)/10:null,S=300,v=64,P=4,D=v-P*2,E=Math.max(b,r,1),R=o=>g.length>1?o/(g.length-1)*S:0,x=o=>P+D-o/E*D,f=Math.max(0,i-1),L=g.slice(0,f+1).map((o,k)=>({x:R(k),y:x(o.cum)})),A=[];if(f>=0&&f<g.length){A.push({x:R(f),y:x(g[f].cum)});for(let o=f+1;o<g.length;o++)A.push({x:R(o),y:x(g[o].forecast??g[o].cum)})}const O=L.length>0?L.map((o,k)=>`${k===0?"M":"L"} ${o.x.toFixed(1)} ${o.y.toFixed(1)}`).join(" "):"",z=A.length>1?A.map((o,k)=>`${k===0?"M":"L"} ${o.x.toFixed(1)} ${o.y.toFixed(1)}`).join(" "):"";return e.jsxs("div",{className:`rounded-xl border p-4 flex flex-col ${p}`,children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("p",{className:`text-3xl font-black ${c} leading-none`,children:d?"â¦":n?n(r):r}),!d&&t!==0&&e.jsxs("span",{className:`flex items-center gap-0.5 text-[11px] font-semibold px-1.5 py-0.5 rounded-full ${t>0?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,title:`Vormonat (Tag 1â${i}): ${n?n(N):N}`,children:[t>0?e.jsx(ye,{className:"w-3 h-3"}):e.jsx(ve,{className:"w-3 h-3"}),t>0?"+":"",s,"%"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:h}),w!=null&&e.jsxs("p",{className:"text-[11px] mt-0.5 font-semibold",style:{color:m},children:[r," von ",y," Termine (",w,"%)"]}),e.jsxs("div",{className:"mt-1.5 flex items-baseline gap-1.5",style:{color:m},children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wider opacity-70",children:"Forecast Monatsende:"}),e.jsx("span",{className:"text-sm font-bold",children:n?n(b):b}),i>0&&l>0&&e.jsxs("span",{className:"text-[10px] opacity-60 ml-auto",children:["Tag ",i,"/",l]})]}),e.jsx("div",{className:"flex-1 mt-2 min-h-[60px]",children:g.length>1&&e.jsxs("svg",{viewBox:`0 0 ${S} ${v}`,preserveAspectRatio:"none",className:"w-full h-full",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:`grad-${u}`,x1:"0",x2:"0",y1:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:m,stopOpacity:"0.4"}),e.jsx("stop",{offset:"100%",stopColor:m,stopOpacity:"0"})]})}),L.length>1&&e.jsx("path",{d:`${O} L ${L[L.length-1].x} ${v} L 0 ${v} Z`,fill:`url(#grad-${u})`}),O&&e.jsx("path",{d:O,stroke:m,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"}),z&&e.jsx("path",{d:z,stroke:m,strokeWidth:"2",fill:"none",strokeDasharray:"4 3",opacity:"0.5"}),L.length>0&&e.jsx("circle",{cx:L[L.length-1].x,cy:L[L.length-1].y,r:"3",fill:m})]})})]})}function st({brandId:a,dateFrom:u,dateTo:h}){const c=M.useMemo(()=>{if(u==null||h==null)return"1M";
1const v=Math.round((h-u)/864e5);return v<=1?"1D":v<=10?"1W":v<=60?"1M":v<=210?"6M":"1Y"},[u,h]),{data:p,isLoading:m}=C.analytics.leadConversionTrend.useQuery({brandId:a,range:c,dateFrom:u,dateTo:h},{staleTime:5*6e4,refetchOnWindowFocus:!1,retry:1}),n=p?.points??[],j=p?.current??0,d=p?.delta??0,g=p?.totalLeads??0,r=p?.totalContracts??0,b=300,N=64,t=Math.max(...n.map(v=>v.rate),1),s=Math.min(...n.map(v=>v.rate),0),i=4,l=N-i*2,y=Math.max(t-s,1),w=n.length>0?n.map((v,P)=>{const D=P/Math.max(n.length-1,1)*b,E=i+l-(v.rate-s)/y*l;return`${P===0?"M":"L"} ${D.toFixed(1)} ${E.toFixed(1)}`}).join(" "):"",S=n.length>0?{x:b,y:i+l-(n[n.length-1].rate-s)/y*l}:null;return e.jsxs("div",{className:"rounded-xl border bg-amber-500/10 border-amber-500/20 p-4 col-span-2 sm:col-span-1 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("p",{className:"text-3xl font-black text-amber-400",children:m?"â¦":j>0?`${j.toString().replace(".",",")} %`:"â"}),!m&&d!==0&&e.jsxs("span",{className:`flex items-center gap-1 text-[11px] font-semibold px-2 py-0.5 rounded-full ${d>0?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:[d>0?e.jsx(ye,{className:"w-3 h-3"}):e.jsx(ve,{className:"w-3 h-3"}),d>0?"+":"",d," %"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Lead â Vertrag"}),e.jsxs("p",{className:"text-[10px] text-amber-400/70 mt-0.5",children:[r," von ",g," Leads"]}),e.jsx("div",{className:"flex-1 mt-2 min-h-[60px]",children:n.length>1&&e.jsxs("svg",{viewBox:`0 0 ${b} ${N}`,preserveAspectRatio:"none",className:"w-full h-full",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:`grad-conv-${c}`,x1:"0",x2:"0",y1:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#fbbf24",stopOpacity:"0.4"}),e.jsx("stop",{offset:"100%",stopColor:"#fbbf24",stopOpacity:"0"})]})}),e.jsx("path",{d:`${w} L ${b} ${N} L 0 ${N} Z`,fill:`url(#grad-conv-${c})`}),e.jsx("path",{d:w,stroke:"#fbbf24",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"}),S&&e.jsx("circle",{cx:S.x-2,cy:S.y,r:"3",fill:"#fbbf24"})]})}),e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-2",children:["Zeitraum: ",c," (Hauptfilter)"]})]})}function Bt({rows:a,isLoading:u}){const h=n=>n>0?`${Math.round(n).toLocaleString("de-DE")} â¬`:"â",[,c]=Ke(),[p,m]=M.useState(null);return e.jsxs(V,{className:"bg-card border-border",children:[e.jsx(B,{className:"pb-2",children:e.jsxs(Q,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Ee,{className:"h-4 w-4 text-primary"}),"Studio-Ãbersicht"]})}),e.jsx(I,{className:"p-0 pb-2",children:u?e.jsx("p",{className:"px-4 py-6 text-xs text-muted-foreground",children:"Lade Datenâ¦"}):a.length?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b border-border",children:["Studio","Leads","Termine","Freunde","Shows","Lead â Termin","Verträge aus Shows","Online / Direkt","Verträge gesamt","Abgänge (Magicline)","Show â Abschluss","Umsatz","Umsatz Moremembers","Lead â Sale","Zielerreichung","Offene Feedbacks","Spend (Monat)","CPL","CPT","CPM","Spend Forecast (Monatsende)","Sales Forecast (90d)"].map(n=>e.jsx("th",{className:"text-left px-4 py-2 text-muted-foreground font-medium",children:n},n))})}),e.jsx("tbody",{children:[...a].sort((n,j)=>j.totalSales-n.totalSales).map(n=>{const j=n.goalPct,d=j===null?"text-muted-foreground":j>=100?"text-green-400 font-semibold":j>=70?"text-yellow-400":"text-red-400",g=n.totalLeads>0?Math.round(n.totalAppointments/n.totalLeads*100):0,r=n.pastAppointments??0,b=n.shows??0,N=n.pendingFeedback??0,t=n.showRate,s=t===null?"text-muted-foreground":t>=70?"text-green-400 font-semibold":t>=40?"text-yellow-400":"text-red-400 font-semibold";return e.jsxs("tr",{className:"border-b border-border/40 hover:bg-muted/20 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium text-foreground",children:n.name}),e.jsx("td",{className:"px-4 py-2.5 text-blue-400",children:n.totalLeads}),e.jsx("td",{className:"px-4 py-2.5 text-purple-400",children:n.totalAppointments}),e.jsx("td",{className:"px-4 py-2.5",children:(n.friends??0)>0?e.jsx("button",{onClick:()=>m({id:n.brandId,name:n.name}),className:"text-pink-400 hover:underline cursor-pointer",title:"Freunde-Auswertung öffnen â wie viele bestätigt / Vertrag (Abgleich per Name)",children:n.friends}):e.jsx("span",{className:"text-pink-400",children:"0"})}),e.jsx("td",{className:"px-4 py-2.5",title:r>0?`${b} erschienen / ${r} bewertete Termine`+(N>0?` · ${N} ohne Feedback (zaehlen NICHT in der Quote)`:""):N>0?`${N} Termine ohne Feedback`:"Noch keine Termine stattgefunden",children:e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:s,children:r>0?`${b}/${r}${t!=null?` (${t}%)`:""}`:"â"}),N>0&&e.jsxs("button",{onClick:()=>c(`/admin/feedbacks?brandId=${n.brandId}`),className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-orange-500/15 text-orange-400 border border-orange-500/30 hover:bg-orange-500/25 cursor-pointer",title:`${N} Termine sind vorbei aber ohne Feedback â klick zum Ãffnen & Erreicht/Nicht err. setzen damit die Quote stimmt`,children:["+",N," pend."]})]})}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("span",{className:g>=30?"text-green-400 font-semibold":g>=15?"text-yellow-400":g>0?"text-orange-400":"text-muted-foreground",children:n.totalLeads>0?`${g}%`:"â"})}),e.jsx("td",{className:"px-4 py-2.5 text-amber-400",children:n.showsContracts??0}),e.jsx("td",{className:"px-4 py-2.5 text-sky-400",children:n.onlineContracts??0}),e.jsx("td",{className:"px-4 py-2.5 text-emerald-400 font-semibold",children:n.totalSales}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums",children:e.jsx("span",{className:(n.monthCancellations??0)>0?"text-red-400 font-semibold":"text-muted-foreground",children:n.monthCancellations??0})}),e.jsx("td",{className:"px-4 py-2.5",children:(()=>{const i=n.shows??0;if(i===0)return e.jsx("span",{className:"text-muted-foreground",children:"â"});const l=n.showsContracts??0,y=Math.round(l/i*100),w=y>=50?"text-green-400 font-semibold":y>=25?"text-yellow-400":"text-red-400";return e.jsxs("span",{className:w,title:`${l} Vertraege aus ${i} Shows`,children:[l,"/",i," (",y,"%)"]})})()}),e.jsx("td",{className:"px-4 py-2.5 text-cyan-400",children:h(n.totalRevenue)}),e.jsx("td",{className:"px-4 py-2.5 text-pink-400",title:(n.agencyMonthlyFee??0)>0?`Provision aus Verträgen: ${h(n.provisionFromContracts??0)} + Pauschale: ${h(n.agencyMonthlyFee??0)} â¬/Mt à ${n.monthsInPeriod??1} = ${h(n.provisionFromFee??0)}`:"Provision aus Verträgen (keine Pauschale hinterlegt)",children:h(n.totalProvision)}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsxs("span",{className:n.conversionRate>=20?"text-green-400":n.conversionRate>=10?"text-yellow-400":"text-muted-foreground",children:[n.conversionRate,"%"]})}),e.jsx("td",{className:`px-4 py-2.5 ${d}`,children:j!==null?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-16 h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${j>=100?"bg-green-400":j>=70?"bg-yellow-400":"bg-red-400"}`,style:{width:`${Math.min(j,100)}%`}})}),e.jsxs("span",{children:[j,"%"]})]}):"â"}),e.jsx("td",{className:"px-4 py-2.5",children:(n.openFeedbacks??0)>0?e.jsx("button",{onClick:()=>c(`/admin/feedbacks?brandId=${n.brandId}`),className:"text-orange-400 font-semibold hover:underline cursor-pointer",title:"Offene Feedbacks öffnen â vergangene Termine ohne Be
1wertung",children:n.openFeedbacks}):e.jsx("span",{className:"text-muted-foreground",children:"0"})}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums",children:e.jsx("span",{className:(n.spendThisMonth??0)>0?"text-amber-400":"text-muted-foreground",children:(n.spendThisMonth??0)>0?`${Math.round(n.spendThisMonth??0).toLocaleString("de-DE")} â¬`:"â"})}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums",children:e.jsx("span",{className:n.cpl!=null?"text-cyan-400":"text-muted-foreground",children:n.cpl!=null?`${n.cpl.toLocaleString("de-DE")} â¬`:"â"})}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums",children:e.jsx("span",{className:n.cpt!=null?"text-purple-400":"text-muted-foreground",children:n.cpt!=null?`${n.cpt.toLocaleString("de-DE")} â¬`:"â"})}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums",children:e.jsx("span",{className:n.cpm!=null?"text-fuchsia-400":"text-muted-foreground",children:n.cpm!=null?`${n.cpm.toLocaleString("de-DE")} â¬`:"â"})}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums",children:e.jsx("span",{className:n.budgetForecastMonthEnd!=null?"text-orange-400":"text-muted-foreground",children:n.budgetForecastMonthEnd!=null?`${n.budgetForecastMonthEnd.toLocaleString("de-DE")} â¬`:"â"})}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums",children:e.jsx("span",{className:n.salesForecast90d!=null?"text-emerald-400 font-semibold":"text-muted-foreground",children:n.salesForecast90d!=null?`${n.salesForecast90d.toLocaleString("de-DE")}`:"â"})})]},n.brandId)})}),e.jsx("tfoot",{children:e.jsx("tr",{className:"border-t border-border bg-muted/10 font-semibold",children:(()=>{const n=a.reduce((t,s)=>t+s.totalLeads,0),j=a.reduce((t,s)=>t+s.totalAppointments,0),d=a.reduce((t,s)=>t+(s.friends??0),0),g=a.reduce((t,s)=>t+(s.pastAppointments??0),0),r=a.reduce((t,s)=>t+(s.shows??0),0),b=g>0?Math.round(r/g*100):null,N=a.reduce((t,s)=>t+s.totalSales,0);return e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-4 py-2 text-muted-foreground",children:"Gesamt"}),e.jsx("td",{className:"px-4 py-2 text-blue-400",children:n}),e.jsx("td",{className:"px-4 py-2 text-purple-400",children:j}),e.jsx("td",{className:"px-4 py-2 text-pink-400",children:d}),e.jsx("td",{className:"px-4 py-2 text-muted-foreground",children:g>0?`${r}/${g}${b!=null?` (${b}%)`:""}`:"â"}),e.jsx("td",{className:"px-4 py-2 text-muted-foreground",children:"â"}),e.jsx("td",{className:"px-4 py-2 text-amber-400",children:a.reduce((t,s)=>t+(s.showsContracts??0),0)}),e.jsx("td",{className:"px-4 py-2 text-sky-400",children:a.reduce((t,s)=>t+(s.onlineContracts??0),0)}),e.jsx("td",{className:"px-4 py-2 text-emerald-400",children:N}),e.jsx("td",{className:"px-4 py-2 text-red-400",children:a.reduce((t,s)=>t+(s.monthCancellations??0),0)}),(()=>{const t=a.reduce((i,l)=>i+(l.showsContracts??0),0);if(r===0)return e.jsx("td",{className:"px-4 py-2 text-muted-foreground",children:"â"});const s=Math.round(t/r*100);return e.jsxs("td",{className:"px-4 py-2 text-muted-foreground",children:[t,"/",r," (",s,"%)"]})})(),e.jsx("td",{className:"px-4 py-2 text-cyan-400",children:h(a.reduce((t,s)=>t+s.totalRevenue,0))}),e.jsx("td",{className:"px-4 py-2 text-pink-400",children:h(a.reduce((t,s)=>t+s.totalProvision,0))}),e.jsx("td",{className:"px-4 py-2 text-muted-foreground",children:n>0?`${Math.round(N/n*100)}%`:"â"}),e.jsx("td",{className:"px-4 py-2 text-muted-foreground",children:"â"}),e.jsx("td",{className:"px-4 py-2 text-orange-400",children:a.reduce((t,s)=>t+(s.openFeedbacks??0),0)})]})})()})})]})}):e.jsx("p",{className:"px-4 py-6 text-xs text-muted-foreground",children:"Keine aktiven Studios gefunden."})}),e.jsx(Qt,{brand:p,onClose:()=>m(null)})]})}function Qt({brand:a,onClose:u}){const{data:h,isLoading:c}=C.analytics.friendsConversion.useQuery({brandId:a?.id??0},{enabled:!!a,staleTime:6e4}),p=h?.invited??0,m=h?.confirmed??0,n=h?.withContract??0,j=g=>p>0?Math.round(g/p*100):0,d=h?.friends??[];return e.jsx(be,{open:!!a,onOpenChange:g=>!g&&u(),children:e.jsxs(je,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[e.jsx(fe,{children:e.jsxs(Ne,{children:["Freunde-Auswertung â ",a?.name]})}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"Abgleich der eingeladenen Freunde per Vor- + Nachname gegen die Leads dieser Marke (gesamt)."}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 my-3",children:[e.jsxs("div",{className:"rounded-lg border border-border p-3 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-pink-400",children:p}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Eingeladen"})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-blue-400",children:m}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Termin bestätigt · ",j(m),"%"]})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-green-400",children:n}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Vertrag · ",j(n),"%"]})]})]}),c?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"Lädtâ¦"}):d.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"Keine eingeladenen Freunde gefunden."}):e.jsx("div",{className:"rounded-lg border border-border overflow-hidden divide-y divide-border",children:d.map((g,r)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:`${g.firstName??""} ${g.lastName??""}`.trim()||"â"}),g.inviter&&e.jsxs("div",{className:"text-[11px] text-muted-foreground truncate",children:["eingeladen von ",g.inviter]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[!g.matched&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:"kein Lead-Match"}),g.confirmed&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-500/15 text-blue-400 border border-blue-500/30",children:"Termin â"}),g.hasContract&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-green-500/15 text-green-400 border border-green-500/30",children:"Vertrag â"})]})]},r))})]})})}function rt({kpis:a,showFinancials:u=!0,contractsOverride:h,commissionOverride:c,commissionFlatOverride:p}){const m=new Date,n=a?.daysInMonth??new Date(m.getFullYear(),m.getMonth()+1,0).getDate(),j=a?.remainingDaysThisMonth??n-m.getDate()+1,d=Math.max(1,n-j+1),g=Math.max(0,j-1),r=h??a?.gymContractsThisMonth??0,b=c??a?.gymCommissionThisMonth??0,N=p??0,t=Math.max(0,b-N),s=r/d,i=t/d,l=Math.round(s*n),y=Math.round(i*n+N),w=Math.round(s*g),S=Math.round(i*g),v=m.toLocaleDateString("de-DE",{month:"long",year:"numeric"}),P=Math.round((d-1)/n*100),D=a?.monthlyGoalSetting>0?a.monthlyGoalSetting:a?.thisMonthContractsNeeded>0?a.thisMonthContractsNeeded:0,E=D>0?D-l:0,R=D===0||l>=D,x=!R&&E<=Math.ceil(D*.15),f=D>0&&g>
10?Math.ceil(Math.max(0,D-r)/g):null,L=D>0?R?"Im Plan â":x?"Leicht hinter Plan":"Mehr Gas nötig!":s>=1.5?"Starke Performance":s>=.8?"Solide Performance":"Langsames Tempo",A=D>0?R?"#22c55e":x?"#f59e0b":"#ef4444":s>=1.5?"#22c55e":s>=.8?"#f59e0b":"#ef4444";return e.jsxs(V,{className:"bg-card border-border overflow-hidden",children:[e.jsx("div",{className:"h-1.5",style:{background:`linear-gradient(90deg, ${A}, #3b82f6, #ec4899)`}}),e.jsxs(B,{className:"pb-3 pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(Q,{className:"text-base font-bold flex items-center gap-2",children:[e.jsx(ue,{className:"h-5 w-5 text-blue-400"}),"Hochrechnung Monatsende â ",v]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs px-2.5 py-1 rounded-full font-semibold",style:{background:`${A}18`,color:A,border:`1px solid ${A}40`},children:L}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Tag ",d," / ",n," · ",g," Tage verbleibend"]})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${P}%`,background:"linear-gradient(90deg, #3b82f6, #60a5fa)"}})}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground mt-1",children:[e.jsxs("span",{children:["1. ",m.toLocaleDateString("de-DE",{month:"long"})]}),e.jsxs("span",{className:"font-medium text-blue-400",children:[P,"% vergangen"]}),e.jsxs("span",{children:["Ende ",m.toLocaleDateString("de-DE",{month:"long"})]})]})]})]}),e.jsx(I,{className:"pb-5",children:e.jsxs("div",{className:"grid gap-4 grid-cols-1 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-2xl p-5 space-y-4",style:{background:"rgba(16,185,129,0.07)",border:"1px solid rgba(16,185,129,0.25)"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-emerald-400",children:[e.jsx(qe,{className:"w-4 h-4"}),"Verträge bis Monatsende"]}),D>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Ziel: ",e.jsx("span",{className:"text-white font-bold text-base",children:D})]})]}),e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-5xl font-black leading-none",style:{color:A},children:l}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Hochrechnung"})]}),D>0&&e.jsxs("div",{className:"pb-1",children:[e.jsxs("p",{className:"text-3xl font-black text-foreground/25 leading-none",children:["/ ",D]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Monatsziel"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded-lg bg-black/20 px-3 py-2",children:[e.jsx("p",{className:"font-bold text-foreground",children:r}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"bereits abgeschlossen"})]}),e.jsxs("div",{className:"rounded-lg bg-black/20 px-3 py-2",children:[e.jsxs("p",{className:"font-bold text-emerald-300",children:["+",w]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"noch erwartet"})]})]}),D>0&&e.jsx("div",{className:"rounded-lg px-3 py-2 text-xs font-medium",style:{background:`${A}14`,color:A,border:`1px solid ${A}30`},children:R?`Ziel wird erreicht${l-D>0?` · +${l-D} über Ziel`:" · genau auf Kurs"}`:`${E} Verträge fehlen zum Ziel${f?` · ${f}/Tag nötig`:""}`}),e.jsxs("div",{children:[e.jsx("div",{className:"h-2 bg-black/20 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${D>0?Math.min(l/D*100,100):Math.min(r/Math.max(l,1)*100,100)}%`,background:D>0?A:"#22c55e"}})}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1.5",children:["à ",e.jsx("span",{className:"font-semibold text-emerald-300",children:s.toFixed(2)}),"/Tag",D>0&&e.jsxs("span",{children:[" · Forecast: ",e.jsxs("span",{className:"font-semibold",style:{color:A},children:[Math.round(l/D*100),"%"]})," des Ziels"]})]})]})]}),u&&e.jsxs("div",{className:"rounded-2xl p-5 space-y-4",style:{background:"rgba(236,72,153,0.07)",border:"1px solid rgba(236,72,153,0.25)"},children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-pink-400",children:[e.jsx(Je,{className:"w-4 h-4"}),"Umsatz Moremembers bis Monatsende"]}),b===0?e.jsxs("div",{className:"py-4 text-center space-y-1",children:[e.jsx("p",{className:"text-3xl font-black text-pink-400/40",children:"â"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Noch keine provisionspflichtigen Verträge diesen Monat"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-end gap-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-5xl font-black text-pink-400 leading-none",children:ce(y)}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Hochrechnung"})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded-lg bg-black/20 px-3 py-2",children:[e.jsx("p",{className:"font-bold text-foreground",children:ce(b)}
1),e.jsx("p",{className:"text-xs text-muted-foreground",children:"bereits erzielt"})]}),e.jsxs("div",{className:"rounded-lg bg-black/20 px-3 py-2",children:[e.jsxs("p",{className:"font-bold text-pink-300",children:["+",ce(S)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"noch erwartet"})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"h-2 bg-black/20 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-pink-500 rounded-full",style:{width:`${y>0?Math.min(b/y*100,100):0}%`}})}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1.5",children:["à ",e.jsx("span",{className:"font-semibold text-pink-300",children:ce(Math.round(i))}),"/Tag"]})]})]})]})]})})]})}function Wt({brandId:a,dateFrom:u,dateTo:h,rangeLabel:c}){const[p,m]=M.useState(!1),{data:n=[],isLoading:j}=C.studioStats.contractShowAudit.useQuery({brandId:a,dateFrom:u,dateTo:h},{enabled:p,refetchOnWindowFocus:!1,staleTime:2*6e4}),d=n,g=t=>new Date(t).toLocaleString("de-DE",{day:"2-digit",month:"2-digit",year:"2-digit",hour:"2-digit",minute:"2-digit"}),r=d.filter(t=>t.countsAsShow).length,b=d.filter(t=>t.countsAsContractFromShow).length,N=d.filter(t=>t.appointmentCount===0).length;return e.jsxs("div",{className:"rounded-xl border border-border bg-card",children:[e.jsxs("button",{onClick:()=>m(t=>!t),className:"w-full flex items-center justify-between px-4 py-3 text-left",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Vertrags-Show-Diagnose"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Pro Vertrag: hatte der Lead einen Termin, dessen Status & warum es als Show zählt (",c,")"]})]}),e.jsx(Ue,{className:`h-4 w-4 text-muted-foreground transition-transform ${p?"rotate-180":""}`})]}),p&&e.jsx("div",{className:"px-4 pb-4",children:j?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Lädtâ¦"}):d.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Keine Verträge im Zeitraum."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2 mb-3 text-xs",children:[e.jsxs("span",{className:"px-2 py-1 rounded bg-muted",children:[d.length," Verträge"]}),e.jsxs("span",{className:"px-2 py-1 rounded bg-amber-500/10 text-amber-600 dark:text-amber-400",children:[r," zählen als Show"]}),e.jsxs("span",{className:"px-2 py-1 rounded bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",children:[b," Vertrag aus Show"]}),e.jsxs("span",{className:"px-2 py-1 rounded bg-blue-500/10 text-blue-600 dark:text-blue-400",children:[N," ohne Termin (rein online)"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-muted-foreground border-b border-border",children:[e.jsx("th",{className:"py-1.5 pr-2",children:"Lead"}),e.jsx("th",{className:"py-1.5 pr-2",children:"Studio"}),e.jsx("th",{className:"py-1.5 pr-2",children:"Abschluss"}),e.jsx("th",{className:"py-1.5 pr-2",children:"Quelle"}),e.jsx("th",{className:"py-1.5 pr-2",children:"Termin"}),e.jsx("th",{className:"py-1.5 pr-2",children:"Show?"}),e.jsx("th",{className:"py-1.5 pr-2",children:"Bewertung"})]})}),e.jsx("tbody",{children:d.map(t=>e.jsxs("tr",{className:"border-b border-border/40",children:[e.jsx("td",{className:"py-1.5 pr-2 font-medium text-foreground whitespace-nowrap",children:t.leadName}),e.jsx("td",{className:"py-1.5 pr-2 text-muted-foreground",children:t.brandName}),e.jsxs("td",{className:"py-1.5 pr-2 whitespace-nowrap",children:[g(t.signedAt),e.jsxs("span",{className:"text-muted-foreground",children:[" · ",Number(t.value).toFixed(2)," â¬"]})]}),e.jsx("td",{className:"py-1.5 pr-2 text-muted-foreground",children:t.contractSource}),e.jsx("td",{className:"py-1.5 pr-2 whitespace-nowrap",children:t.appointmentCount===0?e.jsx("span",{className:"text-muted-foreground",children:"â"}):e.jsxs(e.Fragment,{children:[t.apptScheduledAt?g(t.apptScheduledAt):"?"," ",e.jsxs("span",{className:"text-muted-foreground",children:["(",t.apptStatus,", ",t.apptRel," Abschluss)"]})]})}),e.jsx("td",{className:"py-1.5 pr-2",children:t.countsAsShow?e.jsx("span",{className:"text-amber-600 dar
1k:text-amber-400 font-medium",children:"â Show"}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx("td",{className:"py-1.5 pr-2 text-muted-foreground",children:t.rule})]},t.id))})]})})]})})]})}function Oe({brandId:a,dateFrom:u,dateTo:h,label:c}){const p=new Date(u).toISOString().slice(0,10),m=new Date(h).toISOString().slice(0,10),{data:n}=C.ads.roi.useQuery({brandId:a,dateFrom:p,dateTo:m},{staleTime:5*6e4,refetchOnWindowFocus:!1,retry:1}),j=Number(n?.spend??0);return e.jsx(Z,{label:c,value:j>0?`${Math.round(j).toLocaleString("de-DE")} â¬`:"â",color:"text-rose-400",bg:"bg-rose-500/10 border-rose-500/20"})}function _t(){const{user:a}=Me(),u=a?.role==="assistant",[,h]=Ke(),[c,p]=M.useState(void 0),[m,n]=M.useState(null),j={refetchOnWindowFocus:!1,retry:1,staleTime:2*6e4},{data:d}=C.brands.list.useQuery(void 0,{staleTime:30*6e4,refetchOnWindowFocus:!1,refetchOnMount:!1}),g=M.useMemo(()=>oe(),[]),[r,b]=M.useState(g.from),[N,t]=M.useState(g.to),s=M.useMemo(()=>({from:r,to:N}),[r,N]),i=M.useMemo(()=>{const x=new Date(r),f=new Date(N),L=x.getMonth()===f.getMonth()&&x.getFullYear()===f.getFullYear(),A=x.getDate()===1,O=f.getDate()>=new Date(f.getFullYear(),f.getMonth()+1,0).getDate();return L&&A&&O?x.toLocaleDateString("de-DE",{month:"long",year:"numeric"}):r<=0?"Gesamt":`${x.toLocaleDateString("de-DE")} â ${f.toLocaleDateString("de-DE")}`},[r,N]),{data:l=[]}=C.analytics.getDailyActivity.useQuery({brandId:c,dateFrom:s.from,dateTo:s.to},j),{data:y=[],isLoading:w}=C.studioStats.comparison.useQuery({dateFrom:s.from,dateTo:s.to},{...j,staleTime:5*6e4}),{data:S}=C.dashboard.kpis.useQuery({brandId:c,dateFrom:s.from,dateTo:s.to},j),{data:v}=C.dashboard.callQuotesToday.useQuery({brandId:c},{refetchInterval:6e4,staleTime:3e4}),{data:P}=C.tasks.completedTodayByUser.useQuery({brandId:c},{refetchInterval:6e4,staleTime:3e4}),{data:D=[]}=C.appointments.listOpenFeedbacks.useQuery({brandId:c??void 0,limit:100},{refetchInterval:6e4,staleTime:3e4}),E=l.map(x=>({day:new Date(x.day??x.date).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit"}),Leads:Number(x.leads??0),Termine:Number(x.appointments??0),Verträge:Number(x.contracts??0)})),R=y??[];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Dashboard"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-0.5",children:[i,c!=null&&d?` · ${d.find(x=>x.id===c)?.name??""}`:" · Alle Marken"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsx(F,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>{const x=new Date,f=new Date(x.getFullYear(),x.getMonth(),x.getDate()),L=new Date(x.getFullYear(),x.getMonth(),x.getDate(),23,59,59,999);b(f.getTime()),t(L.getTime())},children:"Heute"}),e.jsx(F,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>{const x=oe();b(x.from),t(x.to)},children:"Dieser Monat"}),e.jsx(F,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>{const x=new Date,f=new Date(x.getFullYear(),x.getMonth()-1,1),L=new Date(x.getFullYear(),x.getMonth(),0,23,59,59,999);b(f.getTime()),t(L.getTime())},children:"Letzter Monat"}),e.jsx(F,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>{b(0),t(Date.now())},children:"Gesamt"})]}),e.jsx("input",{type:"date",value:ge(r),onChange:x=>{const f=new Date(x.target.value);f.setHours(0,0,0,0),b(f.getTime())},className:"bg-card border border-border text-xs h-8 px-2 rounded"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"}),e.jsx("input",{type:"date",value:ge(N),onChange:x=>{const f=new Date(x.target.value);f.setHours(23,59,59,999),t(f.getTime())},className:"bg-card border border-border text-xs h-8 px-2 rounded"}),e.jsxs(Qe,{value:c?.toString()??"all",onValueChange:x=>p(x==="all"?void 0:Number(x)),children:[e.jsxs(We,{className:"w-56 h-9",children:[e.jsx(Ee,{className:"h-3.5 w-3.5 mr-2 text-muted-foreground"}),e.jsx(_e,{placeholder:"Alle Marken"})]}),e.jsxs(Ge,{children:[e.jsx(me,{value:"all",children:"Alle Marken (kumuliert)"}),d?.map(x=>e.jsx(me,{value:x.id.toString(),children:x.name},x.id))]})]})]})]}),D.length>0&&e.jsx(V,{className:"bg-amber-500/5 border-amber-500/30",children:e.jsxs(I,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Nt,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:"Offene Termin-Feedbacks"}),e.jsx("span",{className:"text-xs font-bold px-1.5 py-0.5 rounded-full bg-amber-500 text-white",children:D.length})]}),e.jsx(F,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>h("/admin/feedbacks"),children:"Alle ansehen"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-2",children:"Vergangene Termine ohne Ergebnis (erschienen / No-Show / Abschluss). Bitte nachpflegen."}),e.jsx("div",{className:"divide-y divide-border",children:D.slice(0,5).map(x=>e.jsxs("button",{onClick:()=>x.leadId&&h(`/leads/${x.leadId}`),className:"w-full flex items-center justify-between gap-2 py-1.5 text-left hover:bg-muted/40 rounded px-1",children:[e.jsx("span",{className:"text-sm text-foreground truncate",children:`${x.leadFirstName??""} ${x.leadLastName??""}`.trim()||"Termin"}),e.jsxs("span",{className:"text-[11px] text-muted-foreground shrink-0",children:[x.brandName??""," · ",new Date(x.scheduledAt).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit"})]})]},x.id))}),D.length>5&&e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-1.5 text-center",children:["+ ",D.length-5," weitere"]})]})}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 ga
1p-3",children:(()=>{if((()=>{const T=oe();return Math.abs(r-T.from)<1e3&&Math.abs(N-T.to)<1e3})())return e.jsxs(e.Fragment,{children:[e.jsx(de,{brandId:c,metric:"leads",label:"Neue Leads im Monat",color:"text-blue-400",bg:"bg-blue-500/10 border-blue-500/20",accentRgb:"#60a5fa"}),e.jsx(de,{brandId:c,metric:"appointments",label:"Termine im Monat",color:"text-purple-400",bg:"bg-purple-500/10 border-purple-500/20",accentRgb:"#c084fc"}),e.jsx(de,{brandId:c,metric:"shows",label:"Shows im Monat",color:"text-amber-400",bg:"bg-amber-500/10 border-amber-500/20",accentRgb:"#fbbf24"}),e.jsx(de,{brandId:c,metric:"contracts",label:"Verträge im Monat",color:"text-emerald-400",bg:"bg-emerald-500/10 border-emerald-500/20",accentRgb:"#34d399"}),e.jsx(st,{brandId:c,dateFrom:s.from,dateTo:s.to}),e.jsx(Oe,{brandId:c,dateFrom:s.from,dateTo:s.to,label:"Ad-Spend (Monat)"})]});const f=S,L=f?.totalLeads??0,A=f?.totalAppointments??0,O=f?.showedUpCount??0,z=f?.totalContracts??0,o=L>0?Math.round(z/L*1e3)/10:0,k=L>0?Math.round(A/L*1e3)/10:0;return e.jsxs(e.Fragment,{children:[e.jsx(Z,{label:`Leads (${i})`,value:L,color:"text-blue-400",bg:"bg-blue-500/10 border-blue-500/20"}),e.jsx(Z,{label:`Termine (${i})`,value:A,color:"text-purple-400",bg:"bg-purple-500/10 border-purple-500/20"}),e.jsx(Z,{label:`Lead â Termin (${i})`,value:`${k} %`,color:"text-fuchsia-500 dark:text-fuchsia-400",bg:"bg-fuchsia-500/10 border-fuchsia-500/20"}),e.jsx(Z,{label:`Shows (${i})`,value:O,color:"text-amber-400",bg:"bg-amber-500/10 border-amber-500/20"}),e.jsx(Z,{label:`Verträge (${i})`,value:z,color:"text-emerald-400",bg:"bg-emerald-500/10 border-emerald-500/20"}),e.jsx(Z,{label:`Lead â Vertrag (${i})`,value:`${o} %`,color:"text-orange-400",bg:"bg-orange-500/10 border-orange-500/20"}),e.jsx(Oe,{brandId:c,dateFrom:r,dateTo:N,label:`Ad-Spend (${i})`})]})})()}),e.jsx(nt,{brandId:c,dateFrom:r,dateTo:N}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(Z,{label:"Termine heute",value:S?.todayAppointmentsScheduled??0,color:"text-purple-400",bg:"bg-purple-500/10 border-purple-500/20"}),e.jsx(Z,{label:"Termine bestätigt (heute)",value:`${S?.todayAppointmentsConfirmed??0} / ${S?.todayAppointmentsScheduled??0}`,color:"text-emerald-400",bg:"bg-emerald-500/10 border-emerald-500/20"})]}),e.jsxs(V,{className:"bg-card border-border",children:[e.jsx(B,{className:"pb-2",children:e.jsxs(Q,{className:"text-sm flex items-center justify-between",children:[e.jsx("span",{children:"Aufgaben heute erledigt â pro Assistenz"}),e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["Gesamt: ",(P??[]).reduce((x,f)=>x+Number(f.count??0),0)]})]})}),e.jsx(I,{children:(P??[]).length?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-2",children:(P??[]).map(x=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border bg-muted/30 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:x.name}),x.role&&e.jsx("p",{className:"text-[10px] text-muted-foreground capitalize",children:String(x.role).replace(/_/g," ")})]}),e.jsx("span",{className:"text-lg font-bold text-emerald-400 ml-2 shrink-0",children:x.count})]},x.userId))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Heute wurden noch keine Aufgaben erledigt."})})]}),e.jsxs(V,{className:"bg-card border-border",children:[e.jsx(B,{className:"pb-2",children:e.jsxs(Q,{className:"text-base flex items-center gap-2",children:[e.jsx(Se,{className:"w-4 h-4 text-primary"}),"Tägliche Aktivität (",new Date().toLocaleDateString("de-DE",{month:"long"}),")"]})}),e.jsx(I,{children:E.length===0?e.jsx("div",{className:"text-sm text-muted-foreground text-center py-8",children:"Noch keine Aktivität in diesem Monat"}):e.jsx("div",{className:"h-72",children:e.jsx(he,{width:"100%",height:"100%",children:e.jsxs(Se,{data:E,margin:{top:8,right:8,bottom:8,left:-12},children:[e.jsx(Le,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",opacity:.4}),e.jsx($e,{dataKey:"day",stroke:"hsl(var(--muted-foreground))",fontSize:10}),e.jsx(Fe,{stroke:"hsl(var(--muted-foreground))",fontSize:10,allowDecimals:!1}),e.jsx(pe,{contentStyle:{background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:6,fontSize:12},cursor:{fill:"hsl(var(--muted))",opacity:.2}}),e.jsx(Ae,{wrapperStyle:{fontSize:11},iconSize:10}),e.jsx(ee,{dataKey:"Leads",fill:"#60a5fa",radius:[3,3,0,0]}),e.jsx(ee,{dataKey:"Termine",fill:"#c084fc",radius:[3,3,0,0]}),e.jsx(ee,{dataKey:"Verträge",fill:"#34d399",radius:[3,3,0,0]})]})})})})]}),S&&!u&&(()=>{const x=c?R.filter(z=>z.brandId===c):R,f=x.length>0,L=f?x.reduce((z,o)=>z+(o.totalSales??0),0):void 0,A=f?x.reduce((z,o)=>z+(o.totalProvision??0),0):void 0,O=f?x.reduce((z,o)=>z+(o.provisionFromFee??0),0):void 0;return e.jsx(rt,{kpis:S,showFinancials:!0,contractsOverride:L,commissionOverride:A,commissionFlatOverride:O})})(),!c&&e.jsx(Bt,{rows:R,isLoading:w}),!u&&e.jsx(Wt,{brandId:c,dateFrom:s.from,dateTo:s.to,rangeLabel:i}),!c&&e.jsx(It,{dateFrom:s.from,dateTo:s.to}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground mb-1",children:["ð",e.jsx("span",{children:"Calls heute"})]}),e.jsx("div",{className:"text-2xl sm:text-3xl font-black text-blue-400",children:(v?.calls??0).toLocaleStr
1ing("de-DE")}),e.jsx("div",{className:"text-[10px] text-muted-foreground mt-1",children:"Alle Telefon-Versuche"})]}),e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground mb-1",children:["â",e.jsx("span",{children:"Erreicht"})]}),e.jsx("div",{className:"text-2xl sm:text-3xl font-black text-emerald-400",children:(v?.reached??0).toLocaleString("de-DE")}),v?.reachedRate!=null&&e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-1",children:[Math.round(v.reachedRate*100),"% Quote"]})]}),e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground mb-1",children:["ð
",e.jsx("span",{children:"Termine gebucht"})]}),e.jsx("div",{className:"text-2xl sm:text-3xl font-black text-violet-400",children:(v?.apptsBooked??0).toLocaleString("de-DE")}),v?.apptRate!=null&&e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-1",children:[Math.round(v.apptRate*100),"% von erreicht"]})]}),e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground mb-1",children:["ð",e.jsx("span",{children:"Neue Leads heute"})]}),e.jsx("div",{className:"text-2xl sm:text-3xl font-black text-orange-400",children:(v?.newLeads??0).toLocaleString("de-DE")})]})]}),v?.byUser&&v.byUser.length>0&&e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-2 font-semibold uppercase",children:"Telefonleistung heute pro Vertriebler"}),e.jsx("div",{className:"space-y-1",children:v.byUser.map(x=>e.jsxs("button",{type:"button",className:"flex items-center justify-between text-sm gap-2 w-full text-left hover:bg-muted/40 rounded px-1.5 py-1 -mx-1.5 transition-colors disabled:cursor-default",onClick:()=>x.userId&&n({id:x.userId,name:x.userName}),disabled:!x.userId,title:x.userId?"Klick: Anruf-Log + Termine heute anzeigen":"Kein User-ID â Log nicht verfuegbar",children:[e.jsx("span",{className:"truncate flex-1 text-foreground underline-offset-2 hover:underline",children:x.userName}),e.jsxs("span",{className:"text-muted-foreground tabular-nums flex items-center gap-2 flex-wrap justify-end",children:[e.jsxs("span",{title:"Anzahl aller Telefonversuche (Erreicht + Nicht-Erreicht) heute",children:[x.calls," Calls"]}),e.jsxs("span",{title:"Davon erreicht â d.h. activityType='reached' (Lead war wirklich am Apparat)",children:["· ",e.jsx("strong",{className:"text-emerald-600 dark:text-emerald-400",children:x.reached})," erreicht",x.reachedRate!=null&&e.jsxs("span",{className:"text-[11px] text-muted-foreground ml-1",children:["(",Math.round(x.reachedRate*100),"%)"]})]}),x.appts!=null&&e.jsxs("span",{title:"Termine heute vereinbart â distincte Leads gezaehlt (Doppel-Klicks zaehlen nicht). Quote = Termine / Erreichte.",children:["· ",e.jsx("strong",{className:"text-blue-600 dark:text-blue-400",children:x.appts})," Termine",x.apptRate!=null&&x.appts>0&&e.jsxs("span",{className:"text-[11px] text-muted-foreground ml-1",children:["(",Math.round(x.apptRate*100),"%)"]})]}),(x.friends??0)>0&&e.jsxs("span",{title:"Freunde die der Lead zum Termin mitgebracht hat (appointment_guests, gezaehlt fuer die heute gebuchten Termine dieses Vertrieblers).",children:["· ",e.jsx("strong",{className:"text-amber-600 dark:text-amber-400",children:x.friends})," Freunde"]}),(x.contracts??0)>0&&e.jsxs("span",{title:`Vertraege heute aus Leads die dieser User mit appointment_booked beruehrt hat${x.revenue?` (Umsatz: ${x.revenue.toLocaleString("de-DE",{style:"currency",currency:"EUR",maximumFractionDigits:0})})`:""}`,children:["· ",e.jsx("strong",{className:"text-pink-600 dark:text-pink-400",children:x.contracts})," Verträge",x.contractRate!=null&&e.jsxs("span",{className:"text-[11px] text-muted-foreground ml-1",children:["(",Math.round(x.contractRate*100),"% von Termine)"]}),x.revenue>0&&e.jsxs("span",{className:"text-[11px] text-muted-foreground ml-1",children:["· ",Number(x.revenue).toLocaleStr
1ing("de-DE",{style:"currency",currency:"EUR",maximumFractionDigits:0})]})]})]})]},x.userId??"?"))}),e.jsxs("div",{className:"flex items-center justify-between mt-2 gap-2 flex-wrap",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Klick auf einen Vertriebler oeffnet das Anruf-Log + Termine-Liste."}),e.jsx(Gt,{})]})]}),m&&e.jsx(Ut,{userId:m.id,userName:m.name,brandId:c,onOpenChange:x=>{x||n(null)}}),e.jsx(Kt,{brandId:c,dateFrom:s.from,dateTo:s.to,rangeLabel:i}),e.jsx(Ot,{brandId:c,dateFrom:s.from,dateTo:s.to})]})}function Gt(){const a=C.useUtils(),[u,h]=M.useState(1),c=C.dashboard.backfillReachedFromAppointments.useMutation({onSuccess:p=>{window.alert(`Backfill abgeschlossen: ${p.backfilled} reached-Events erstellt · ${p.skipped} uebersprungen (existierten schon) · ${p.scanned} Termine gescannt.`),a.dashboard.callQuotesToday.invalidate()},onError:p=>window.alert(`Fehler: ${p.message}`)});return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("select",{value:u,onChange:p=>h(Number(p.target.value)),className:"h-7 text-[10px] rounded border border-border bg-background px-1.5",children:[e.jsx("option",{value:1,children:"heute"}),e.jsx("option",{value:3,children:"letzte 3 Tage"}),e.jsx("option",{value:7,children:"letzte 7 Tage"}),e.jsx("option",{value:14,children:"letzte 14 Tage"}),e.jsx("option",{value:30,children:"letzte 30 Tage"})]}),e.jsx(F,{type:"button",variant:"outline",size:"sm",className:"h-7 text-[10px] px-2",disabled:c.isPending,onClick:()=>{window.confirm(`Reached-Backfill fuer ${u} Tag(e) starten? Fuer jeden Termin der noch kein Erreicht-Event hat wird eines erzeugt (1 Sek. vor dem Termin).`)&&c.mutate({daysBack:u})},children:c.isPending?"Backfill laeuftâ¦":"ð§ Reached-Backfill"})]})}function Ut({userId:a,userName:u,brandId:h,onOpenChange:c}){const p=C.dashboard.callLogToday.useQuery({userId:a,brandId:h}),m=p.data?.activities??[],n=p.data?.appointments??[],j=p.data?.brandBreakdown??[],d=r=>new Date(r).toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit"}),g=r=>new Date(r).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"2-digit"});return e.jsx(be,{open:!0,onOpenChange:c,children:e.jsxs(je,{className:"max-w-4xl max-h-[85vh] overflow-y-auto",children:[e.jsx(fe,{children:e.jsxs(Ne,{children:["ð Anruf-Log heute â ",u]})}),e.jsxs("div",{className:"space-y-4 mt-2",children:[j.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase mb-2 font-semibold",children:"Aufteilung nach Marke"}),e.jsx("div",{className:"border border-border rounded-md overflow-hidden",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-muted/50 text-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Marke"}),e.jsx("th",{className:"text-right px-2 py-1.5 font-semibold",children:"Anrufe"}),e.jsx("th",{className:"text-right px-2 py-1.5 font-semibold",children:"Erreicht"}),e.jsx("th",{className:"text-right px-2 py-1.5 font-semibold",children:"Quote"}),e.jsx("th",{className:"text-right px-2 py-1.5 font-semibold",children:"Termine"})]})}),e.jsx("tbody",{children:j.map(r=>{const b=r.reachQuote==null?"text-muted-foreground":r.reachQuote>=30?"text-emerald-600 dark:text-emerald-400 font-semibold":r.reachQuote>=15?"text-yellow-600 dark:text-yellow-400":"text-red-600 dark:text-red-400 font-semibold";return e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"px-2 py-1.5 font-medium text-foreground",children:r.brandName}),e.jsx("td",{className:"px-2 py-1.5 text-right tabular-nums",children:r.totalCalls}),e.jsx("td",{className:"px-2 py-1.5 text-right tabular-nums text-emerald-600 dark:text-emerald-400",children:r.reached}),e.jsx("td",{className:`px-2 py-1.5 text-right tabular-nums ${b}`,children:r.reachQuote==null?"â":`${r.reachQuote}%`}),e.jsx("td",{className:"px-2 py-1.5 text-right tabular-nums text-purple-600 dark:text-purple-400",children:r.appointments})]},String(r.brandId??"_none"))})})]})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs text-muted-foreground uppercase mb-2 font-semibold",children:["Anrufe (",m.length,")"]}),p.isLoading?e.jsx("div",{className:"text-sm text-muted-foreground",children:"Ladeâ¦"}):m.length===0?e.jsx("div",{className:"text-sm text-muted-foreground italic",children:"Heute noch keine Anrufe geloggt."}):e.jsx("div",{className:"border border-border rounded-md overflow-hidden",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-muted/50 text-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Zeit"}),e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Status"}),e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Lead"}),e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Marke"}),e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Telefon"}),e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Notiz"})]})}),e.jsx("tbody",{children:m.map(r=>e.jsxs("tr",{className:"border-t border-border hover:bg-muted/20",children:[e.jsx("td",{className:"px-2 py-1.5 tabular-nums text-muted-foreground",children:d(r.createdAt)}),e.jsx("td",{className:"px-2 py-1.5",children:r.activityType==="reached"?e.jsx("span",{className:"text-emerald-600 dark:text-emerald-400 font-semibold",children:"â erreicht"}):r.activityType==="appointment_booked"?e.jsx("span",{className:"text-purple-600 dar
1k:text-purple-400",children:"ð
Termin"}):e.jsx("span",{className:"text-orange-600 dark:text-orange-400",children:"â nicht err."})}),e.jsx("td",{className:"px-2 py-1.5",children:r.leadId?e.jsxs("a",{href:`/leads/${r.leadId}`,className:"text-blue-600 dark:text-blue-400 hover:underline",children:[r.firstName," ",r.lastName]}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx("td",{className:"px-2 py-1.5 text-muted-foreground truncate max-w-[140px]",title:r.brandName??"",children:r.brandName??"â"}),e.jsx("td",{className:"px-2 py-1.5 font-mono text-[11px] text-muted-foreground",children:r.phone??"â"}),e.jsx("td",{className:"px-2 py-1.5 text-muted-foreground max-w-xs truncate",title:r.notes??"",children:r.notes??"â"})]},r.id))})]})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs text-muted-foreground uppercase mb-2 font-semibold",children:["Termine heute vereinbart (",n.length,")"]}),n.length===0?e.jsx("div",{className:"text-sm text-muted-foreground italic",children:"Heute noch keine Termine angelegt."}):e.jsx("div",{className:"border border-border rounded-md overflow-hidden",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-muted/50 text-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Termin-Datum"}),e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Status"}),e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Lead / Titel"}),e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Marke"}),e.jsx("th",{className:"text-left px-2 py-1.5 font-semibold",children:"Telefon"})]})}),e.jsx("tbody",{children:n.map(r=>e.jsxs("tr",{className:"border-t border-border hover:bg-muted/20",children:[e.jsxs("td",{className:"px-2 py-1.5 tabular-nums",children:[g(r.scheduledAt)," ",d(r.scheduledAt)]}),e.jsx("td",{className:"px-2 py-1.5 text-muted-foreground",children:r.status}),e.jsx("td",{className:"px-2 py-1.5",children:r.leadId?e.jsxs("a",{href:`/leads/${r.leadId}`,className:"text-blue-600 dark:text-blue-400 hover:underline",children:[r.firstName," ",r.lastName]}):e.jsx("span",{className:"text-muted-foreground italic",children:r.manualTitle??"manueller Termin"})}),e.jsx("td",{className:"px-2 py-1.5 text-muted-foreground truncate max-w-[140px]",title:r.brandName??"",children:r.brandName??"â"}),e.jsx("td",{className:"px-2 py-1.5 font-mono text-[11px] text-muted-foreground",children:r.phone??"â"})]},r.id))})]})}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-2",children:'ð¡ Hinweis: Wenn ein Vertriebler 0 âerreicht" hat aber Termine, hat er beim Anruf vergessen den âErreicht"-Button zu klicken. Termin-Daten sind unabhaengig.'})]})]})]})})}function oe(){const a=new Date,u=new Date(a.getFullYear(),a.getMonth(),1),h=new Date(a.getFullYear(),a.getMonth()+1,0,23,59,59,999);return{from:u.getTime(),to:h.getTime()}}function ge(a){const u=new Date(a),h=u.getFullYear(),c=String(u.getMonth()+1).padStart(2,"0"),p=String(u.getDate()).padStart(2,"0");return`${h}-${c}-${p}`}function Zt({brandId:a,dateFrom:u,dateTo:h}){const{data:c}=C.messagingAnalytics.summary.useQuery({brandId:a,dateFrom:u,dateTo:h},{staleTime:3e4}),p=c?.whatsapp;if(!p)return null;const m=Math.max(1,Math.round((h-u)/864e5)),n=m<=1?"heute":`letzte ${m} Tage`,j=[{label:"Gesendet",value:p.outbound??0,cls:"text-foreground"},{label:"Zugestellt",value:p.delivered??0,sub:`${p.deliveryRate??0}%`,cls:"text-emerald-500"},{label:"Gelesen",value:p.read??0,sub:`${p.readRate??0}%`,cls:"text-sky-500"},{label:"Antworten",value:p.inbound??0,sub:`Antwortrate ${p.replyRate??0}%`,cls:"text-amber-500"},{label:"Nicht zugestellt",value:p.failed??0,cls:"text-red-500"}];return e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"text-xs font-semibold text-muted-foreground mb-2",children:["ð¬ WhatsApp · ",n]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-5 gap-3",children:j.map(d=>e.jsxs("div",{className:"rounded-xl border border-border bg-card p-3",children:[e.jsx("div",{className:`text-xl font-black ${d.cls}`,children:d.value}),e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:[d.label,d.sub?` · ${d.sub}`:""]})]},d.label))}),e.jsx("div",{className:"text-[10.5px] text-muted-foreground mt-1.5",children:"Button-Klicks & Details pro Flow â in der Messaging-Analyse unten. (Link-Klicks liefert WhatsApp nicht.)"})]})}function rs(){const{user:a}=Me();return a?.role==="admin"?e.jsx(_t,{}):e.jsx(Ht,{})}function Ht(){const{user:a}=Me(),u=a?.role==="studio_team"||a?.role==="studio_owner",h=a?.role==="assistant",c=!1,p=!u&&!h,[m,n]=M.useState(void 0),j=M.useMemo(()=>
1oe(),[]),[d,g]=M.useState(j.from),[r,b]=M.useState(j.to),{data:N}=C.brands.list.useQuery(void 0,{staleTime:30*6e4,refetchOnWindowFocus:!1,refetchOnMount:!1}),t={refetchOnWindowFocus:!1,retry:1},{data:s,isLoading:i}=C.dashboard.kpis.useQuery({brandId:m,dateFrom:d,dateTo:r},{staleTime:2*6e4,...t}),{data:l}=C.dashboard.trends.useQuery({brandId:m,dateFrom:d,dateTo:r},{staleTime:2*6e4,...t}),{data:y=[]}=C.dashboard.leadSourceBreakdown.useQuery({brandId:m,dateFrom:d,dateTo:r},{staleTime:2*6e4,...t}),{data:w=[],isLoading:S}=C.studioStats.comparison.useQuery({dateFrom:d,dateTo:r},{enabled:c,staleTime:5*6e4,...t}),{data:v=[]}=C.analytics.getDailyActivity.useQuery({brandId:m,dateFrom:d,dateTo:r},{staleTime:5*6e4,...t}),P=new Date(d).toISOString().slice(0,10),D=new Date(r).toISOString().slice(0,10),{data:E}=C.ads.roi.useQuery({brandId:m,dateFrom:P,dateTo:D},{staleTime:12e4}),{data:R}=C.ads.studioOverview.useQuery({dateFrom:P,dateTo:D},{staleTime:12e4,enabled:!u}),x=r-d<2*864e5,f=x?"Heute":"Im Zeitraum",L=l?.leadsThisWeek??0,A=l?.apptsThisWeek??0,O=l?.contractsThisWeek??0,z=L+A+O;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Dashboard"}),s?.brandName&&e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:s.brandName})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx(F,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>{const o=new Date,k=new Date(o.getFullYear(),o.getMonth(),o.getDate()),T=new Date(o.getFullYear(),o.getMonth(),o.getDate(),23,59,59,999);g(k.getTime()),b(T.getTime())},children:"Heute"}),e.jsx(F,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>{const o=new Date,k=new Date(o.getFullYear(),o.getMonth(),o.getDate()-1),T=new Date(o.getFullYear(),o.getMonth(),o.getDate()-1,23,59,59,999);g(k.getTime()),b(T.getTime())},children:"Gestern"}),e.jsx(F,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>{const o=oe();g(o.from),b(o.to)},children:"Dieser Monat"}),e.jsx(F,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>{const o=new Date,k=new Date(o.getFullYear(),o.getMonth()-1,1),T=new Date(o.getFullYear(),o.getMonth(),0,23,59,59,999);g(k.getTime()),b(T.getTime())},children:"Letzter Monat"}),e.jsx(F,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>{g(0),b(Date.now())},children:"Gesamt"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(K,{type:"date",className:"h-8 text-xs w-36",value:ge(d),onChange:o=>g(new Date(o.target.value).getTime())}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"}),e.jsx(K,{type:"date",className:"h-8 text-xs w-36",value:ge(r),onChange:o=>b(new Date(o.target.value+"T23:59:59").getTime())})]}),e.jsxs(Qe,{value:m?.toString()??"all",onValueChange:o=>n(o==="all"?void 0:Number(o)),children:[e.jsxs(We,{className:"w-48 h-8",children:[e.jsx(Ee,{className:"h-3.5 w-3.5 mr-2 text-muted-foreground"}),e.jsx(_e,{placeholder:"Alle Marken"})]}),e.jsxs(Ge,{children:[e.jsx(me,{value:"all",children:"Alle Marken (kumuliert)"}),N?.map(o=>e.jsx(me,{value:o.id.toString(),children:o.name},o.id))]})]}),c]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:f}),e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-primary/10 text-primary text-xs font-semibold",children:[z," gesamt"]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[[{label:`Neue Leads ${x?"heute":"im Zeitraum"}`,value:L,icon:De,color:"text-blue-400",bg:"bg-blue-500/10 border-blue-500/20"},{label:`Termine ${x?"heute":"im Zeitraum"}`,value:A,icon:yt,color:"text-purple-400",bg:"bg-purple-500/10 border-purple-500/20"},{label:`Verträge ${x?"heute":"im Zeitraum"}`,value:O,icon:qe,color:"text-emerald-400",bg:"bg-emerald-500/10 border-emerald-500/20"}].map(({label:o,value:k,icon:T,color:$,bg:W})=>e.jsxs("div",{className:`rounded-xl border p-4 flex items-center gap-4 ${W}`,children:[e.jsx("div",{className:`p-2.5 rounded-lg bg-card/50 ${$}`,children:e.jsx(T,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:`text-3xl font-black ${$}`,children:k}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:o})]})]},o)),e.jsx(st,{brandId:m,dateFrom:d,dateTo:r})]})]}),c,e.jsx($t,{brandId:m??void 0}),p&&m!=null&&e.jsx(Rt,{brandId:m,defaultRange:"30d"}),e.jsx(Vt,{brandId:m}),e.jsx(Zt,{brandId:m,dateFrom:d,dateTo:r}),e.jsx(zt,{brandId:m,dateFrom:d,dateTo:r}),i?e.jsx("div",{className:"grid grid-cols-3 gap-4",children:Array.from({length:3}).map((o,k)=>e.jsx(V,{className:"bg-card border-border",children:e.jsx(I,{className:"p-5",children:e.jsx("div",{className:"h-8 bg-muted animate-pulse rounded"})})},k))}):e.jsxs(e.Fragment,{children:[l&&(()=>{const k=r-d<1728e5?"vs. Vortag":"vs. Vorperiode",T=l.leadsThisWeek>0?Math.round(l.contractsThisWeek/l.leadsThisWeek*100):0,$=[{label:"Neue Leads",curr:l.leadsThisWeek,delta:l.leadsDelta},{label:"Neue Verträge",curr:l.contractsThisWeek,delta:l.contractsDelta},{label:"Termine",curr:l.apptsThisWeek,delta:l.apptsDelta}];return e.jsxs("div",{className:"flex flex-wrap gap-3 items-center",children:[$.map(({label:W,curr:H,delta:G})=>e.jsxs("div",{className:"flex items-center gap-2 bg-card border border-border rounded-lg px-4 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[W," ",e.jsx("span",{className:"font-semibold text-foreground",children:H})," im Zeitraum"]}),G>0?e.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-green-400 font-medium",children:[e.jsx(ye,{className:"w-3 h-3"}),"+",G,"%"]}):G<0?e.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-red-400 font-medium",children:[e.jsx(ve,{className:"w-3 h-3"}),G,"%"]}):e.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-muted-foreground",children:[e.jsx(vt,{className:"w-3 h-3"}),"±0%"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:k})]},W)),e.jsxs("div",{className:"flex items-center gap-2 bg-card border border-amber-500/30 rounded-lg px-4 py-2",children:[e.jsx(kt,{className:"w-3 h-3 text-amber-400"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Lead â Vertrag"}),e.jsxs("span",{className:"font-semibold text-amber-400",children:[T,"%"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"im Zeitraum"})]})]})})(),e.jsx(rt,{kpis:s,showFinancials:p}),s&&e.jsxs(V,{className:"bg-card border-border",children:[e.jsx(B,{className:"pb-3",children:e.jsxs(Q,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(ue,{className:"h-4 w-4 text-primary"}),"Sales Funnel"]})}),e.jsxs(I,{className:"pb-4",children:[e.jsxs("div",{className:"flex items-stretch gap-0 overflow-x-auto pb-2",children:[[{label:"Leads",value:s.totalLeads,
1color:"bg-blue-500",textColor:"text-blue-400",sub:null},{label:"Termine",value:s.totalAppointments,color:"bg-violet-500",textColor:"text-violet-400",sub:`${s.totalLeads>0?Math.round(s.totalAppointments/s.totalLeads*100):0}% der Leads`},{label:"Shows",value:s.showedUpCount??0,color:"bg-amber-500",textColor:"text-amber-400",sub:`${s.totalAppointments>0?Math.round(s.showedUpCount/s.totalAppointments*100):0}% der Termine`},{label:"Verträge",value:s.totalContracts,color:"bg-emerald-500",textColor:"text-emerald-400",sub:`${s.showedUpCount>0?Math.round(s.appointmentContracts/s.showedUpCount*100):0}% der Shows`}].map((o,k,T)=>e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"flex flex-col items-center min-w-[90px] px-3 py-3 rounded-xl bg-muted/30 border border-border/50",children:[e.jsx("span",{className:`text-2xl font-bold ${o.textColor}`,children:o.value}),e.jsx("span",{className:"text-xs font-medium text-foreground mt-0.5",children:o.label}),o.sub&&e.jsx("span",{className:"text-[10px] text-muted-foreground mt-0.5",children:o.sub})]}),k<T.length-1&&e.jsx("div",{className:"flex flex-col items-center mx-1 text-muted-foreground",children:e.jsx("span",{className:"text-lg leading-none",children:"â"})})]},o.label)),e.jsx("div",{className:"mx-3 w-px bg-border self-stretch"}),e.jsxs("div",{className:"flex flex-col items-center min-w-[90px] px-3 py-3 rounded-xl bg-muted/30 border border-border/50",children:[e.jsx("span",{className:"text-2xl font-bold text-teal-400",children:s.directContracts??0}),e.jsx("span",{className:"text-xs font-medium text-foreground mt-0.5",children:"Direkt Vertrag"}),e.jsx("span",{className:"text-[10px] text-muted-foreground mt-0.5",children:"Online / Studio"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-3 pt-3 border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-orange-500/10 border border-orange-500/20 rounded-lg px-3 py-2",children:[e.jsx(Ye,{className:"w-3.5 h-3.5 text-orange-400"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-bold text-orange-400",children:s.openFeedbacks??0}),e.jsx("span",{className:"text-xs text-muted-foreground ml-1.5",children:"Offene Terminfeedbacks"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 bg-pink-500/10 border border-pink-500/20 rounded-lg px-3 py-2",children:[e.jsx(Re,{className:"w-3.5 h-3.5 text-pink-400"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-bold text-pink-400",children:s.friendsInvited??0}),e.jsx("span",{className:"text-xs text-muted-foreground ml-1.5",children:"Freunde eingeladen"})]}),e.jsx("span",{className:"text-muted-foreground/40",children:"·"}),e.jsx(wt,{className:"w-3.5 h-3.5 text-green-400"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-bold text-green-400",children:s.inviteBookings??0}),e.jsx("span",{className:"text-xs text-muted-foreground ml-1.5",children:"Akzeptiert"})]})]})]})]})]}),s&&s.totalLeads>0&&e.jsx(V,{children:e.jsxs(I,{className:"pt-4 pb-4",children:[e.jsxs("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[e.jsx(ue,{className:"w-3.5 h-3.5 text-primary"})," Lead-Conversion"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:(()=>{const o=s.totalLeads??0,k=s.totalAppointments??0,T=s.showedUpCount??0,$=s.totalContracts??0,W=s.appointmentContracts??0,H=o>0?Math.round($/o*100):0,G=o>0?Math.round(k/o*100):0,ie=k>0?Math.round(T/k*100):0,se=T>0?Math.round(W/T*100):0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Lead â Vertrag"}),e.jsxs("div",{className:`text-2xl font-black ${H>=20?"text-emerald-400":H>=10?"text-amber-400":"text-red-400"}`,children:[H,"%"]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:[$," / ",o]})]}),e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Lead â Termin"}),e.jsxs("div",{className:"text-xl font-bold text-cyan-400",children:[G,"%"]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:[k," / ",o]})]}),e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Termin â Show"}),e.jsxs("div",{className:"text-xl font-bold text-violet-400",children:[ie,"%"]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:[T," / ",k]})]}),e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Show â Vertrag"}),e.jsxs("div",{className:"text-xl font-bold text-emerald-400",children:[se,"%"]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:[W," / ",T]})]})]})})()})]})}),p&&E&&E.spend>0&&e.jsxs("div",{className:"rounded-xl p-4 grid grid-cols-1 sm:grid-cols-3 gap-4",style:{background:"rgba(59,130,246,0.06)",border:"1px solid rgba(59,130,246,0.18)"},children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-xs text-muted-foreground uppercase tracking-wider mb-1 flex items-center justify-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-blue-500 inline-block"}),"Ad-Budget"]}),e.jsxs("p",{className:"text-2xl font-bold text-foreground",children:["⬠",Number(E.spend).toLocaleStr
1ing("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"ausgegeben im Zeitraum"})]}),e.jsxs("div",{className:"text-center",style:{borderLeft:"1px solid rgba(59,130,246,0.15)",borderRight:"1px solid rgba(59,130,246,0.15)"},children:[e.jsxs("p",{className:"text-xs text-muted-foreground uppercase tracking-wider mb-1 flex items-center justify-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-blue-400 inline-block"}),"Kosten / Lead"]}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:E.costPerLead!=null?`⬠${Number(E.costPerLead).toLocaleString("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})}`:"â"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[E.adsLeadCount??0," Ads-Leads · ",E.leadCount??0," gesamt"]})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-xs text-muted-foreground uppercase tracking-wider mb-1 flex items-center justify-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-400 inline-block"}),"Kosten / Vertrag"]}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:E.costPerContract!=null?`⬠${Number(E.costPerContract).toLocaleString("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})}`:"â"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[E.contractCount??0," Verträge (alle Quellen)"]})]})]}),!u&&R&&R.length>0&&e.jsxs(V,{className:"bg-card border-border",children:[e.jsx(B,{className:"pb-2",children:e.jsxs(Q,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Ct,{className:"h-4 w-4 text-blue-400"}),"Meta Ads â Studio-Ãbersicht",e.jsx("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:"nur verbundene Studios"})]})}),e.jsx(I,{className:"p-0 pb-2",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left px-4 py-2",children:"Studio"}),e.jsx("th",{className:"text-right px-4 py-2",children:"Budget"}),e.jsx("th",{className:"text-right px-4 py-2",children:"Leads"}),e.jsx("th",{className:"text-right px-4 py-2",children:"Käufe"}),e.jsx("th",{className:"text-right px-4 py-2",children:"CTR"}),e.jsx("th",{className:"text-right px-4 py-2",children:"Klicks"})]})}),e.jsx("tbody",{children:R.map(o=>e.jsxs("tr",{className:"border-b border-border/50 hover:bg-muted/20 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium text-foreground",children:o.studioName}),e.jsxs("td",{className:"px-4 py-2.5 text-right tabular-nums text-foreground",children:["⬠",o.spend.toLocaleString("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})]}),e.jsx("td",{className:"px-4 py-2.5 text-right tabular-nums text-blue-400",children:o.leads}),e.jsx("td",{className:"px-4 py-2.5 text-right tabular-nums text-green-400",children:o.contracts}),e.jsxs("td",{className:"px-4 py-2.5 text-right tabular-nums text-muted-foreground",children:[o.ctr.toFixed(2)," %"]}),e.jsx("td",{className:"px-4 py-2.5 text-right tabular-nums text-muted-foreground",children:o.clicks.toLocaleString("de-DE")})]},o.brandId))})]})})})]}),e.jsxs(V,{className:"bg-card border-border",children:[e.jsx(B,{className:"pb-2",children:e.jsxs(Q,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Ze,{className:"h-4 w-4 text-primary"}),"Tägliche Aktivität",e.jsx("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:"Leads · Termine · Verträge"})]})}),e.jsx(I,{className:"pb-3",children:v.length===0?e.jsx("div",{className:"h-48 flex items-center justify-center text-xs text-muted-foreground",children:"Keine Daten im gewählten Zeitraum"}):e.jsx(he,{width:"100%",height:210,children:e.jsxs(Se,{data:v,barCategoryGap:"30%",margin:{top:4,right:4,left:-20,bottom:0},children:[e.jsx(Le,{strokeDasharray:"3 3",stroke:"rgba(255,255,255,0.04)"}),e.jsx($e,{dataKey:"date",tick:{fontSize:10,fill:"rgba(255,255,255,0.35)"},tickFormatter:o=>{const[,k,T]=o.split("-");return`${T}.${k}`},interval:"preserveStartEnd"}),e.jsx(Fe,{tick:{fontSize:10,fill:"rgba(255,255,255,0.35)"},allowDecimals:!1}),e.jsx(pe,{contentStyle:{background:"#1a1a1a",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"8px",fontSize:"12px"},labelFormatter:o=>{const[k,T,$]=o.split("-");return`${$}.${T}.${k}`},formatter:(o,k)=>[o,k==="leads"?"Leads":k==="appointments"?"Termine":"Verträge"]}),e.jsx(Ae,{formatter:o=>o==="leads"?"Leads":o==="appointments"?"Termine":"Verträge",wrapperStyle:{fontSize:"11px"}}),e.jsx(ee,{dataKey:"leads",fill:"#3b82f6",radius:[2,2,0,0]}
1),e.jsx(ee,{dataKey:"appointments",fill:"#a855f7",radius:[2,2,0,0]}),e.jsx(ee,{dataKey:"contracts",fill:"#22c55e",radius:[2,2,0,0]})]})})})]}),y.length>0&&e.jsxs(V,{className:"bg-card border-border",children:[e.jsx(B,{className:"pb-2",children:e.jsxs(Q,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(De,{className:"h-4 w-4 text-blue-400"}),"Leads nach Quelle â Funnel",e.jsx("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:"Leads â Termine â Shows â Verträge"})]})}),e.jsx(I,{className:"p-0 pb-2",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Quelle"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"Leads"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"Termine"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium text-green-400/80",children:"Shows"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"LâT"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"TâShow"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium text-emerald-400",children:"Verträge"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium text-emerald-400",children:"Close-Rate"})]})}),e.jsx("tbody",{children:y.map(o=>{const k=at[o.source]??o.source??"Unbekannt",T=Number(o.leadCount),$=Number(o.appointmentCount),W=Number(o.showCount??0),H=Number(o.contractCount),G=T>0?Math.round($/T*100):0,ie=$>0?Math.round(W/$*100):0,se=T>0?Math.round(H/T*100):0,Pe=ze=>ze>=25?"text-green-400":ze>=10?"text-yellow-400":"text-muted-foreground";return e.jsxs("tr",{className:"border-b border-border/40 hover:bg-muted/20",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium",children:k}),e.jsx("td",{className:"px-3 py-2.5 text-right text-blue-400 font-semibold",children:T}),e.jsx("td",{className:"px-3 py-2.5 text-right text-purple-400",children:$}),e.jsx("td",{className:"px-3 py-2.5 text-right text-green-400",children:W}),e.jsxs("td",{className:`px-3 py-2.5 text-right text-xs ${Pe(G)}`,children:[G,"%"]}),e.jsxs("td",{className:`px-3 py-2.5 text-right text-xs ${Pe(ie)}`,children:[ie,"%"]}),e.jsx("td",{className:"px-3 py-2.5 text-right text-emerald-400 font-bold",children:H}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:e.jsxs("span",{className:`text-xs font-semibold px-2 py-0.5 rounded-full ${se>=20?"bg-emerald-500/20 text-emerald-400":se>=8?"bg-amber-500/20 text-amber-400":"bg-muted text-muted-foreground"}`,children:[se,"%"]})})]},o.source??"null")})}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"border-t border-border bg-muted/10 font-semibold text-xs",children:[e.jsx("td",{className:"px-4 py-2 text-muted-foreground",children:"Gesamt"}),e.jsx("td",{className:"px-3 py-2 text-right text-blue-400",children:y.reduce((o,k)=>o+Number(k.leadCount),0)}),e.jsx("td",{className:"px-3 py-2 text-right text-purple-400",children:y.reduce((o,k)=>o+Number(k.appointmentCount),0)}),e.jsx("td",{className:"px-3 py-2 text-right text-green-400",children:y.reduce((o,k)=>o+Number(k.showCount??0),0)}),e.jsx("td",{className:"px-3 py-2 text-right text-muted-foreground",children:(()=>{const o=y.reduce((T,$)=>T+Number($.leadCount),0),k=y.reduce((T,$)=>T+Number($.appointmentCount),0);return o>0?`${Math.round(k/o*100)}%`:"â"})()}),e.jsx("td",{className:"px-3 py-2 text-right text-muted-foreground",children:(()=>{const o=y.reduce((T,$)=>T+Number($.appointmentCount),0),k=y.reduce((T,$)=>T+Number($.showCount??0),0);return o>0?`${Math.round(k/o*100)}%`:"â"})()}),e.jsx("td",{className:"px-3 py-2 text-right text-emerald-400",children:y.reduce((o,k)=>o+Number(k.contractCount),0)}),e.jsx("td",{className:"px-4 py-2 text-right text-muted-foreground",children:(()=>{const o=y.reduce((T,$)=>T+Number($.leadCount),0),k=y.reduce((T,$)=>T+Number($.contractCount),0);return o>0?`${Math.round(k/o*100)}%`:"â"})()})]})})]})})})]})]})]})}export{rs 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.