1import{j as e}from"./ui-B-jAfBIu.js";import{e as O,r as x}from"./vendor-DFDkvaNg.js";import{B as b,X as f,A as ee,b as N,F as W,U,s as h,a6 as D,y as se,I as te,af as re}from"./index-BCsAUAr3.js";import{C as o,a as $,b as G,d as Q,c as d}from"./card-FDTNR4GW.js";import{B as g}from"./badge-Dm4sUQsj.js";import{C as ae}from"./circle-check-D03ZvCsy.js";import{A as ne,a as ie}from"./avatar-CP7FeTX_.js";import{P as B}from"./plus-BIp8B92L.js";import{T as le}from"./trending-up-CU3hskiL.js";import{C as ce}from"./clock-tUlmfkpA.js";import{T}from"./target-B9xH42XD.js";import{S as q}from"./search-EEELfpZ7.js";import"./supabase-DM3UDwCf.js";import"./query-BNFXhbss.js";const oe=[{id:1,title:"Erste Firma anlegen",description:"Erstellen Sie einen Showroom für Ihren ersten Kunden",icon:N,action:"/admin/showroom/companies/new",actionLabel:"Firma anlegen",color:"text-blue-600 bg-blue-50 dark:bg-blue-950"},{id:2,title:"Dokumente hochladen",description:"Laden Sie Templates hoch oder weisen Sie Dokumente zu",icon:W,action:"/admin/showroom/templates",actionLabel:"Templates verwalten",color:"text-green-600 bg-green-50 dark:bg-green-950"},{id:3,title:"Kunden einladen",description:"Fügen Sie Teammitglieder zur Firma hinzu",icon:U,action:null,actionLabel:"In Firma â Team Tab",color:"text-purple-600 bg-purple-50 dark:bg-purple-950"}];function de({onDismiss:m}){const S=O(),[C,j]=x.useState(!1);if(C)return null;const _=()=>{j(!0),m==null||m()};return e.jsxs(o,{className:"border-2 border-primary/20 bg-gradient-to-br from-primary/5 to-background",children:[e.jsx($,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(G,{className:"text-xl",children:"Willkommen im DGF Showroom Admin!"}),e.jsx(g,{variant:"secondary",className:"text-xs",children:"Quick Start"})]}),e.jsx(Q,{children:"Folgen Sie diesen Schritten, um Ihren ersten Kunden einzurichten"})]}),e.jsx(b,{variant:"ghost",size:"icon",onClick:_,className:"h-8 w-8",children:e.jsx(f,{className:"h-4 w-4"})})]})}),e.jsxs(d,{children:[e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:oe.map(n=>{const v=n.icon;return e.jsx(o,{className:"hover:shadow-md transition-shadow",children:e.jsxs(d,{className:"pt-6",children:[e.jsx("div",{className:`h-12 w-12 rounded-lg ${n.color} flex items-center justify-center mb-4`,children:e.jsx(v,{className:"h-6 w-6"})}),e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsxs(g,{variant:"outline",className:"text-xs",children:["Schritt ",n.id]})}),e.jsx("h3",{className:"font-semibold mb-1",children:n.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n.description})]}),n.action?e.jsxs(b,{onClick:()=>S(n.action),variant:"outline",className:"w-full",size:"sm",children:[n.actionLabel,e.jsx(ee,{className:"h-4 w-4 ml-2"})]}):e.jsx("div",{className:"text-xs text-muted-foreground bg-muted/50 p-2 rounded text-center",children:n.actionLabel})]})},n.id)})}),e.jsx("div",{className:"mt-6 p-4 bg-muted/30 rounded-lg border",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0",children:e.jsx(ae,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium mb-1",children:"Tipp für Fortgeschrittene"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nutzen Sie die Template-Verwaltung, um Standarddokumente mehreren Firmen gleichzeitig zuzuweisen. So sparen Sie Zeit bei wiederkehrenden Dokumenten."})]})]})})]})]})}function Se(){const m=O(),[S,C]=x.useState(!0),[j,_]=x.useState([]),[n,v]=x.useState(""),[l,F]=x.useState({search:[],status:[],industries:[]}),[V,Z]=x.useState(!1),[H,I]=x.useState(!1),[R,w]=x.useState(!1),[k,X]=x.useState({totalCustomers:0,newCustomers:0,openDocuments:0,completedPhasesThisWeek:0});x.useEffect(()=>{J()},[]);const J=async()=>{try{const{data:{session:s}}=await h.auth.getSession();if(!s){m("/auth");return}const{data:t}=await h.from("user_roles").select("role").eq("user_id",s.user.id);if(!(t==null?void 0:t.some(r=>r.role==="admin"||r.role==="user"))){D.error("Kein Zugriff auf Admin-Bereich"),m("/");return}Z((t==null?void 0:t.some(r=>r.role==="admin"))||!1),await K()}catch(s){console.error("Access check error:",s),D.error("Zugriffsfehler"),m("/")}},K=async()=>{try{const{data:s,error:t}=await h.from("showroom_companies").select("*").order("created_at",{ascending:!1});if(t)throw t;const i=await Promise.all((s||[]).map(async r=>{const{count:a}=await h.from("showroom_company_users").select("*",{count:"exact",head:!0}).eq("company_id",r.id),{count:u}=await h.from("showroom_company_documents").select("*",{count:"exact",head:!0}).eq("company_id",r.id),{data:c}=await h.from("showroom_project_phases").select("phase_name").eq("company_id",r.id).eq("status","in_progress").order("phase_order").limit(1);return{...r,customer_count:a||0,document_count:u||0,active_phase:c&&c.length>0?c[0].phase_name:null}}));_(i),I(i.length===0),await M()}catch(s){console.error("Error loading companies:",s),D.error("Fehler beim Laden der Firmen")}finally{C(!1)}},M=async()=>{try{const{count:s}=await h.from("user_roles").select("*",{count:"exact",head:!0}).eq("role","client"),t=new Date;t.setDate(t.getDate()-7);const{count:i}=await h.from("showroom_company_users").select("*",{count:"exact",head:!0}).gte("joined_at",t.toISOString()),{count:r}=await h.from("showroom_company_documents").select("*",{count:"exact",head:!0}).eq("require_signature",!0).is("signed_at",null),a=new Date;a.setDate(a.getDate()-a.getDay());const{count:u}=await h.from("showroom_project_phases").select("*",{count:"exact",head:!0}).eq("status","completed").gte("updated_at",a.toISOString());X({totalCustomers:s||0,newCustomers:i||0,openDocuments:r||0,completedPhasesThisWeek:u||0})}catch(s){console.error("Error loading KPI stats:",s)}},z=s=>{const t=s.toLowerCase().trim(),i={aktiv:"active",active:"active",abgeschlossen:"completed",completed:"completed",pausiert:"paused",paused:"paused"},r={immobilien:"Immobilien",bau:"Bau",energie:"Energie",handel:"Handel",industrie:"Industrie",tech:"Technologie",technologie:"Technologie"},a={search:[],status:[],industries:[]};t.split(/\s+/).filter(c=>c.length>
10).forEach(c=>{if(i[c]){const p=i[c];a.status.includes(p)||a.status.push(p)}else if(r[c]){const p=r[c];a.industries.includes(p)||a.industries.push(p)}else c.length>1&&a.search.push(c)}),F(a)},P=j.filter(s=>{const t=l.search.length===0||l.search.every(a=>{var u;return s.name.toLowerCase().includes(a)||((u=s.industry)==null?void 0:u.toLowerCase().includes(a))}),i=l.status.length===0||l.status.includes(s.status),r=l.industries.length===0||l.industries.some(a=>{var u;return(u=s.industry)==null?void 0:u.includes(a)});return t&&i&&r}),A=(s,t)=>{F(i=>({...i,[s]:i[s].filter(r=>r!==t)}))},L=()=>{v(""),F({search:[],status:[],industries:[]})},y=l.search.length>0||l.status.length>0||l.industries.length>0;Array.from(new Set(j.map(s=>s.industry).filter(Boolean)));const Y=s=>{switch(s){case"active":return"bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/20";case"completed":return"bg-blue-500/10 text-blue-700 dark:text-blue-400 border-blue-500/20";case"paused":return"bg-gray-500/10 text-gray-700 dark:text-gray-400 border-gray-500/20";default:return"bg-muted"}},E=s=>{switch(s){case"active":return"Aktiv";case"completed":return"Abgeschlossen";case"paused":return"Pausiert";default:return s}};return S?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Lade Dashboard..."})]})}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("div",{className:"border-b bg-gradient-to-r from-primary/5 via-primary/10 to-primary/5",children:e.jsxs("div",{className:"container mx-auto px-6 py-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-bold mb-2",children:"Sales Dashboard"}),e.jsx("p",{className:"text-muted-foreground text-lg",children:"Willkommen zurück! Verwalten Sie Ihre Kunden und Firmen"})]}),e.jsxs(b,{size:"lg",onClick:()=>w(!0),className:"shadow-lg",children:[e.jsx(B,{className:"h-5 w-5 mr-2"}),"Kunde hinzufügen"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(o,{className:"border-2",children:e.jsx(d,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Aktive Kunden"}),e.jsx("p",{className:"text-3xl font-bold mt-2",children:k.totalCustomers})]}),e.jsx("div",{className:"h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(U,{className:"h-6 w-6 text-primary"})})]})})}),e.jsx(o,{className:"border-2",children:e.jsx(d,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Neue Kunden (7 Tage)"}),e.jsx("p",{className:"text-3xl font-bold mt-2",children:k.newCustomers})]}),e.jsx("div",{className:"h-12 w-12 rounded-full bg-green-500/10 flex items-center justify-center",children:e.jsx(le,{className:"h-6 w-6 text-green-600"})})]})})}),e.jsx(o,{className:"border-2",children:e.jsx(d,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Offene Dokumente"}),e.jsx("p",{className:"text-3xl font-bold mt-2",children:k.openDocuments})]}),e.jsx("div",{className:"h-12 w-12 rounded-full bg-orange-500/10 flex items-center justify-center",children:e.jsx(ce,{className:"h-6 w-6 text-orange-600"})})]})})}),e.jsx(o,{className:"border-2",children:e.jsx(d,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Phasen abgeschlossen"}),e.jsx("p",{className:"text-3xl font-bold mt-2",children:k.completedPhasesThisWeek})]}),e.jsx("div",{className:"h-12 w-12 rounded-full bg-blue-500/10 flex items-center justify-center",children:e.jsx(T,{className:"h-6 w-6 text-blue-600"})})]})})})]})]})}),e.jsxs("div",{className:"container mx-auto px-6 py-8",children:[H&&j.length===0&&e.jsx("div",{className:"mb-8",children:e.jsx(de,{onDismiss:()=>I(!1)})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-8",children:[e.jsx(o,{className:"cursor-pointer hover:shadow-lg transition-all border-2 border-primary/20",onClick:()=>w(!0),children:e.jsx(d,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-14 w-14 roun
1ded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(se,{className:"h-7 w-7 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-lg",children:"Kunde hinzufügen"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Neuer Kunde oder Firma"})]})]})})}),e.jsx(o,{className:"cursor-pointer hover:shadow-lg transition-all",onClick:()=>m("/admin/showroom/companies/new"),children:e.jsx(d,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-14 w-14 rounded-lg bg-blue-500/10 flex items-center justify-center",children:e.jsx(N,{className:"h-7 w-7 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-lg",children:"Neue Firma"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Firma ohne Kunde anlegen"})]})]})})}),V&&e.jsx(o,{className:"cursor-pointer hover:shadow-lg transition-all",onClick:()=>m("/admin/showroom/templates"),children:e.jsx(d,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-14 w-14 rounded-lg bg-purple-500/10 flex items-center justify-center",children:e.jsx(W,{className:"h-7 w-7 text-purple-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-lg",children:"Template hochladen"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Dokument-Vorlage erstellen"})]})]})})})]}),e.jsx(o,{className:"mb-6",children:e.jsxs(d,{className:"p-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(q,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-muted-foreground"}),e.jsx(te,{placeholder:"Suchen: Firmenname, Status (aktiv, pausiert), Branche (Immobilien, Bau)...",value:n,onChange:s=>{v(s.target.value),z(s.target.value)},onKeyDown:s=>{s.key==="Enter"&&z(n)},className:"pl-10 pr-10 h-12 text-base"}),n&&e.jsx("button",{onClick:L,className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(f,{className:"h-4 w-4"})})]}),y&&e.jsxs("div",{className:"flex flex-wrap gap-2 mt-4 pt-4 border-t",children:[l.search.map(s=>e.jsxs(g,{variant:"secondary",className:"px-3 py-1 text-sm flex items-center gap-2",children:[e.jsx(q,{className:"h-3 w-3"}),s,e.jsx("button",{onClick:()=>A("search",s),className:"hover:text-destructive transition-colors",children:e.jsx(f,{className:"h-3 w-3"})})]},`search-${s}`)),l.status.map(s=>e.jsxs(g,{className:"px-3 py-1 text-sm flex items-center gap-2 bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/20",children:[e.jsx(T,{className:"h-3 w-3"}),E(s),e.jsx("button",{onClick:()=>A("status",s),className:"hover:text-destructive transition-colors",children:e.jsx(f,{className:"h-3 w-3"})})]},`status-${s}`)),l.industries.map(s=>e.jsxs(g,{className:"px-3 py-1 text-sm flex items-center gap-2 bg-blue-500/10 text-blue-700 dark:text-blue-400 border-blue-500/20",children:[e.jsx(N,{className:"h-3 w-3"}),s,e.jsx("button",{onClick:()=>A("industries",s),className:"hover:text-destructive transition-colors",children:e.jsx(f,{className:"h-3 w-3"})})]},`industry-${s}`)),e.jsx(b,{variant:"ghost",size:"sm",onClick:L,className:"text-xs text-muted-foreground hover:text-foreground",children:"Alle Filter löschen"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:[e.jsx("strong",{children:"Tipp:"}),' Gib "aktiv immobilien" ein für aktive Immobilienfirmen, oder "dgf abgeschlossen" für abgeschlossene Projekte mit "DGF" im Namen']})]})}),P.length===0?e.jsx(o,{children:e.jsxs(d,{className:"text-center py-12",children:[e.jsx(N,{className:"h-16 w-16 mx-auto mb-4 text-muted-foreground opacity-50"}),e.jsx("p",{className:"text-lg font-medium mb-2",children:y?"Keine Firmen gefunden":"Noch keine Firmen erstellt"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:y?"Versuchen Sie einen anderen Suchbegriff oder Filter":"Erstellen Sie Ihre erste Firma, um zu beginnen"}),!y&&e.jsxs(b,{onClick:()=>w(!0),children:[e.jsx(B,{className:"h-4 w-4 mr-2"}),"Kunde hinzufügen"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:P.map(s=>e.jsxs(o,{className:"cursor-pointer hover:shadow-lg hover:scale-[1.02] transition-all border-2",onClick:()=>m(`/admin/showroom/companies/${s.id}`),children:[e.jsxs($,{children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[s.logo_url?e.jsxs(ne,{className:"h-14 w-14 roun
1ded-lg",children:[e.jsx("img",{src:s.logo_url,alt:s.name,className:"object-contain"}),e.jsx(ie,{className:"rounded-lg",children:s.name.substring(0,2).toUpperCase()})]}):e.jsx("div",{className:"h-14 w-14 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(N,{className:"h-7 w-7 text-primary"})}),e.jsx(g,{variant:"outline",className:Y(s.status),children:E(s.status)})]}),e.jsx(G,{className:"text-xl mb-2 line-clamp-1",children:s.name}),s.industry&&e.jsx(Q,{className:"text-sm",children:s.industry})]}),e.jsxs(d,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-4 pb-4 border-b",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-primary",children:s.customer_count||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Kunden"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:s.document_count||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Dokumente"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-green-600",children:s.active_phase?"â":"â"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Phase"})]})]}),s.active_phase&&e.jsxs("div",{className:"flex items-center gap-2 text-sm mb-2",children:[e.jsx(T,{className:"h-4 w-4 text-green-600"}),e.jsx("span",{className:"text-muted-foreground",children:"Aktive Phase:"}),e.jsx("span",{className:"font-medium",children:s.active_phase})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Erstellt: ",new Date(s.created_at).toLocaleDateString("de-DE")]})]})]},s.id))})]}),e.jsx(re,{open:R,onOpenChange:w,onSuccess:()=>{K()}})]})}export{Se 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.