1import{r as o,j as e}from"./framer-motion-CQxuJa5n.js";import{u as Y,s as a,an as v,t as Z,S as g,ak as u,U as c,ao as ee,P as te,p as se,B as ae,c as re,C as i,i as n,T as le,v as ie,f as d,g as m,h as N,H as y,w as ne}from"./index-CSx7K-7R.js";import{B as w}from"./badge-Yar_qzGV.js";import{C as oe}from"./crown-BJhum9o3.js";import{G as ce}from"./globe-B3q7zUSQ.js";import{C as de}from"./chevron-left-DeVGDa0x.js";import{P as p}from"./phone-DfeYL_-y.js";import{F as me}from"./file-text-CQNieni0.js";import{M as k}from"./mail-CQVr-2Yp.js";import{A as xe}from"./arrow-right-Q4CCUTFT.js";import"./recharts-CFjfazL9.js";function _e(){const h=Y(),[s,_]=o.useState(null),[S,L]=o.useState(!0),[f,C]=o.useState([]);o.useEffect(()=>{A()},[]);const A=async()=>{try{const[t,T,O,M,P,D,q,E,B]=await Promise.all([a.from("user_roles").select("*",{count:"exact",head:!0}).eq("role","admin"),a.from("seller_users").select("*",{count:"exact",head:!0}),a.from("seller_users").select("*",{count:"exact",head:!0}).eq("is_active",!0),a.from("voice_agent_leads").select("*",{count:"exact",head:!0}),a.from("voice_agent_leads").select("*",{count:"exact",head:!0}).eq("status","won"),a.from("voice_agents").select("*",{count:"exact",head:!0}).eq("is_deleted",!1),a.from("calculator_offers").select("*",{count:"exact",head:!0}),a.from("calculator_offers").select("*",{count:"exact",head:!0}).eq("status","signed"),a.from("seller_activities").select("*, seller_users(name)").order("created_at",{ascending:!1}).limit(10)]),j=(r,x)=>{if(r.error&&!v(r.error))throw r.error;return r.data??x},l=r=>{if(r.error&&!v(r.error))throw r.error;return r.count||0},V=l(t),F=l(T),K=l(O),U=l(M),G=l(P),H=l(D),I=l(q),$=l(E),z=j(B,[]),J=await a.from("calculator_offers").select("monthly_price").in("status",["sent","viewed"]),Q=j(J,[])?.reduce((r,x)=>r+(x.monthly_price||0),0)||0,b=new Date().toISOString().split("T")[0],W=await a.from("seller_activities").select("*",{count:"exact",head:!0}).eq("activity_type","call").gte("created_at",b),X=await a.from("seller_activities").select("*",{count:"exact",head:!0}).eq("activity_type","email").gte("created_at",b);_({totalAdmins:V||0,totalSellers:F||0,activeSellers:K||0,totalLeads:U||0,wonLeads:G||0,totalVoiceAgents:H||0,totalOffers:I||0,signedOffers:$||0,pipelineValue:Q,emailsSentToday:l(X),callsToday:l(W)}),C(z||[])}catch(t){console.error("Error loading stats:",t),Z.error("Kunne ikke hente statistik")}finally{L(!1)}},R=[{title:"System Status",description:"Live fejlovervÃ¥gning, agent sundhed, fejllog pÃ¥ tværs af alle agenter",icon:g,href:"/admin/status",color:"bg-orange-500/10 text-orange-500",stat:null,statLabel:null},{title:"Kontrolcenter",description:"Fuld oversigt: brugere, forbrug, fakturering og betalinger",icon:g,href:"/admin/kontrol",color:"bg-red-500/10 text-red-500",stat:null,statLabel:null},{title:"Ãkonomi & Profit",description:"Live MRR, margin pr. partner, profit pr. agent, cost breakdown",icon:u,href:"/admin/okonomi",color:"bg-emerald-500/10 text-emerald-500",stat:null,statLabel:null},{title:"Analytics",description:"Fuldt overblik: samtaler, forbrug pr. agent, Twilio/OpenAI/ElevenLabs omkostninger",icon:u,href:"/admin/analytics",color:"bg-blue-500/10 text-blue-500",stat:null,statLabel:null},{title:"Team Management",description:"Opret brugere, se aktivitet og kommuniker med dit team",icon:c,href:"/admin/team",color:"bg-emerald-500/10 text-emerald-500",stat:(s?.totalAdmins||0)+(s?.totalSellers||0),statLabel:"teammedlemmer"},{title:"Admin Brugere",description:"Opret og administrer admin konti med fuld adgang",icon:oe,href:"/admin/brugere",color:"bg-purple-500/10 text-purple-500",stat:s?.totalAdmins||0,statLabel:"admins"},{title:"Sælger-administration",description:"Administrer sælgere, provision og særaftaler",icon:c,href:"/admin/saelgere",color:"bg-blue-500/10 text-blue-500",stat:s?.activeSellers||0,statLabel:"aktive sælgere"},{title:"Partner-administration",description:"Se alle partnere, deres kunder og oprettede agenter",icon:c,href:"/admin/partnere",color:"bg-teal-500/10 text-teal-500",stat:null,statLabel:null},{title:"Salgs-oversigt",description:"Se alle sælgeres aktivitet, emails og performance",icon:u,href:"/admin/salgs-oversigt",color:"bg-green-500/10 text-green-500",stat:s?.wonLeads||0,statLabel:"vundne deals"},{title:"Pro Sitemap Builder",description:"Automatisk opdagelse af alle indexerbare sider og sitemap-generering",icon:ce,href:"/admin/sitemap-builder",color:"bg-cyan-500/10 text-cyan-500",stat:null,statLabel:null}
1,{title:"Klik-tracking",description:"Detaljeret tracking af demo-flows og engagement",icon:ee,href:"/admin/klik-tracking",color:"bg-orange-500/10 text-orange-500",stat:null,statLabel:null},{title:"Demo â Note / SMS / BG",description:"Antal demoer, scannede URLâer, note, telefon/SMS og baggrund",icon:te,href:"/admin/demo-requests",color:"bg-sky-500/10 text-sky-500",stat:null,statLabel:null}];return S?e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx(se,{className:"h-8 w-8 animate-spin"})}):e.jsx("div",{className:"min-h-screen bg-background p-6",children:e.jsxs("div",{className:"max-w-7xl mx-auto space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(ae,{variant:"outline",size:"sm",onClick:()=>h("/dashboard"),children:[e.jsx(de,{className:"h-4 w-4 mr-1"}),"Dashboard"]}),e.jsx("img",{src:re,alt:"Agento",className:"h-10 w-auto"}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(g,{className:"h-6 w-6 text-primary"}),"Admin Kontrolcenter"]}),e.jsx("p",{className:"text-muted-foreground",children:"Styr hele platformen fra ét sted"})]})]})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4",children:[e.jsx(i,{children:e.jsxs(n,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(p,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Voice Agents"})]}),e.jsx("div",{className:"text-2xl font-bold",children:s?.totalVoiceAgents})]})}),e.jsx(i,{children:e.jsxs(n,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(c,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Total Leads"})]}),e.jsx("div",{className:"text-2xl font-bold",children:s?.totalLeads})]})}),e.jsx(i,{children:e.jsxs(n,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(le,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Vundne"})]}),e.jsx("div",{className:"text-2xl font-bold text-green-500",children:s?.wonLeads})]})}),e.jsx(i,{children:e.jsxs(n,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(ie,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Pipeline"})]}),e.jsxs("div",{className:"text-2xl font-bold",children:[((s?.pipelineValue||0)/1e3).toFixed(0),"k"]})]})}),e.jsx(i,{children:e.jsxs(n,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(me,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Tilbud"})]}),e.jsxs("div",{className:"text-2xl font-bold",children:[s?.signedOffers,"/",s?.totalOffers]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs(i,{className:"border-primary/20",children:[e.jsx(d,{className:"pb-2",children:e.jsxs(m,{className:"text-sm flex items-center gap-2",children:[e.jsx(k,{className:"h-4 w-4 text-primary"}),"Emails sendt i dag"]})}),e.jsx(n,{children:e.jsx("div",{className:"text-4xl font-bold",children:s?.emailsSentToday})})]}),e.jsxs(i,{className:"border-primary/20",children:[e.jsx(d,{className:"pb-2",children:e.jsxs(m,{className:"text-sm flex items-center gap-2",children:[e.jsx(p,{className:"h-4 w-4 text-primary"}),"Opkald i dag"]})}),e.jsx(n,{children:e.jsx("div",{className:"text-4xl font-bold",children:s?.callsToday})})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:R.map(t=>e.jsx(i,{className:"cursor-pointer hover:border-primary/50 transition-colors group",onClick:()=>h(t.href),children:e.jsxs(d,{children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("div",{className:`p-3 rounded-lg ${t.color}`,children:e.jsx(t.icon,{className:"h-6 w-6"})}),t.stat!==null&&e.jsxs(w,{variant:"secondary",className:"text-lg px-3",children:[t.stat," ",t.statLabel]})]}),e.jsxs(m,{className:"flex items-center gap-2 group-hover:text-primary transition-colors",children:[t.title,e.jsx(xe,{className:"h-4 w-4 opacity-0 group-hover:opacity-100 transition-opacity"})]}),e.jsx(N,{children:t.description})]})},t.href))}),e.jsxs(i,{children:[e.jsxs(d,{children:[e.jsxs(m,{className:"flex items-center gap-2",children:[e.jsx(y,{className:"h-5 w-5"}),"Seneste aktivitet"]}),e.jsx(N,{children:"Live feed fra alle sælgere"})]}),e.jsx(n,{children:f.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Ingen aktivitet endnu"}):e.jsx("div",{className:"space-y-3",children:f.map(t=>e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg bg-muted/50",children:[e.jsx("div",{className:`p-2 rounded-lg ${t.activity_type==="call"?"bg-green-500/10 text-green-500":t.activity_type==="email"?"bg-blue-500/10 text-blue-500":t.activity_type==="meeting"?"bg-purple-500/10 text-purple-500":"bg-muted text-muted-foreground"}`,children:t.activity_type==="call"?e.jsx(p,{className:"h-4 w-4"}):t.activity_type==="email"?e.jsx(k,{className:"h-4 w-4"}):t.activity_type==="meeting"?e.jsx(ne,{className:"h-4 w-4"}):e.jsx(y,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:t.title}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[t.seller_users?.name||"Ukendt"," ⢠",new Date(t.created_at).toLocaleTimeString("da-DK",{hour:"2-digit",minute:"2-digit"})]})]}),e.jsx(w,{variant:"outline",className:"shrink-0",children:t.activity_type==="call"?"Opkald":t.activity_type==="email"?"Email":t.activity_type==="meeting"?"Møde":t.activity_type})]},t.id))})})]})]})})}export{_e as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.