1import{b as S,aU as C,r as q,a as m,s as d,j as e,n as x,o as u,p as h,N as f,v as V,w as A,x as F,y as z,z as p,q as K,F as $,aC as k,ao as B,d as j,aE as D,B as L}from"./index-DH-BokCi.js";import{F as E}from"./footprints-B7OUcHMf.js";import{P as M}from"./phone-BSjYJulZ.js";import{R as P}from"./ruler-Oz6tAZRu.js";function H(){const{user:a,roles:_}=S(),g=C(),[l,N]=q.useState("__all__"),i=_.includes("door2door_scout"),b=m({queryKey:["scout-my-vertriebler",a==null?void 0:a.id],enabled:!!(a!=null&&a.id)&&i,queryFn:async()=>{const{data:s}=await d.from("d2d_scout_assignments").select("vertriebler_id").eq("scout_id",a.id),t=(s||[]).map(w=>w.vertriebler_id);if(!t.length)return[];const{data:n}=await d.from("profiles").select("id, full_name, email").in("id",t).order("full_name");return n||[]}}),c=m({queryKey:["scout-vertriebler-customers",a==null?void 0:a.id,l],enabled:!!(a!=null&&a.id)&&i,queryFn:async()=>{let s=d.from("customers").select("id, first_name, last_name, email, phone, street, city, postal_code, status, lead_status, assigned_to, created_at").eq("status","lead").order("created_at",{ascending:!1});l!=="__all__"&&(s=s.eq("assigned_to",l));const{data:t}=await s;return t||[]}});if(!i)return e.jsx("div",{className:"p-6",children:e.jsx(x,{children:e.jsxs(u,{children:[e.jsx(h,{children:"Kein Zugriff"}),e.jsx(f,{children:"Dieser Bereich ist nur für D2D-Scouts verfügbar."})]})})});const r=b.data||[],o=c.data||[],v=s=>{s.assigned_to&&g(`/aufmass?customer_id=${s.id}&on_behalf_of=${s.assigned_to}`)},y=s=>{if(!s)return"â";const t=r.find(n=>n.id===s);return(t==null?void 0:t.full_name)||(t==null?void 0:t.email)||s.slice(0,8)};return e.jsxs("div",{className:"p-4 md:p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(E,{className:"h-7 w-7 text-primary"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Scout-Arbeitsplatz"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Lead-Kunden deiner zugeordneten Vertriebler â starte hier ein Aufmaà im Namen des Vertrieblers."})]})]}),e.jsxs(x,{children:[e.jsx(u,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Meine Vertriebler"}),e.jsx(f,{children:r.length===0?"Dir ist noch kein Vertriebler zugeordnet. Bitte beim Admin melden.":`${r.length} Vertriebler zugeordnet`})]}),r.length>0&&e.jsxs(V,{value:l,onValueChange:N,children:[e.jsx(A,{className:"w-64",children:e.jsx(F,{})}),e.jsxs(z,{children:[e.jsx(p,{value:"__all__",children:"Alle Vertriebler"}),r.map(s=>e.jsx(p,{value:s.id,children:s.full_name||s.email},s.id))]})]})]})}),e.jsx(K,{children:c.isLoading?e.jsx($,{className:"h-40"}):o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Keine Lead-Kunden für die aktuelle Auswahl."}):e.jsx("div",{className:"space-y-2",children:o.map(s=>e.jsxs("div",{className:"border rounded-md p-3 flex flex-col sm:flex-row gap-3 sm:items-center",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsxs("div",{className:"font-medium",children:[s.first_name," ",s.last_name??""]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:[s.street&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(k,{className:"h-3 w-3"})," ",s.street,s.postal_code||s.city?`, ${s.postal_code??""} ${s.city??""}`:""]}),s.phone&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(M,{className:"h-3 w-3"})," ",s.phone]}),s.email&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(B,{className:"h-3 w-3"})," ",s.email]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(j,{variant:"outline",className:"text-xs",children:["Lead ",s.lead_status?`· ${s.lead_status}`:""]}),e.jsxs(j,{variant:"secondary",className:"text-xs inline-flex items-center gap-1",children:[e.jsx(D,{className:"h-3 w-3"})," ",y(s.assigned_to)]})]})]}),e.jsx("div",{className:"flex gap-2",children:e.jsxs(L,{size:"sm",onClick:()=>v(s),children:[e.jsx(P,{className:"h-4 w-4 mr-1"})," Aufmaà erstellen"]})})]},s.id))})})]})]})}export{H 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.