1import{a5 as pe,a as he,b as ge,r as n,t as r,j as e,L as R}from"./index-BUX0r8JQ.js";import{u as V}from"./useQuery-BMiCuMJP.js";import{u as m}from"./useMutation-BweaPkBn.js";import{u as c}from"./useServerFn-9pAu7vJ6.js";import{B as i}from"./button--elNhoJn.js";import{I as v}from"./input-DzGQRw3C.js";import{L as d}from"./label-Cz3PwN8q.js";import{T as je}from"./textarea-PWwLTXDr.js";import{D as Q,a as $,b as z,c as G,e as H}from"./dialog-CQ2nc7bB.js";import{S as K,a as U,b as W,c as J,d as X}from"./select-B60fX1mo.js";import{R as fe}from"./rich-text-editor-B_tICiwa.js";import{W as Ne}from"./whatsapp-thread-Dbs98u9N.js";import{S as ve}from"./student-tasks-panel-RgnzwMjO.js";import{s as be,N as we}from"./send-student-message.functions-BFtcgij-.js";import{f as Se,u as ye,h as ke,j as Le,k as Ce,L as _e,a as Te,b as Ee,c as Ae,m as Me}from"./leads.functions-Dwtfma6z.js";import{l as De}from"./student-messages.functions-v6B_FNdf.js";import{A as Oe}from"./arrow-left-XEo-OIuD.js";import{P as Pe}from"./pencil-CfO0px3P.js";import{M as w}from"./mail-Dzz0Mjr-.js";import{P as Fe}from"./phone-3C_Tt38G.js";import{U as Be}from"./user-plus-D7NJ7Otx.js";import{T as Ie}from"./trash-2-DaaEDP8X.js";import{B as qe}from"./bell-C1flJ-A7.js";import"./index-C833xbDj.js";import"./utils-C2L_odii.js";import"./index-BNjY9exZ.js";import"./index-8g23YmAE.js";import"./index-D_q8iQL_.js";import"./index-DZueT1y7.js";import"./x-w7OtB7e_.js";import"./index-Hu762Ic1.js";import"./index-KK8WqVF3.js";import"./index-DEYbTS-N.js";import"./index-B5swJlW0.js";import"./check-B-sFfVhD.js";import"./popover-BqIl_OR6.js";import"./checkbox-C8MKiptk.js";import"./trial-lesson.functions-DZ612uHq.js";import"./loader-circle-BacOCgRc.js";import"./download-DIu1y4GX.js";import"./plan-trial-lesson-dialog-BTn-dNwM.js";import"./google-calendar.functions-C1YLeZP-.js";import"./teacher-availability.functions-CHjrKqf8.js";import"./groups.functions-cjZDu-OU.js";import"./calendar-RkYx8ibk.js";import"./circle-check-CuhSxIKO.js";import"./external-link-B0CYUlcX.js";import"./plus-DQV2Nl2m.js";import"./message-circle-oy-6kV1w.js";import"./users-4Ce_2_k6.js";import"./send-C3WbGoMw.js";import"./chevron-right-BJ1C2qYp.js";import"./calendar-plus-CBP5S3sP.js";import"./clock-C29iCMeS.js";import"./tasks.functions-C1BH0HdW.js";import"./tabs-Ch4AvdUx.js";import"./index-D792vpS1.js";import"./triangle-alert-ChGRCJ2D.js";import"./circle-ClLjbhWQ.js";function Y(a){const p=Array.isArray(a?.field_data)?a.field_data:[],h=new Set(["full_name","email","phone_number"]);return p.map(l=>({label:String(l?.name??"").replace(/_/g," ").trim(),value:Array.isArray(l?.values)?l.values.map(o=>String(o)).join(", "):""})).filter(l=>l.value&&l.label&&!h.has(l.label.replace(/ /g,"_").toLowerCase()))}function Gs(){const{leadId:a}=pe.useParams(),p=he(),h=ge(),l=c(Se),o=c(ye),Z=c(ke),ee=c(Le),se=c(Ce),te=c(be),{data:S}=V({queryKey:["lead",a],queryFn:()=>l({data:{id:a}})}),t=S?.lead,y=S?.events??[],[b,ae]=n.useState(null),[re,g]=n.useState(!1),[j,k]=n.useState(""),[L,C]=n.useState(""),[ne,ie]=n.useState(""),[le,_]=n.useState(!1),[oe,f]=n.useState(!1),[T,E]=n.useState(""),[A,M]=n.useState(""),[D,O]=n.useState(""),u=()=>{p.invalidateQueries({queryKey:["lead",a]}),p.invalidateQueries({queryKey:["leads"]})},de=m({mutationFn:s=>o({data:{id:a,status:s}}),onSuccess:()=>{r.success("Status bijgewerkt"),u()},onError:s=>r.error(s.message)}),me=m({mutationFn:s=>o({data:{id:a,tag:s}}),onSuccess:()=>{r.success("Tag bijgewerkt"),u()},onError:s=>r.error(s.message)}),P=m({mutationFn:()=>o({data:{id:a,fullName:T.trim()||void 0,email:A.trim(),phone:D.trim()}}),onSuccess:()=>{r.success("Gegevens bijgewerkt"),f(!1),u()},onError:s=>r.error(s.message)}),F=m({mutationFn:()=>o({data:{id:a,notes:b??""}}),onSuccess:()=>{r.success("Notitie opgeslagen"),u()},onError:s=>r.error(s.message)}),B=m({mutationFn:()=>ee({data:{id:a}}),onSuccess:s=>{r.success("Omgezet naar leerling"),h({to:"/students/$studentId",params:{studentId:s.studentId}})},onError:s=>r.error(s.message)}),ce=m({mutationFn:()=>Z({data:{id:a}}),onSuccess:()=>{r.success("Lead verwijderd"),h({to:"/leads"})},onError:s=>r.error(s.message)}),I=m({mutationFn:async()=>{const s=await te({data:{to:t.email,toName:t.full_name??void 0,subject:j,bodyHtml:L,bodyText:ne||" "}});if(!s?.ok)throw new Error(s?.error??"Verzenden mislukt");await se({data:{id:a,kind:"email",summary:`Mail verstuurd: ${j}`}}),(t.status==="nieuw"||t.status==="benaderd")&&await o({data:{id:a,status:"mail_contact"}})},onSuccess:()=>{r.success("Mail verstuurd"),g(!1),k(""),C(""),u()},onError:s=>r.error(s.message)}),ue=c(De),x=V({queryKey:["lead-messages",t?.email??""],queryFn:()=>ue({data:{email:t.email}}),enabled:!!t?.email,staleTime:6e4}),N=x.data?.messages??[],q=n.useRef(!1);return n.useEffect(()=>{q.current||!t||t.status!=="nieuw"||N.length!==0&&(q.current=!0,o({data:{id:a,status:"mail_contact"}}).then(u).catch(()=>{}))},[t,N.length]),t?e.jsxs("div",{className:"px-6 py-10 lg:px-12",children:[e.jsxs(R,{to:"/leads",className:"mb-6 inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(Oe,{className:"h-4 w-4"})," Terug naar leads"]}),e.jsxs("header",{className:"mb-8",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-widest text-muted-foreground",children:"Lead"}),e.jsxs("div",{className:"mt-1 flex items-center gap-3",children:[e.jsx("h1",{className:"font-display text-4xl text-foreground",children:t.full_name??"Onbekend"}),e.jsxs(i,{variant:"outline",size:"sm",onClick:()=>{E(t.full_name??""),M(t.email??""),O(t.phone??""),f(!0)},children:[e.jsx(Pe,{className:"mr-1.5 h-3.5 w-3.5"})," Bewerken"]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-4 text-sm text-muted-foreground",children:[t.email&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(w,{className:"h-4 w-4"}),t.email]}),t.phone&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Fe,{className:"h-4 w-4"}),t.phone]})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-2xl border border-border p-4 text-sm",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Herkomst"}),e.jsx("p",{className:"mt-1",children:t.source==="facebook"?"Facebook-advertentie":t.source==="whatsapp"?"WhatsApp":"Handmatig"}),e.jsx("p",{className:"text-muted-foreground",children:[t.campaign_name,t.ad_name].filter(
1Boolean).join(" · ")||"â"})]}),Y(t.raw).length>0&&e.jsxs("div",{className:"rounded-2xl border border-border p-4 text-sm",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Formulierantwoorden"}),t.form_name&&e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:t.form_name}),e.jsx("dl",{className:"mt-2 space-y-2",children:Y(t.raw).map(s=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:s.label}),e.jsx("dd",{className:"font-medium",children:s.value})]},s.label))})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Status"}),e.jsxs(K,{value:t.status,onValueChange:s=>de.mutate(s),children:[e.jsx(U,{className:"mt-1",children:e.jsx(W,{})}),e.jsx(J,{children:_e.map(s=>e.jsx(X,{value:s,children:Te[s]},s))})]})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Tag"}),e.jsxs(K,{value:t.tag??"nieuwe_lead",onValueChange:s=>me.mutate(s),children:[e.jsx(U,{className:"mt-1",children:e.jsx(W,{})}),e.jsx(J,{children:Ee.map(s=>e.jsx(X,{value:s,children:Ae[s]},s))})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:Me[t.tag??"nieuwe_lead"]})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Notities"}),e.jsx(je,{className:"mt-1",value:b??t.notes??"",onChange:s=>ae(s.target.value),placeholder:"Wat is er afgesproken?"}),e.jsx(i,{size:"sm",variant:"outline",className:"mt-2",disabled:b===null||F.isPending,onClick:()=>F.mutate(),children:"Notitie opslaan"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(i,{disabled:!t.email,onClick:()=>g(!0),children:[e.jsx(w,{className:"mr-2 h-4 w-4"})," Mailen"]}),t.student_id?e.jsx(i,{variant:"outline",asChild:!0,children:e.jsx(R,{to:"/students/$studentId",params:{studentId:t.student_id},children:"Open leerling"})}):e.jsxs(i,{variant:"outline",disabled:B.isPending,onClick:()=>B.mutate(),children:[e.jsx(Be,{className:"mr-2 h-4 w-4"})," Omzetten naar leerling"]}),e.jsxs(i,{variant:"ghost",className:"text-destructive",onClick:()=>ce.mutate(),children:[e.jsx(Ie,{className:"mr-2 h-4 w-4"})," Verwijderen"]})]}),e.jsxs(i,{type:"button",className:"w-full",onClick:()=>_(!0),children:[e.jsx(qe,{className:"mr-2 h-4 w-4"})," Nieuwe taak"]}),e.jsx(ve,{leadId:a}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs uppercase tracking-wider text-muted-foreground",children:"Tijdlijn"}),e.jsxs("ul",{className:"space-y-2",children:[y.map(s=>e.jsxs("li",{className:"rounded-lg border border-border p-3 text-sm",children:[e.jsx("p",{children:s.summary}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.actor_name??"Systeem"," ·"," ",new Date(s.created_at).toLocaleString("nl-NL",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})]})]},s.id)),y.length===0&&e.jsx("li",{className:"text-sm text-muted-foreground",children:"Nog niets gebeurd."})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"mb-2 flex items-center gap-2 text-xs uppercase tracking-wider text-muted-foreground",children:[e.jsx(w,{className:"h-4 w-4"})," Mailcontact"]}),e.jsxs("div",{className:"rounded-2xl border border-border p-4",children:[!t.email&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Geen e-mailadres bekend."}),t.email&&x.isLoading&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Mailbox ladenâ¦"}),t.email&&x.data?.error&&e.jsx("p",{className:"text-sm text-destructive",children:x.data.error}),t.email&&!x.isLoading&&N.length===0&&!x.data?.error&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nog geen mailcontact gevonden."}),e.jsx("ul",{className:"space-y-2",children:N.map(s=>e.jsxs("li",{className:`rounded-lg border border-border border-l-4 p-3 text-sm ${s.direction==="incoming"?"border-l-emerald-500":"border-l-sky-500"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"truncate font-medium",children:s.subject}),e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:new Date(s.date).toLocaleDateString("nl-NL",{day:"numeric",month:"short"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.direction==="incoming"?`Van ${s.fromName||s.from}`:`Aan ${s.to}`}),s.preview&&e.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-muted-foreground",children:s.preview})]},s.id))})]})]}),e.jsx(Ne,{target:{leadId:a},collapsible:!0})]})]}),re&&e.jsx(Q,{open:!0,onOpenChange:()=>g(!1),children:e.jsxs($,{className:"max-h-[90vh] max-w-2xl overflow-y-auto",children:[e.jsx(z,{children:e.jsxs(G,{children:["Mail aan ",t.full_name??t.email]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Onderwerp"}),e.jsx(v,{value:j,onChange:s=>k(s.target.value)})]}
1),e.jsxs("div",{children:[e.jsx(d,{children:"Bericht"}),e.jsx(fe,{onChange:(s,xe)=>{C(s),ie(xe)},placeholder:"Schrijf je bericht..."})]})]}),e.jsxs(H,{children:[e.jsx(i,{variant:"ghost",onClick:()=>g(!1),children:"Annuleren"}),e.jsx(i,{disabled:!j||!L||I.isPending,onClick:()=>I.mutate(),children:"Versturen"})]})]})}),oe&&e.jsx(Q,{open:!0,onOpenChange:()=>f(!1),children:e.jsxs($,{className:"max-w-md",children:[e.jsx(z,{children:e.jsx(G,{children:"Lead bewerken"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Naam"}),e.jsx(v,{value:T,onChange:s=>E(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{children:"E-mailadres"}),e.jsx(v,{type:"email",value:A,onChange:s=>M(s.target.value),placeholder:"[email protected]"})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Telefoonnummer"}),e.jsx(v,{value:D,onChange:s=>O(s.target.value),placeholder:"+31612345678"})]})]}),e.jsxs(H,{children:[e.jsx(i,{variant:"ghost",onClick:()=>f(!1),children:"Annuleren"}),e.jsx(i,{disabled:P.isPending,onClick:()=>P.mutate(),children:"Opslaan"})]})]})}),e.jsx(we,{open:le,onOpenChange:_,leadId:a,onCreated:()=>p.invalidateQueries({queryKey:["record-tasks",a]})})]}):e.jsx("div",{className:"px-6 py-10 text-sm text-muted-foreground lg:px-12",children:"Ladenâ¦"})}export{Gs as component};
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.