1import{j as e}from"./radix-7KI6mJPD.js";import{r as u}from"./highcharts-DAm76Z6K.js";import{u as xs,a as We,b as ra}from"./tanstack-B2cSsH6e.js";import{u as Aa,a as Fa}from"./usePricingTiers-DHO7R-T_.js";import{u as hs,s as c,e as F,f as E,aK as $e,h as L,i as B,j as V,a as ce,aJ as cs,B as q,ab as gs,Y as ve,$ as me,H as M,ar as De,as as Ke,at as Ee,r as Ma,av as Le,b_ as za,aW as Ms,b as ms,C as Da,br as us,aO as Ka,bz as zs,dG as Ds,a3 as Te,aB as Ce,cS as Ks,L as b,I as ae,ci as Ea,dB as Es,aY as ta,aT as La,aQ as Ba,aR as qa,b7 as le,w as Ia,A as Oa,M as qe,_ as Va,bl as ss,au as as,aw as Ra,T as Wa,ay as $a,az as Ta,aA as pe,aC as rs,aD as ts,a5 as Ls,dH as Ha,d as Bs,bv as ns,bO as Ie,aE as je,J as X,K as Y,N as ee,O as se,Q as i,aF as Ga,a2 as Ua,aG as qs,aH as Qa,aI as Ja,o as is,aL as Za,c as Is,ax as Os,S as Vs,aM as Xa,dI as Oe,q as Ya,ca as ls,b1 as Rs,bA as er,dJ as sr,cI as ar,bj as rr,aj as tr,bp as Ws,af as nr,by as ir,dK as lr,b6 as dr,bS as or,dA as cr,bB as mr,b2 as ur,aa as xr,cu as hr,am as gr,dL as pr,E as jr,cz as br,aN as vr}from"./index-BbUi1KSl.js";import{T as na,a as ia,b as Ge,c as de,d as la,e as oe}from"./table-DgrR3m7e.js";import{A as $s,a as Ts,b as Hs,c as Gs,d as Us,e as Qs,f as Js,g as Zs}from"./alert-dialog-B2-XbRWq.js";import{a as fr,f as ds,g as Nr,b as yr}from"./useUserInvoices-C-5mHwna.js";import{M as wr,C as _r,a as kr}from"./mail-x-DPzp5PwE.js";import{M as Cr}from"./mail-check-FBwXg25t.js";import{P as Sr}from"./PageBreadcrumb-DNvI_kLy.js";import{R as Pr}from"./ResilientBoundary-DZD4vPUS.js";import{a as Ar,u as Fr}from"./react-vendor-BDlMpkbs.js";import{F as Mr}from"./file-BpKgxDdD.js";import{f as Xs}from"./formatDistanceToNow-DaRTVVRx.js";const zr=({userId:l,userEmail:t,userName:h})=>{var I,U;const{toast:f}=hs(),W=xs(),[T,Q]=u.useState(null),{downloadInvoicePdf:H,generateInvoicePdfBase64:xe,isGenerating:fe}=fr(),{data:J,isLoading:Ne}=We({queryKey:["adminUserInvoices",l],queryFn:async()=>{const{data:n,error:N}=await c.from("invoices").select("id, invoice_number, amount_due, amount_paid, currency, status, period_start, period_end, paid_at, created_at, stripe_invoice_id, billing_cycle").eq("user_id",l).order("created_at",{ascending:!1});if(N)throw N;return n||[]}}),{data:w,isLoading:o}=We({queryKey:["adminUserEmailSends",l],queryFn:async()=>{const{data:n,error:N}=await c.from("checkout_email_sends").select("id, template_type, status, sent_at, created_at, error_message, stripe_invoice_id").eq("recipient_email",t).in("template_type",["recurring_invoice","tier_purchase","batch_purchase"]).order("created_at",{ascending:!1});if(N)throw N;return n||[]}}),{data:P,isLoading:_}=We({queryKey:["adminUserSubscription",l],queryFn:async()=>{const{data:n,error:N}=await c.from("subscriptions").select(` 2 id, status, started_at, cancelled_at, mrr_amount, billing_cycle, stripe_subscription_id, pricing_tier_id, batch_id, 3 pricing_tiers (name_nl), 4 pricing_batches (batch_name) 5 `).eq("user_id",l).order("created_at",{ascending:!1}).limit(1);if(N)throw N;return(n==null?void 0:n[0])||null}}),O=ra({mutationFn:async n=>{var N,_e,Se,d;const{pdfBase64:a,invoiceNumber:A}=await xe(n.id),R=A||n.invoice_number||n.id.slice(0,8).toUpperCase(),k=((N=P==null?void 0:P.pricing_tiers)==null?void 0:N.name_nl)||((_e=P==null?void 0:P.pricing_batches)==null?void 0:_e.batch_name)||"Abonnement",$=h.split(" ")[0]||h,Z=await c.functions.invoke("send-checkout-email",{body:{type:"recurring_invoice",recipient:{email:t,first_name:$||"Klant"},data:{plan_name:k,tier_name:k,amount:ds(n.amount_due,n.currency||"EUR"),billing_cycle:n.billing_cycle==="yearly"?"jaarlijks":"maandelijks",invoice_number:R,dashboard_url:"https://hellolumen.ai/dashboard",stripe_invoice_id:n.stripe_invoice_id},attachments:[{filename:`Factuur-${R}.pdf`,content:a,contentType:"application/pdf"}]}});if(Z.error)throw new Error(Z.error.message);if(!((Se=Z.data)!=null&&Se.success))throw new Error(((d=Z.data)==null?void 0:d.error)||"Verzenden mislukt");return Z.data},onSuccess:()=>{f({title:"E-mail verzonden",description:"De factuur is opnieuw per e-mail verzonden."}),W.invalidateQueries({queryKey:["adminUserEmailSends",l]})},onError:n=>
5{f({title:"Fout bij verzenden",description:n.message||"Kon de factuur niet verzenden",variant:"destructive"})}}),re=async n=>{Q(n.id);try{await O.mutateAsync(n)}finally{Q(null)}},Fe=n=>{H(n.id,n.invoice_number)},he=n=>!n||!w?null:w.find(N=>N.stripe_invoice_id===n)||null,Me=n=>{if(!n)return e.jsxs(M,{variant:"outline",className:"bg-muted/50 text-muted-foreground border-muted",children:[e.jsx(wr,{className:"h-3 w-3 mr-1"}),"Niet verzonden"]});switch(n.status){case"sent":return e.jsx(De,{children:e.jsxs(Ke,{children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(M,{variant:"outline",className:"bg-success/10 text-success border-success/30",children:[e.jsx(Cr,{className:"h-3 w-3 mr-1"}),"Verzonden"]})}),e.jsx(Le,{children:e.jsxs("p",{children:["Verzonden op ",n.sent_at?ve(new Date(n.sent_at),"d MMM yyyy HH:mm",{locale:me}):"Onbekend"]})})]})});case"failed":return e.jsx(De,{children:e.jsxs(Ke,{children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(M,{variant:"outline",className:"bg-destructive/10 text-destructive border-destructive/30",children:[e.jsx(ms,{className:"h-3 w-3 mr-1"}),"Mislukt"]})}),e.jsx(Le,{children:e.jsx("p",{children:n.error_message||"Onbekende fout"})})]})});case"pending":return e.jsxs(M,{variant:"outline",className:"bg-warning/10 text-warning border-warning/30",children:[e.jsx(us,{className:"h-3 w-3 mr-1"}),"In wachtrij"]});default:return e.jsx(M,{variant:"outline",className:"bg-muted text-muted-foreground",children:n.status})}},ye=(n,N)=>{if(N)return e.jsxs(M,{variant:"outline",className:"bg-warning/10 text-warning border-warning/30",children:[e.jsx(Ms,{className:"h-3 w-3 mr-1"}),"Opgezegd (loopt tot ",ve(new Date(N),"d MMM yyyy",{locale:me}),")"]});switch(n){case"active":return e.jsxs(M,{variant:"outline",className:"bg-success/10 text-success border-success/30",children:[e.jsx(Da,{className:"h-3 w-3 mr-1"}),"Actief"]});case"cancelled":return e.jsxs(M,{variant:"outline",className:"bg-destructive/10 text-destructive border-destructive/30",children:[e.jsx(Ms,{className:"h-3 w-3 mr-1"}),"Geannuleerd"]});case"past_due":return e.jsxs(M,{variant:"outline",className:"bg-destructive/10 text-destructive border-destructive/30",children:[e.jsx(ms,{className:"h-3 w-3 mr-1"}),"Achterstallig"]});default:return e.jsx(M,{variant:"outline",className:"bg-muted text-muted-foreground",children:n})}},we=Ne||o||_;return e.jsxs("div",{className:"space-y-6 mt-6",children:[e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-indigo-500/5 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-indigo-500 to-indigo-600 shadow-lg shadow-indigo-500/25",children:e.jsx($e,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(L,{className:"text-xl",children:"Abonnementsstatus"}),e.jsx(B,{children:"Huidige abonnement en betalingscyclus"})]})]})}),e.jsx(V,{className:"relative",children:_?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ce,{className:"h-4 w-4 animate-spin"}),"Laden..."]}):P?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Plan"}),e.jsx("p",{className:"font-medium",children:((I=P.pricing_tiers)==null?void 0:I.name_nl)||((U=P.pricing_batches)==null?void 0:U.batch_name)||"Onbekend"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Status"}),ye(P.status,P.cancelled_at)]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Betalingscyclus"}),e.jsx("p",{className:"font-medium capitalize",children:P.billing_cycle==="yearly"?"Jaarlijks":"Maandelijks"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"MRR"}),e.jsx("p",{className:"font-medium",children:ds(P.mrr_amount,"EUR")})]})]}):e.jsx("p",{className:"text-muted-foreground",children:"Geen actief abonnement"})})]}),e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-emerald-500/5 via-trans
5parent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-emerald-500 to-emerald-600 shadow-lg shadow-emerald-500/25",children:e.jsx(cs,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Facturen"}),e.jsx(B,{children:"Alle facturen van deze gebruiker"})]})]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>{W.invalidateQueries({queryKey:["adminUserInvoices",l]}),W.invalidateQueries({queryKey:["adminUserEmailSends",l]})},children:[e.jsx(gs,{className:"h-4 w-4 mr-2"}),"Vernieuwen"]})]})}),e.jsx(V,{className:"relative",children:we?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(ce,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):J&&J.length>0?e.jsxs(na,{children:[e.jsx(ia,{children:e.jsxs(Ge,{children:[e.jsx(de,{children:"Factuurnummer"}),e.jsx(de,{children:"Datum"}),e.jsx(de,{children:"Periode"}),e.jsx(de,{children:"Bedrag"}),e.jsx(de,{children:"Status"}),e.jsx(de,{children:"E-mail"}),e.jsx(de,{className:"text-right",children:"Acties"})]})}),e.jsx(la,{children:J.map(n=>{const N=he(n.stripe_invoice_id);return e.jsxs(Ge,{children:[e.jsx(oe,{className:"font-mono text-sm",children:n.invoice_number||n.id.slice(0,8).toUpperCase()}),e.jsx(oe,{children:n.created_at?ve(new Date(n.created_at),"d MMM yyyy",{locale:me}):"-"}),e.jsx(oe,{children:n.period_start&&n.period_end?e.jsxs("span",{className:"text-sm text-muted-foreground",children:[ve(new Date(n.period_start),"d MMM",{locale:me})," - ",ve(new Date(n.period_end),"d MMM yyyy",{locale:me})]}):"-"}),e.jsx(oe,{className:"font-medium",children:ds(n.amount_due,n.currency||"EUR")}),e.jsx(oe,{children:e.jsx(M,{variant:"outline",className:yr(n.status),children:Nr(n.status)})}),e.jsx(oe,{children:Me(N)}),e.jsx(oe,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(De,{children:e.jsxs(Ke,{children:[e.jsx(Ee,{asChild:!0,children:e.jsx(q,{variant:"ghost",size:"icon",onClick:()=>Fe(n),disabled:fe===n.id,children:fe===n.id?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):e.jsx(Ma,{className:"h-4 w-4"})})}),e.jsx(Le,{children:"Factuur downloaden"})]})}),e.jsx(De,{children:e.jsxs(Ke,{children:[e.jsx(Ee,{asChild:!0,children:e.jsx(q,{variant:"ghost",size:"icon",onClick:()=>re(n),disabled:T===n.id,children:T===n.id?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):e.jsx(za,{className:"h-4 w-4"})})}),e.jsx(Le,{children:"Factuur opnieuw mailen"})]})})]})})]},n.id)})})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(cs,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Geen facturen gevonden voor deze gebruiker"})]})})]})]})};var Dr=Object.defineProperty,Kr=Object.defineProperties,Er=Object.getOwnPropertyDescriptors,Ys=Object.getOwnPropertySymbols,Lr=Object.prototype.hasOwnProperty,Br=Object.prototype.propertyIsEnumerable,ea=(l,t,h)=>t in l?Dr(l,t,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[t]=h,He=(l,t)=>{for(var h in t||(t={}))Lr.call(t,h)&&ea(l,h,t[h]);if(Ys)for(var h of Ys(t))Br.call(t,h)&&ea(l,h,t[h]);return l},os=(l,t)=>Kr(l,Er(t));const qr=Ka({amount:qa().int({message:"Voer een geheel getal in"}).positive({message:"Aantal moet groter zijn dan 0"}).max(1e6,{message:"Maximaal 1.000.000 credits per aanpassing"}),reason:Ba().trim().min(3,{message:"Reden moet minimaal 3 tekens bevatten"}).max(500,{message:"Reden mag maximaal 500 tekens bevatten"}).regex(/^[a-zA-Z0-9Ã-ÿ\s.,!?()'-]+$/,{message:"Reden bevat ongeldige tekens"}),isAddition:La()}),Ve=l=>l?l.replace(/<[^>]*>/g,"").replace(/[<>"'&]/g,t=>({"<":"<",">":">",'"':""","'":"'","&":"&"})[t]||t).slice(0,1e3):"",Ir=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-3 gap-4",children:[1,2,3].map(l=>e.jsxs("div",{className:"p-4 rounded-xl bg-muted/50 border border-muted-foreground
5/10",children:[e.jsx(le,{className:"h-8 w-16 mx-auto mb-2"}),e.jsx(le,{className:"h-3 w-20 mx-auto"})]},l))}),e.jsxs("div",{className:"space-y-4 p-4 rounded-xl bg-muted/30 border border-muted-foreground/10",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{className:"h-9 flex-1"}),e.jsx(le,{className:"h-9 flex-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(le,{className:"h-11"}),e.jsx(le,{className:"h-11"})]}),e.jsx(le,{className:"h-11 w-full"})]})]}),Or=()=>e.jsx("div",{className:"space-y-3 p-4",children:[1,2,3].map(l=>e.jsxs("div",{className:"p-3 rounded-lg bg-muted/30 border border-muted-foreground/5 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(le,{className:"h-5 w-16"}),e.jsx(le,{className:"h-4 w-24"})]}),e.jsx(le,{className:"h-4 w-3/4"}),e.jsx(le,{className:"h-3 w-32"})]},l))}),Vr=({userId:l,subscription:t,creditsLimit:h,isLoading:I=!1,onCreditsUpdated:U})=>{var f;const{toast:W}=hs(),T=xs(),[Q,H]=u.useState(""),[xe,fe]=u.useState(""),[J,Ne]=u.useState(!0),[w,o]=u.useState({}),P=u.useRef(null);u.useEffect(()=>{if(!l||!(t!=null&&t.id))return;P.current&&c.removeChannel(P.current);const d=c.channel(`admin-credits-${l}`).on("postgres_changes",{event:"UPDATE",schema:"public",table:"subscriptions",filter:`id=eq.${t.id}`},a=>{T.invalidateQueries({queryKey:["creditHistory",l]}),U==null||U()}).subscribe(a=>{});return P.current=d,()=>{P.current&&(c.removeChannel(P.current),P.current=null)}},[l,t==null?void 0:t.id,T,U]);const _=(f=t==null?void 0:t.credits_used)!=null?f:0,O=h-_,{data:re,isLoading:Fe,isError:he,refetch:Me,isFetching:ye}=We({queryKey:["creditHistory",l],queryFn:async({signal:d})=>{const a=new Promise((R,k)=>{const $=setTimeout(()=>{k(new Error("Request timeout - netwerk te traag"))},15e3);d==null||d.addEventListener("abort",()=>clearTimeout($))}),A=async()=>{var R;const{data:k,error:$}=await c.from("credit_history").select("*").eq("user_id",l).order("created_at",{ascending:!1}).limit(50).abortSignal(d);if($)throw $;if(!k||k.length===0)return[];const Z=[...new Set(k.map(z=>z.performed_by))],{data:te}=await c.from("profiles").select("id, full_name, email").in("id",Z).abortSignal(d),ne=new Map((R=te==null?void 0:te.map(z=>[z.id,z.full_name||z.email||"Onbekend"]))!=null?R:[]);return k.map(z=>os(He({},z),{performer_name:ne.get(z.performed_by)||"Onbekend"}))};return Promise.race([A(),a])},staleTime:3e4,retry:2,retryDelay:d=>Math.min(1e3*2**d,1e4)}),we=ra({mutationFn:async({amount:d,reason:a,isAddition:A})=>{var R;if(!t)throw new Error("Geen actief abonnement gevonden");const{data:{user:k}}=await c.auth.getUser();if(!k)throw new Error("Niet ingelogd");const{data:$}=await c.from("subscriptions").select("credits_bonus").eq("id",t.id).single(),Z=(R=$==null?void 0:$.credits_bonus)!=null?R:0,te=O;let ne,z=_,Pe;A?(ne={credits_bonus:Z+d,updated_at:new Date().toISOString()},Pe=te+d):(z=_+d,ne={credits_used:z,updated_at:new Date().toISOString()},Pe=te-d);const{error:Ae}=await c.from("subscriptions").update(ne).eq("id",t.id);if(Ae)throw Ae;const{error:ue}=await c.from("credit_history").insert({user_id:l,amount:A?d:-d,reason:Ve(a),performed_by:k.id,credits_before:te,credits_after:Pe});if(ue)throw ue;return{newCreditsUsed:z,amount:d,isAddition:A}},onMutate:async({amount:d,isAddition:a})=>{await T.cancelQueries({queryKey:["creditHistory",l]});const A=T.getQueryData(["creditHistory",l]),R={id:`temp-${Date.now()}`,user_id:l,amount:a?d:-d,reason:Ve(xe),performed_by:"current-user",credits_before:O,credits_after:O+(a?d:-d),created_at:new Date().toISOString(),performer_name:"Jij (bezig...)"};return T.setQueryData(["creditHistory",l],k=>[R,...k||[]]),{previousHistory:A}},onSuccess:d=>{W({title:d.isAddition?"Credits toegevoegd":"Credits afgetrokken",description:`${d.amount} credits ${d.isAddition?"toegevoegd aan":"afgetrokken van"} het account.`}),H(""),fe(""),o({}),T.invalidateQueries({queryKey:["creditHistory",l]}),U==null||U()},onError:(d,a,A)=>{A!=null&&A.previousHistory&&T.setQueryData(["creditHistory",l],A.previousHistory),W({title:"Fout bij aanpassen credits",description:d.message,variant:"destructive"})}}),n=u.useCallback(()=>{const d=parseInt(Q),a=qr.safeParse({amount:isNaN(d)?0:d,reason:xe,isAddition:J});if(!a.success){const A={};
5a.error.errors.forEach(k=>{const $=k.path[0];A[$]=k.message}),o(A);const R=a.error.errors[0];W({title:"Validatiefout",description:(R==null?void 0:R.message)||"Controleer de invoer",variant:"destructive"});return}if(!J&&a.data.amount>O){o({amount:`Maximaal ${O} credits beschikbaar`}),W({title:"Niet genoeg credits",description:`Deze gebruiker heeft slechts ${O} beschikbare credits.`,variant:"destructive"});return}o({}),we.mutate({amount:a.data.amount,reason:a.data.reason,isAddition:a.data.isAddition})},[Q,xe,J,O,we,W]),N=u.useCallback(d=>{H(d),w.amount&&o(a=>os(He({},a),{amount:""}))},[w.amount]),_e=u.useCallback(d=>{fe(d),w.reason&&o(a=>os(He({},a),{reason:""}))},[w.reason]),Se=u.useMemo(()=>!re||re.length===0?null:re.map(d=>e.jsxs("div",{className:`p-3 rounded-lg bg-muted/30 border border-muted-foreground/5 space-y-2 transition-opacity ${d.id.startsWith("temp-")?"opacity-60":"opacity-100"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d.amount>0?e.jsxs(M,{variant:"default",className:"bg-green-500/20 text-green-600 border-green-500/30",children:[e.jsx(zs,{className:"h-3 w-3 mr-1"}),"+",d.amount]}):e.jsxs(M,{variant:"default",className:"bg-red-500/20 text-red-600 border-red-500/30",children:[e.jsx(Ds,{className:"h-3 w-3 mr-1"}),d.amount]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[d.credits_before," â ",d.credits_after]})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:ve(new Date(d.created_at),"d MMM yyyy HH:mm",{locale:me})})]}),e.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[e.jsx(Te,{className:"h-3.5 w-3.5 mt-0.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:Ve(d.reason)})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(Ce,{className:"h-3 w-3"}),e.jsxs("span",{children:["Door: ",Ve(d.performer_name)]})]})]},d.id)),[re]);return e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-yellow-500/5 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-yellow-500 to-yellow-600 shadow-lg shadow-yellow-500/25",children:e.jsx(Ks,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(L,{className:"text-xl",children:"Credit Beheer"}),e.jsx(B,{children:"Handmatig credits toevoegen of verwijderen"})]}),!I&&e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-2xl font-bold text-primary",children:O.toLocaleString("nl-NL")}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["van ",h.toLocaleString("nl-NL")," credits"]})]})]})}),e.jsx(V,{className:"relative space-y-6",children:I?e.jsx(Ir,{}):h===0&&!t?e.jsxs("div",{className:"p-6 rounded-xl bg-muted/30 border border-dashed border-muted-foreground/20 text-center space-y-2",children:[e.jsx(Ks,{className:"h-10 w-10 mx-auto text-muted-foreground/50"}),e.jsx("p",{className:"text-muted-foreground font-medium",children:"Geen credit limiet geconfigureerd"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Activeer eerst een plan met credits om credits te kunnen beheren."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-muted/50 border border-muted-foreground/10 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-green-500",children:O.toLocaleString("nl-NL")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Beschikbaar"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/50 border border-muted-foreground/10 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-orange-500",children:_.toLocaleString("nl-NL")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Gebruikt"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/50 border border-muted-foreground
5/10 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-primary",children:h.toLocaleString("nl-NL")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Limiet"})]})]}),t?e.jsxs("div",{className:"space-y-4 p-4 rounded-xl bg-muted/30 border border-muted-foreground/10",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(q,{type:"button",variant:J?"default":"outline",size:"sm",onClick:()=>Ne(!0),className:"flex-1",children:[e.jsx(zs,{className:"h-4 w-4 mr-2"}),"Toevoegen"]}),e.jsxs(q,{type:"button",variant:J?"outline":"default",size:"sm",onClick:()=>Ne(!1),className:"flex-1",children:[e.jsx(Ds,{className:"h-4 w-4 mr-2"}),"Aftrekken"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"creditAmount",children:"Aantal Credits"}),e.jsx(ae,{id:"creditAmount",type:"number",min:"1",max:"1000000",placeholder:"Bijv. 50",value:Q,onChange:d=>N(d.target.value),className:`h-11 bg-background border-muted-foreground/20 ${w.amount?"border-destructive":""}`,"aria-invalid":!!w.amount,"aria-describedby":w.amount?"amount-error":void 0}),w.amount&&e.jsx("p",{id:"amount-error",className:"text-xs text-destructive",children:w.amount})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"reason",children:"Reden *"}),e.jsx(ae,{id:"reason",placeholder:"Bijv. Bonus credits, Correctie, etc.",value:xe,onChange:d=>_e(d.target.value),maxLength:500,className:`h-11 bg-background border-muted-foreground/20 ${w.reason?"border-destructive":""}`,"aria-invalid":!!w.reason,"aria-describedby":w.reason?"reason-error":void 0}),w.reason&&e.jsx("p",{id:"reason-error",className:"text-xs text-destructive",children:w.reason})]})]}),e.jsx(q,{type:"button",onClick:n,disabled:we.isPending||!Q||!xe,className:"w-full",children:we.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-4 w-4 mr-2 animate-spin"}),"Bezig..."]}):J?e.jsxs(e.Fragment,{children:[e.jsx(_r,{className:"h-4 w-4 mr-2"}),Q||"0"," Credits Toevoegen"]}):e.jsxs(e.Fragment,{children:[e.jsx(kr,{className:"h-4 w-4 mr-2"}),Q||"0"," Credits Aftrekken"]})})]}):e.jsx("div",{className:"p-4 rounded-xl bg-muted/30 border border-muted-foreground/10 text-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Deze gebruiker heeft geen actief abonnement. Activeer eerst een plan om credits te kunnen beheren."})}),e.jsx(Ea,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Es,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h4",{className:"font-medium",children:"Credit Historie"})]}),he&&e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>Me(),disabled:ye,className:"text-xs",children:[e.jsx(gs,{className:`h-3 w-3 mr-1 ${ye?"animate-spin":""}`}),"Opnieuw laden"]})]}),he?e.jsxs("div",{className:"p-6 text-center rounded-xl border border-destructive/20 bg-destructive/5",children:[e.jsx(ms,{className:"h-8 w-8 mx-auto mb-2 text-destructive/70"}),e.jsx("p",{className:"text-destructive font-medium",children:"Kon historie niet laden"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Controleer je internetverbinding en probeer opnieuw."})]}):Fe?e.jsx("div",{className:"rounded-xl border border-muted-foreground/10",children:e.jsx(Or,{})}):Se?e.jsx(ta,{className:"h-[300px] rounded-xl border border-muted-foreground/10",children:e.jsx("div",{className:"p-4 space-y-3",children:Se})}):e.jsxs("div",{className:"p-8 text-center text-muted-foreground rounded-xl border border-dashed border-muted-foreground/20",children:[e.jsx(Es,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"Nog geen credit aanpassingen"})]})]})]})})]})},Rr=l=>e.jsx(Pr,{name:"CreditManagement",autoRetryAfter:3e3,maxAutoRetries:2,children:e.jsx(Vr,He({},l))});var Wr=Object.defineProperty,$r=Object.defineProperties,Tr=Object.getOwnPropertyDescriptors,sa=Object.getOwnPropertySymbols,Hr=Object.prototype.hasOwnProperty,Gr=Object.prototype.propertyIsEnumerable,aa=(l,t,h)=>t in l?Wr(l,t,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[t]=h,be=(l,t)=>
5{for(var h in t||(t={}))Hr.call(t,h)&&aa(l,h,t[h]);if(sa)for(var h of sa(t))Gr.call(t,h)&&aa(l,h,t[h]);return l},Re=(l,t)=>$r(l,Tr(t));const K=({id:l,label:t,icon:h,type:I="text",required:U=!1,placeholder:f,value:W,onChange:T})=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:l,className:"text-sm font-medium flex items-center gap-2",children:[t," ",U&&e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs("div",{className:"relative group/input",children:[h&&e.jsx(h,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground group-focus-within/input:text-primary transition-colors"}),e.jsx(ae,{id:l,type:I,placeholder:f,value:W,onChange:Q=>T(Q.target.value),className:`${h?"pl-10":""} h-11 bg-muted/50 border-muted-foreground/20 focus:border-primary focus:bg-background transition-all`})]})]}),mt=()=>{var l;const{clientId:t}=Ar(),h=Fr(),I=xs(),U=u.useCallback((s,r)=>{I.setQueryData(["tenants"],m=>m&&m.map(p=>p.id===s?be(be({},p),r):p))},[I]),{toast:f}=hs(),{isSuperAdmin:W,isAdmin:T,isLoading:Q}=Ia(),{data:H,isLoading:xe}=Aa(),[fe,J]=u.useState(!0),[Ne,w]=u.useState(!1),[o,P]=u.useState(null),[_,O]=u.useState(null),[re,Fe]=u.useState([]),[he,Me]=u.useState([]),[ye,we]=u.useState([]),[n,N]=u.useState(!1),[_e,Se]=u.useState("contact"),d=u.useMemo(()=>{var s,r,m,p,v,C;if(!_)return 0;const y=(s=_.pricing_tier_id)!=null?s:_.plan_id,j=(m=(r=H==null?void 0:H.find(ze=>ze.id===y))==null?void 0:r.credits_limit)!=null?m:0,g=(v=(p=_.pricing_batches)==null?void 0:p.credits_limit)!=null?v:0,G=j||g||100,D=(C=_.credits_bonus)!=null?C:0;return G+D},[H,_]),[a,A]=u.useState({salutation:"",firstName:"",middleName:"",lastName:"",jobTitle:"",department:"",phoneFixed:"",phoneMobile:"",personalWebsite:"",preferredLanguage:"nl",companyName:"",streetName:"",houseNumber:"",postalCode:"",city:"",country:"Nederland",kvkNumber:"",btwNumber:"",iban:"",industrySector:"",companySize:"",relationStatus:"lead",customerSegment:"",leadSource:"",communicationFrequency:"",emailMarketingConsent:!1,phoneContactConsent:!1,postalConsent:!1,linkedinProfile:"",username:"",notes:"",role:"user",mrrAmount:0,subscriptionStatus:"inactive",planId:"",vapidPublicKey:"",vapidPrivateKey:"",mailgunApiKey:"",mailgunDomain:"",mailgunFromEmail:"",mailgunFromName:""}),[R,k]=u.useState(!1),[$,Z]=u.useState(!1),[te,ne]=u.useState("idle"),[z,Pe]=u.useState(!1),Ae=u.useRef(!1),ue=u.useRef(null),[Be,Ue]=u.useState(""),[ps,js]=u.useState(!1),[bs,vs]=u.useState(!1),[fs,Ns]=u.useState(!1),ke=u.useRef(null),[ie,ys]=u.useState(null),[Qe,ws]=u.useState(""),[_s,ks]=u.useState(!1),{showLeaveDialog:da,confirmNavigation:oa,cancelNavigation:Cs}=Fa({hasUnsavedChanges:z}),ca={salutation:"Aanhef",firstName:"Voornaam",middleName:"Tussenvoegsel",lastName:"Achternaam",jobTitle:"Functietitel",department:"Afdeling",phoneFixed:"Vast telefoonnummer",phoneMobile:"Mobiel nummer",personalWebsite:"Persoonlijke website",preferredLanguage:"Voorkeurstaal",companyName:"Bedrijfsnaam",streetName:"Straatnaam",houseNumber:"Huisnummer",postalCode:"Postcode",city:"Plaats",country:"Land",kvkNumber:"KvK-nummer",btwNumber:"BTW-nummer",iban:"IBAN",industrySector:"Branche",companySize:"Bedrijfsgrootte",relationStatus:"Relatiestatus",customerSegment:"Klantsegment",leadSource:"Lead bron",communicationFrequency:"Communicatiefrequentie",emailMarketingConsent:"E-mail marketing toestemming",phoneContactConsent:"Telefonisch contact toestemming",postalConsent:"Post toestemming",linkedinProfile:"LinkedIn profiel",username:"Gebruikersnaam",notes:"Notities",role:"Rol",mrrAmount:"MRR bedrag",subscriptionStatus:"Plan status",planId:"Plan",vapidPublicKey:"VAPID Public Key",vapidPrivateKey:"VAPID Private Key",mailgunApiKey:"Mailgun API Key",mailgunDomain:"Mailgun Domain",mailgunFromEmail:"Mailgun From Email",mailgunFromName:"Mailgun From Name"},ma=u.useCallback(()=>{if(!ke.current)return 0;const s=ke.current;let r=0;return Object.keys(a).forEach(m=>{a[m]!==s[m]&&r++}),r},[a]),ua=u.useCallback(()=>{if(!ke.current)return[];const s=ke.current,r=[];return Object.keys(a).forEach(m=>{a[m]!==s[m]&&r.push(ca[m]||m)}),r},[a]),Je=ma(),xa=ua();u.useEffect(()=>{t&&Ze()},[t]),u.useEffect(()=>{_e==="system"&&t&&(async()=>{var r,m,p,v,C,y,j,g,G;try{const{data:D,error:ze}=await c.rpc("get_user_storage_usage_mb",{p_user_id:t});if(!ze&&D){const ge=D;ys({used_mb:(r=ge.used_mb)!=null?r:0,limit_mb:(m=ge.limit_mb)!=null?m:500,usage_pct:(p=ge.usage_pct)!=null?p:0,images_mb:(v=ge.images_mb)!=null?v:0,docs_mb:(C=ge.docs_mb)!=null?C:0,prompts_mb:(y=ge.prompts_mb)!=null?y:0,warning:(j=ge.warning)!=null?j:!1})}const{data:Ye}=await c.from("profiles").select("storage_limit_mb_override").eq("id",t).single();Ye&&ws((G=(g=Ye.storage_limit_mb_override)==null?void 0:g.toString())!=null?G:"")}catch(D){}})()},[_e,t]);const ha=async()=>{var s,r,m,p,v,C,y;if(t){ks(!0);try{const j=Qe.trim()===""?null:parseInt(Qe,10);if(j!==null&&(isNaN(j)||j<0)){f({title:"Ongeldige waarde",description:"Voer een geldig getal in (MB).",variant:"destructive"});return}const{error:g}=await c.from("profiles").update({storage_limit_mb_override:j}).eq("id",t);if(g)throw g;f({title:"Opgeslagen",description:j?`Opslaglimiet: ${j} MB`:"Teruggezet naar tier-standaard."});const{data:G}=await c.rpc("get_user_storage_usage_mb",{p_user_id:t});if(G){const D=G;ys({used_mb:(s=D.used_mb)!=null?s:0,limit_mb:(r=D.limit_mb)!=null?r:500,usage_pct:(m=D.usage_pct)!=null?m:0,images_mb:(p=D.images_mb)!=null?p:0,docs_mb:(v=D.docs_mb)!=null?v:0,prompts_mb:(C=D.prompts_mb)!=null?C:0,warning:(y=D.warning)!=null?y:!1})}}catch(j){f({title:"Fout",description:j instanceof Error?j.message:"Kon opslaglimiet niet opslaan.",variant:"destructive"})}finally{ks(!1)}}},x=(s,r)=>{A(m=>Re(be({},m),{[s]:r})),Ae.current&&Pe(!0)};u.useEffect(()=>{if(!(!z||!Ae.current||!o))return ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>{ga()},1500),()=>{ue.current&&clearTimeout(ue.current)}},[a,z]);const ga=async()=>
5{if(!(!o||Ne)){ne("saving"),w(!0);try{const r={full_name:[a.firstName,a.middleName,a.lastName].filter(Boolean).join(" "),salutation:a.salutation||null,first_name:a.firstName||null,middle_name:a.middleName||null,last_name:a.lastName||null,job_title:a.jobTitle||null,department:a.department||null,phone_fixed:a.phoneFixed||null,phone_mobile:a.phoneMobile||null,personal_website:a.personalWebsite||null,preferred_language:a.preferredLanguage||"nl",company_name:a.companyName||null,street_name:a.streetName||null,house_number:a.houseNumber||null,postal_code:a.postalCode||null,city:a.city||null,country:a.country||"Nederland",kvk_number:a.kvkNumber||null,btw_number:a.btwNumber||null,iban:a.iban||null,industry_sector:a.industrySector||null,company_size:a.companySize||null,relation_status:a.relationStatus||null,customer_segment:a.customerSegment||null,lead_source:a.leadSource||null,communication_frequency:a.communicationFrequency||null,email_marketing_consent:a.emailMarketingConsent,phone_contact_consent:a.phoneContactConsent,postal_consent:a.postalConsent,linkedin_profile:a.linkedinProfile||null,username:a.username||null,notes:a.notes||null,vapid_public_key:a.vapidPublicKey||null,mailgun_domain:a.mailgunDomain||null,mailgun_from_email:a.mailgunFromEmail||null,mailgun_from_name:a.mailgunFromName||null};a.vapidPrivateKey&&a.vapidPrivateKey.trim().length>0&&(r.vapid_private_key=a.vapidPrivateKey),a.mailgunApiKey&&a.mailgunApiKey.trim().length>0&&(r.mailgun_api_key=a.mailgunApiKey);const{error:m}=await c.from("profiles").update(r).eq("id",o.id);if(m)throw m;const{data:{user:p}}=await c.auth.getUser(),v=he.length>0?he[0].role:"user";if(a.role!==v&&(await c.from("user_roles").delete().eq("user_id",o.id),await c.from("user_roles").insert({user_id:o.id,role:a.role,created_by:p==null?void 0:p.id})),n){const{data:C,error:y}=await c.from("subscriptions").select("id").eq("user_id",o.id).limit(1);if(y)throw y;if(C&&C.length>0)await c.from("subscriptions").update({mrr_amount:a.mrrAmount,status:a.subscriptionStatus,pricing_tier_id:a.planId||null}).eq("user_id",o.id);else{const{data:j,error:g}=await c.from("subscriptions").insert({user_id:o.id,mrr_amount:a.mrrAmount,status:a.subscriptionStatus,pricing_tier_id:a.planId||null}).select("*").single();if(g)throw g;O(j)}I.invalidateQueries({queryKey:["tenants"]}),I.invalidateQueries({queryKey:["tenantStats"]})}else _&&(await c.from("subscriptions").delete().eq("user_id",o.id),O(null),N(!1),I.invalidateQueries({queryKey:["tenants"]}),I.invalidateQueries({queryKey:["tenantStats"]}));I.invalidateQueries({queryKey:["profile"]}),ne("saved"),Pe(!1),ke.current=be({},a),setTimeout(()=>{ne("idle")},2e3)}catch(s){ne("error")}finally{w(!1)}}},pa=()=>{ke.current&&(A(be({},ke.current)),Pe(!1),ne("idle"),ue.current&&clearTimeout(ue.current),f({title:"Wijzigingen ongedaan gemaakt",description:"De gegevens zijn teruggezet naar de laatst opgeslagen versie"}))},ja=async(s,r,m={})=>{if(t)try{await c.from("activity_logs").insert({user_id:t,action_type:s,action_description:r,metadata:m})}catch(p){}},Ze=async()=>{var s;try{J(!0);const{data:r,error:m}=await c.from("profiles").select("*").eq("id",t).single();if(m)throw m;P(r);let p={salutation:r.salutation||"",firstName:r.first_name||"",middleName:r.middle_name||"",lastName:r.last_name||"",jobTitle:r.job_title||"",department:r.department||"",phoneFixed:r.phone_fixed||"",phoneMobile:r.phone_mobile||"",personalWebsite:r.personal_website||"",preferredLanguage:r.preferred_language||"nl",companyName:r.company_name||"",streetName:r.street_name||"",houseNumber:r.house_number||"",postalCode:r.postal_code||"",city:r.city||"",country:r.country||"Nederland",kvkNumber:r.kvk_number||"",btwNumber:r.btw_number||"",iban:r.iban||"",industrySector:r.industry_sector||"",companySize:r.company_size||"",relationStatus:r.relation_status||"lead",customerSegment:r.customer_segment||"",leadSource:r.lead_source||"",communicationFrequency:r.communication_frequency||"",emailMarketingConsent:r.email_marketing_consent||!1,phoneContactConsent:r.phone_contact_consent||!1,postalConsent:r.postal_consent||!1,linkedinProfile:r.linkedin_profile||"",username:r.username||"",notes:r.notes||"",role:"user",mrrAmount:0,subscriptionStatus:"inactive",planId:"",vapidPublicKey:r.vapid_public_key||"",vapidPrivateKey:"",mailgunApiKey:"",mailgunDomain:r.mailgun_domain||"",mailgunFromEmail:r.mailgun_from_email||"",mailgunFromName:r.mailgun_from_name||""};const{data:v,error:C}=await c.from("user_roles").select("*").eq("user_id",t);if(!C&&v&&(Me(v),v.length>0)){const S=["superadmin","admin","reseller","user"],es=v.reduce((As,Fs)=>{const Pa=S.indexOf(As.role);return S.indexOf(Fs.role)<Pa?Fs:As});p=Re(be({},p),{role:es.role})}const{data:y,error:j}=await c.from("subscriptions").select(` 6 *, 7 pricing_batches ( 8 credits_limit 9 ) 10 `).eq("user_id",t).order("created_at",{ascending:!1}).limit(1);if(j)throw j;const g=y==null?void 0:y[0];g&&(O(g),N(!0),p=Re(be({},p),{mrrAmount:g.mrr_amount,subscriptionStatus:g.status,planId:((s=g.pricing_tier_id)!=null?s:g.plan_id)||""})),A(p),ke.current=be({},p);const{data:G,error:D}=await c.from("chat_widgets").select("*").eq("owner_id",t).order("created_at",{ascending:!1});!D&&G&&Fe(G);const{data:ze,error:Ye}=await c.from("activity_logs").select("id, action_type, action_description, metadata, created_at").eq("user_id",t).order("created_at",{ascending:!1}).limit(100),{data:ge,error:Ur}=await c.from("ai_costs").select("id, usage_type, tokens_used, model_used, cost_amount, created_at").eq("user_id",t).order("created_at",{ascending:!1}).limit(100),ka={ai_hub_chat:"AI Hub chat gesprek",scan:"Document scan",quiz_coaching:"Quiz coaching",coach_insights:"Coach inzichten gegenereerd",chat:"Chat gesprek",surprise_ai_role:"AI Rol verrassing",surprise_frameworks:"Framework verrassing",wizard_analyze:"Wizard analyse",wizard_prompt_generation:"Wizard prompt generatie",wizard_intro:"Wizard introductie",proactive_coach_message:"Proactief coachbericht",ai_hub_combine:"AI Hub combinatie",lumen_demo_chat:"Lumen demo chat",coach_greeting:"Coach begroeting",document_visual:"Visueel document"},Ca=(ge||[]).map(S=>({id:`ai_${S.id}`,action_type:`ai_usage_${S.usage_type}`,action_description:`${ka[S.usage_type]||S.usage_type} â ${S.tokens_used||0} tokens${S.model_used?` (${S.model_used})`:""}`,metadata:{tokens:S.tokens_used,model:S.model_used,cost:S.cost_amount},created_at:S.created_at})),Sa=[...(ze||[]).map(S=>Re(be({},S),{metadata:typeof S.metadata=="object"&&S.metadata!==null?S.metadata:null})),...Ca].sort((S,es)=>new Date(es.created_at).getTime()-new Date(S.created_at).getTime()).slice(0,100);we(Sa)}catch(r){f({title:"Fout bij ophalen",description:"Kon klantgegevens niet ophalen",variant:"destructive"}),h("/dashboard/tenant-management")}finally{J(!1),setTimeout(()=>{Ae.current=!0},100)}},ba=async()=>{var s,r;if(!(!o||!Be)){js(!0);try{const{data:{session:m}}=await c.auth.getSession(),{data:p,error:v}=await c.functions.invoke("update-user",{body:{userId:o.id,password:Be},headers:{Authorization:`Bearer ${m==null?void 0:m.access_token}`}});if(p!=null&&p.error)throw new Error(p.error);if(v){const C=(s=v==null?void 0:v.context)==null?void 0:s.status,y=(r=v==null?void 0:v.context)==null?void 0:r.body;let j=(v==null?void 0:v.message)||"Kon wachtwoord niet wijzigen.";if(typeof y=="string"&&y.trim())try{const g=JSON.parse(y);
10typeof(g==null?void 0:g.error)=="string"&&g.error.trim()?j=g.error:typeof(g==null?void 0:g.message)=="string"&&g.message.trim()&&(j=g.message)}catch(g){}else if(y&&typeof y=="object"){const g=y;typeof g.error=="string"&&g.error.trim()?j=g.error:typeof g.message=="string"&&g.message.trim()&&(j=g.message)}throw new Error(C?`${j} (status ${C})`:j)}f({title:"Wachtwoord gewijzigd",description:"Het wachtwoord is succesvol bijgewerkt."}),Ue("")}catch(m){f({title:"Fout bij wijzigen wachtwoord",description:m.message||"Kon wachtwoord niet wijzigen.",variant:"destructive"})}finally{js(!1)}}},va=async()=>{const s="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789!@#$%&*?",m=crypto.getRandomValues(new Uint8Array(16)),p=Array.from(m,v=>s[v%s.length]).join("");Ue(p);try{await navigator.clipboard.writeText(p),f({title:"Sterk wachtwoord gegenereerd",description:"Het nieuwe wachtwoord staat in het veld en is gekopieerd."})}catch(v){f({title:"Sterk wachtwoord gegenereerd",description:"Het nieuwe wachtwoord staat in het veld."})}},fa=async()=>{if(!o)return;w(!0);const s=[];try{const r=[a.firstName,a.middleName,a.lastName].filter(Boolean).join(" "),{error:m}=await c.from("profiles").update({full_name:r,salutation:a.salutation||null,first_name:a.firstName||null,middle_name:a.middleName||null,last_name:a.lastName||null,job_title:a.jobTitle||null,department:a.department||null,phone_fixed:a.phoneFixed||null,phone_mobile:a.phoneMobile||null,personal_website:a.personalWebsite||null,preferred_language:a.preferredLanguage||"nl",company_name:a.companyName||null,street_name:a.streetName||null,house_number:a.houseNumber||null,postal_code:a.postalCode||null,city:a.city||null,country:a.country||"Nederland",kvk_number:a.kvkNumber||null,btw_number:a.btwNumber||null,iban:a.iban||null,industry_sector:a.industrySector||null,company_size:a.companySize||null,relation_status:a.relationStatus||null,customer_segment:a.customerSegment||null,lead_source:a.leadSource||null,communication_frequency:a.communicationFrequency||null,email_marketing_consent:a.emailMarketingConsent,phone_contact_consent:a.phoneContactConsent,postal_consent:a.postalConsent,linkedin_profile:a.linkedinProfile||null,username:a.username||null,notes:a.notes||null}).eq("id",o.id);if(m)throw m;s.push("Profiel bijgewerkt");const{data:{user:p}}=await c.auth.getUser(),v=he.length>0?he[0].role:"user";if(a.role!==v&&(s.push(`Rol gewijzigd naar "${a.role}"`),await c.from("user_roles").delete().eq("user_id",o.id),await c.from("user_roles").insert({user_id:o.id,role:a.role,created_by:p==null?void 0:p.id})),n){const C=H==null?void 0:H.find(G=>G.id===a.planId),y=(C==null?void 0:C.price_monthly)||0,{data:j,error:g}=await c.from("subscriptions").select("id").eq("user_id",o.id).limit(1);if(g)throw g;if(j&&j.length>0)await c.from("subscriptions").update({pricing_tier_id:a.planId||null,mrr_amount:y,status:a.subscriptionStatus}).eq("user_id",o.id),s.push("Plan bijgewerkt");else{const{data:G,error:D}=await c.from("subscriptions").insert({user_id:o.id,pricing_tier_id:a.planId||null,mrr_amount:y,status:a.subscriptionStatus}).select("*").single();if(D)throw D;O(G),s.push("Nieuw plan aangemaakt")}U(o.id,{plan:(C==null?void 0:C.name)||"Geen plan",status:a.subscriptionStatus})}else _&&(await c.from("subscriptions").delete().eq("user_id",o.id),O(null),N(!1),s.push("Plan verwijderd"),U(o.id,{plan:"Geen plan",status:"inactive"}));I.invalidateQueries({queryKey:["tenants"]}),I.invalidateQueries({queryKey:["tenantStats"]}),s.length>0&&await ja("profile_updated",`Profiel bijgewerkt: ${s.join(", ")}`,{changes:s,updated_by:p==null?void 0:p.email}),f({title:"Opgeslagen",description:"Klantgegevens zijn bijgewerkt"}),Ze()}catch(r){f({title:"Fout bij opslaan",description:r.message||"Kon wijzigingen niet opslaan",variant:"destructive"})}finally{w(!1)}},Na=async()=>{if(o){Z(!0);try{await vr("delete-user",{userId:o.id}),f({title:"Klant verwijderd",description:`${o.full_name||o.email} is verwijderd`}),h("/dashboard/tenant-management")}catch(s){f({title:"Fout bij verwijderen",description:s.message||"Kon klant niet verwijderen",variant:"destructive"})}finally{Z(!1),k(!1)}}},Ss={superadmin:{badge:"bg-amber-500/20 text-amber-400 border-amber-500/30",icon:"text-amber-100",gradient:"from-
10amber-500 to-amber-600",shadow:"shadow-amber-500/25",label:"Super Admin"},admin:{badge:"bg-purple-500/20 text-purple-400 border-purple-500/30",icon:"text-purple-100",gradient:"from-purple-500 to-purple-600",shadow:"shadow-purple-500/25",label:"Admin"},reseller:{badge:"bg-blue-500/20 text-blue-400 border-blue-500/30",icon:"text-blue-100",gradient:"from-blue-500 to-blue-600",shadow:"shadow-blue-500/25",label:"Reseller"},user:{badge:"bg-muted text-muted-foreground border-border",icon:"text-muted-foreground",gradient:"from-muted to-muted/80",shadow:"shadow-muted/25",label:"Gebruiker"}},Ps=s=>Ss[s]||Ss.user,ya=s=>{const r=Ps(s);return e.jsx(M,{variant:"outline",className:r.badge,children:r.label})},wa=s=>s.startsWith("prompt_")?e.jsx(as,{className:"h-4 w-4"}):s==="library_search"?e.jsx(nr,{className:"h-4 w-4"}):s.startsWith("wizard_")?e.jsx(ir,{className:"h-4 w-4"}):s.startsWith("quiz_")?e.jsx(lr,{className:"h-4 w-4"}):s.startsWith("framework_")?e.jsx(dr,{className:"h-4 w-4"}):s.startsWith("checklist_")?e.jsx(or,{className:"h-4 w-4"}):s.startsWith("project_")?e.jsx(cr,{className:"h-4 w-4"}):s.startsWith("lumen_")?e.jsx(mr,{className:"h-4 w-4"}):s==="level_up"?e.jsx(ur,{className:"h-4 w-4"}):s==="achievement_unlocked"?e.jsx(Os,{className:"h-4 w-4"}):s==="xp_earned"?e.jsx(xr,{className:"h-4 w-4"}):s.startsWith("streak_")?e.jsx(hr,{className:"h-4 w-4"}):s.startsWith("coach_")?e.jsx(Te,{className:"h-4 w-4"}):s==="login"||s==="session_started"?e.jsx(gr,{className:"h-4 w-4"}):s==="logout"?e.jsx(pr,{className:"h-4 w-4"}):s==="page_visited"?e.jsx(jr,{className:"h-4 w-4"}):s==="session_long_active"?e.jsx(us,{className:"h-4 w-4"}):s==="profile_updated"?e.jsx(as,{className:"h-4 w-4"}):s==="role_changed"?e.jsx(Oe,{className:"h-4 w-4"}):s.startsWith("subscription_")?e.jsx($e,{className:"h-4 w-4"}):s.startsWith("ai_usage_")?e.jsx(br,{className:"h-4 w-4"}):e.jsx(Ie,{className:"h-4 w-4"}),_a=s=>s.startsWith("prompt_")||s==="library_search"?"bg-violet-500/20 text-violet-400":s.startsWith("wizard_")?"bg-indigo-500/20 text-indigo-400":s==="quiz_passed"?"bg-green-500/20 text-green-400":s==="quiz_failed"?"bg-red-500/20 text-red-400":s.startsWith("quiz_")?"bg-amber-500/20 text-amber-400":s.startsWith("framework_")?"bg-blue-500/20 text-blue-400":s==="checklist_completed"?"bg-green-500/20 text-green-400":s.startsWith("checklist_progress_")?"bg-amber-500/20 text-amber-400":s.startsWith("checklist_")?"bg-teal-500/20 text-teal-400":s.startsWith("project_")?"bg-sky-500/20 text-sky-400":s.startsWith("lumen_")?"bg-purple-500/20 text-purple-400":s==="level_up"||s==="achievement_unlocked"?"bg-yellow-500/20 text-yellow-400":s==="xp_earned"?"bg-emerald-500/20 text-emerald-400":s==="streak_continued"?"bg-orange-500/20 text-orange-400":s==="streak_broken"?"bg-red-500/20 text-red-400":s.startsWith("coach_")?"bg-cyan-500/20 text-cyan-400":s==="login"||s==="session_started"?"bg-green-500/20 text-green-400":s==="logout"?"bg-muted text-muted-foreground":s==="page_visited"?"bg-slate-500/20 text-slate-400":s==="session_long_active"||s==="profile_updated"?"bg-blue-500/20 text-blue-400":s==="role_changed"?"bg-purple-500/20 text-purple-400":s==="subscription_created"?"bg-green-500/20 text-green-400":s==="subscription_updated"?"bg-amber-500/20 text-amber-400":s==="subscription_cancelled"?"bg-red-500/20 text-red-400":s.startsWith("widget_")?"bg-cyan-500/20 text-cyan-400":s.startsWith("ai_usage_")?"bg-pink-500/20 text-pink-400":"bg-muted text-muted-foreground";if(Q)return e.jsx("div",{className:"flex-1 flex flex-col",children:e.jsx("div",{className:"container py-8",children:e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-muted-foreground",children:"Toegang controleren..."})})})});if(!W&&!T)return e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx(F,{children:e.jsxs(E,{children:[e.jsx(L,{children:"Geen toegang"}),e.jsx(B,{children:"Je hebt geen toegang tot deze pagina. Alleen admins kunnen gebruikers bewerken."})]})})});if(fe)return e.jsx("div",{className:"flex-1 flex flex-col",children:e.jsx("div",{className:"container py-8",children:e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-muted-foreground",children:"Klantgegevens laden..."})})})});if(!o)return e.jsx("div",{className:"flex-1 flex flex-col",children:e.jsx("div",{className:"container py-8",children:e.jsx(F,{children:e.jsxs(E,{children:[e.jsx(L,{children:"Klant niet gevonden"}),e.jsx(B,{children:"Deze klant bestaat niet of is verwijderd."})]})})})});
10const Xe=[a.firstName,a.middleName,a.lastName].filter(Boolean).join(" ")||o.email||"Onbekend";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 flex flex-col",children:e.jsxs("div",{className:"w-full px-6 py-8 space-y-8",children:[e.jsx(Sr,{}),e.jsxs("div",{className:"relative overflow-hidden rounded-3xl bg-gradient-to-r from-primary/20 via-primary/10 to-accent/20 p-8 border border-primary/20",children:[e.jsx("div",{className:"absolute inset-0 bg-grid-white/5"}),e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-primary/20 rounded-full blur-3xl -translate-y-1/2 translate-x-1/2"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-48 h-48 bg-accent/20 rounded-full blur-3xl translate-y-1/2 -translate-x-1/2"}),e.jsxs("div",{className:"relative flex items-center gap-6",children:[e.jsx(q,{variant:"outline",size:"icon",onClick:()=>h("/dashboard/tenant-management"),className:"shrink-0 bg-background/50 backdrop-blur-sm border-primary/20 hover:bg-background/80",children:e.jsx(Oa,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[(()=>{const s=Ps(a.role);return e.jsx("div",{className:`p-3 rounded-2xl bg-gradient-to-br ${s.gradient} shadow-lg ${s.shadow}`,children:e.jsx(Ce,{className:`h-8 w-8 ${s.icon}`})})})(),ya(a.role)]}),e.jsx("h1",{className:"text-4xl font-bold tracking-tight bg-gradient-to-r from-foreground to-foreground/70 bg-clip-text",children:Xe}),e.jsxs("p",{className:"text-muted-foreground mt-2 flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"h-4 w-4"}),o.email]}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Va,{className:"h-4 w-4"}),"Lid sinds ",ve(new Date(o.created_at),"d MMMM yyyy",{locale:me})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[te==="saving"&&e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground animate-pulse",children:[e.jsx(ce,{className:"h-4 w-4 animate-spin"}),"Opslaan..."]}),te==="saved"&&e.jsxs("span",{className:"flex items-center gap-2 text-green-500",children:[e.jsx(ss,{className:"h-4 w-4"}),"Opgeslagen"]}),te==="error"&&e.jsx("span",{className:"flex items-center gap-2 text-destructive",children:"Fout bij opslaan"}),z&&te==="idle"&&e.jsxs("span",{className:"flex items-center gap-2 text-amber-500",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500 animate-pulse"}),"Niet opgeslagen",Je>0&&e.jsx(De,{children:e.jsxs(Ke,{children:[e.jsx(Ee,{asChild:!0,children:e.jsxs("span",{className:"flex items-center gap-1 ml-1 px-2 py-0.5 rounded-full bg-amber-500/20 text-xs font-medium cursor-help",children:[e.jsx(as,{className:"h-3 w-3"}),Je," ",Je===1?"veld":"velden"]})}),e.jsxs(Le,{side:"bottom",className:"max-w-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:"Gewijzigde velden:"}),e.jsx("ul",{className:"text-xs space-y-0.5",children:xa.map((s,r)=>e.jsxs("li",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"h-1 w-1 rounded-full bg-amber-500"}),s]},r))})]})]})})]})]}),z&&e.jsxs(q,{variant:"outline",onClick:pa,className:"border-amber-500/30 text-amber-600 hover:bg-amber-500/10",children:[e.jsx(Ra,{className:"mr-2 h-4 w-4"}),"Ongedaan maken"]}),e.jsxs(q,{variant:"destructive",onClick:()=>k(!0),children:[e.jsx(Wa,{className:"mr-2 h-4 w-4"}),"Verwijderen"]})]})]})]}),e.jsxs($a,{value:_e,onValueChange:Se,className:"w-full",children:[e.jsxs(Ta,{className:"grid w-full grid-cols-9 h-14 bg-muted/50 p-1 rounded-2xl",children:[e.jsxs(pe,{value:"contact",className:"flex items-center gap-2 rounded-xl data-[state=active]:bg-background data-[state=active]:shadow-lg",children:[e.jsx(Ce,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden md:inline",children:"Contact"})]}),e.jsxs(pe,{value:"address",className:"flex items-center gap-2 rounded-xl data-[state=active]:bg-background data-[state=active]:shadow-lg",children:[e.jsx(rs,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden md:inline",children:"Adres"})]}),e.jsxs(pe,{value:"business",className:"flex items-center gap-2 rounded-xl data-[state=active]:bg-background data-[state=active]:shadow-lg",children:[e.jsx(ts,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden md:inline",children:"Zakelijk"})]}),e.jsxs(pe,{value:"crm",className:"flex items-center gap-2 rounded-xl data-[state=active]:bg-background data-[state=active]:shadow-lg",children:[e.jsx(Ls,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden md:inline",children:"CRM"})]}),e.jsxs(pe,{value:"marketing",className:"flex items-center gap-2 rounded-xl data-[state=active]:bg-background data-[state=active]:shadow-lg",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden md:inline",children:"Marketing"})]}),e.jsxs(pe,{value:"invoices",className:"flex items-center gap-2 rounded-xl data-[state=active]:bg-background data-[state=active]:shadow-lg",children:[e.jsx(Ha,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden md:inline",children:"Facturen"})]}),e.jsxs(pe,{value:"system",className:"flex items-center gap-2 rounded-xl data-[state=active]:bg-background data-[state=active]:shadow-lg",children:[e.jsx(Bs,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden md:inline",children:"Systeem"})]}),e.jsxs(pe,{value:"chatbots",className:"flex items-center gap-2 rounded-xl data-[state=active]:bg-background data-[state=active]:shadow-lg",children:[e.jsx(ns,{className:"h-4 w-4"}),e.jsxs("span",{className:"hidden md:inline",children:["Lumen Assistenten (",re.length,")"]})]}),e.jsxs(pe,{value:"activity",className:"flex items-center gap-2 rounded-xl data-[state=active]:bg-background data-[state=active]:shadow-lg",children:[e.jsx(Ie,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden md:inline",children:"Activiteit"})]})]}),e.jsx(je,{value:"contact",className:"space-y-6 mt-6",children:e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-blue-500/5 via-trans
10parent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-blue-500 to-blue-600 shadow-lg shadow-blue-500/25",children:e.jsx(Ce,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Basis Contactgegevens"}),e.jsx(B,{children:"Persoonlijke informatie van de contactpersoon"})]})]})}),e.jsxs(V,{className:"relative space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"salutation",children:"Aanspreektitel"}),e.jsxs(X,{value:a.salutation,onValueChange:s=>x("salutation",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer"})}),e.jsxs(se,{children:[e.jsx(i,{value:"dhr",children:"Dhr."}),e.jsx(i,{value:"mevr",children:"Mevr."}),e.jsx(i,{value:"dr",children:"Dr."}),e.jsx(i,{value:"prof",children:"Prof."})]})]})]}),e.jsx(K,{id:"firstName",label:"Voornaam",icon:Ce,required:!0,placeholder:"Voornaam",value:a.firstName,onChange:s=>x("firstName",s)}),e.jsx(K,{id:"middleName",label:"Tussenvoegsel",placeholder:"van, de, etc.",value:a.middleName,onChange:s=>x("middleName",s)}),e.jsx(K,{id:"lastName",label:"Achternaam",icon:Ce,required:!0,placeholder:"Achternaam",value:a.lastName,onChange:s=>x("lastName",s)})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(K,{id:"jobTitle",label:"Functie",icon:Ga,placeholder:"Bijv. Marketing Manager",value:a.jobTitle,onChange:s=>x("jobTitle",s)}),e.jsx(K,{id:"department",label:"Afdeling",icon:Ua,placeholder:"Bijv. Marketing",value:a.department,onChange:s=>x("department",s)})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{className:"text-sm font-medium flex items-center gap-2",children:"E-mailadres"}),e.jsxs("div",{className:"relative group/input",children:[e.jsx(qe,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{value:o.email||"",disabled:!0,className:"pl-10 h-11 bg-muted/80 border-muted-foreground/20"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"E-mailadres kan niet worden gewijzigd"})]}),e.jsx(K,{id:"phoneFixed",label:"Telefoonnummer (Vast)",icon:qs,type:"tel",placeholder:"+31 20 1234567",value:a.phoneFixed,onChange:s=>x("phoneFixed",s)}),e.jsx(K,{id:"phoneMobile",label:"Mobiel nummer",icon:qs,type:"tel",placeholder:"+31 6 12345678",value:a.phoneMobile,onChange:s=>x("phoneMobile",s)})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(K,{id:"personalWebsite",label:"Website",icon:Qa,placeholder:"https://www.voorbeeld.nl",value:a.personalWebsite,onChange:s=>x("personalWebsite",s)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"preferredLanguage",children:"Voorkeurstaal"}),e.jsxs(X,{value:a.preferredLanguage,onValueChange:s=>x("preferredLanguage",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer taal"})}),e.jsxs(se,{children:[e.jsx(i,{value:"nl",children:"Nederlands"}),e.jsx(i,{value:"en",children:"Engels"}),e.jsx(i,{value:"de",children:"Duits"}),e.jsx(i,{value:"fr",children:"Frans"})]})]})]})]})]})]})}),e.jsx(je,{value:"address",className:"space-y-6 mt-6",children:e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-green-500/5 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-green-500 to-green-600 shadow-lg shadow-green-500/25",children:e.jsx(rs,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Adresgegevens"}),e.jsx(B,{children:"Vestiging- en factuuradres"})]})]})}),e.jsxs(V,{className:"relative space-y-6",children:[e.jsx(K,{id:"companyName",label:"Bedrijfsnaam",icon:ts,placeholder:"Naam van het bedrijf",value:a.companyName,onChange:s=>x("companyName",s)}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx("div",{className:"md:col-span-2",children:e.jsx(K,{id:"streetName",label:"Straatnaam",icon:rs,placeholder:"Straatnaam",value:a.streetName,onChange:s=>x("streetName",s)})}
10),e.jsx(K,{id:"houseNumber",label:"Huisnummer",placeholder:"123A",value:a.houseNumber,onChange:s=>x("houseNumber",s)})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(K,{id:"postalCode",label:"Postcode",placeholder:"1234 AB",value:a.postalCode,onChange:s=>x("postalCode",s)}),e.jsx(K,{id:"city",label:"Plaatsnaam",placeholder:"Amsterdam",value:a.city,onChange:s=>x("city",s)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"country",children:"Land"}),e.jsxs(X,{value:a.country,onValueChange:s=>x("country",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer land"})}),e.jsxs(se,{children:[e.jsx(i,{value:"Nederland",children:"Nederland"}),e.jsx(i,{value:"België",children:"België"}),e.jsx(i,{value:"Duitsland",children:"Duitsland"}),e.jsx(i,{value:"Frankrijk",children:"Frankrijk"}),e.jsx(i,{value:"Verenigd Koninkrijk",children:"Verenigd Koninkrijk"})]})]})]})]})]})]})}),e.jsx(je,{value:"business",className:"space-y-6 mt-6",children:e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-purple-500/5 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-purple-500 to-purple-600 shadow-lg shadow-purple-500/25",children:e.jsx(ts,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Zakelijke & Administratieve Gegevens"}),e.jsx(B,{children:"Fiscale en bedrijfsinformatie"})]})]})}),e.jsxs(V,{className:"relative space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(K,{id:"kvkNumber",label:"KvK-nummer",icon:Ja,placeholder:"12345678",value:a.kvkNumber,onChange:s=>x("kvkNumber",s)}),e.jsx(K,{id:"btwNumber",label:"BTW-nummer",icon:cs,placeholder:"NL123456789B01",value:a.btwNumber,onChange:s=>x("btwNumber",s)})]}),e.jsx(K,{id:"iban",label:"IBAN/Bankrekeningnummer",icon:$e,placeholder:"NL91 ABNA 0417 1643 00",value:a.iban,onChange:s=>x("iban",s)}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"industrySector",children:"Industrie/Sector"}),e.jsxs(X,{value:a.industrySector,onValueChange:s=>x("industrySector",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer sector"})}),e.jsxs(se,{children:[e.jsx(i,{value:"tech",children:"Technologie"}),e.jsx(i,{value:"finance",children:"Financiële diensten"}),e.jsx(i,{value:"healthcare",children:"Gezondheidszorg"}),e.jsx(i,{value:"retail",children:"Retail"}),e.jsx(i,{value:"manufacturing",children:"Productie"}),e.jsx(i,{value:"consulting",children:"Consultancy"}),e.jsx(i,{value:"marketing",children:"Marketing & Reclame"}),e.jsx(i,{value:"education",children:"Onderwijs"}),e.jsx(i,{value:"hospitality",children:"Horeca"}),e.jsx(i,{value:"other",children:"Overig"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"companySize",children:"Bedrijfsgrootte"}),e.jsxs(X,{value:a.companySize,onValueChange:s=>x("companySize",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer grootte"})}),e.jsxs(se,{children:[e.jsx(i,{value:"1",children:"1 persoon (ZZP)"}),e.jsx(i,{value:"2-10",children:"2-10 medewerkers"}),e.jsx(i,{value:"11-50",children:"11-50 medewerkers"}),e.jsx(i,{value:"51-200",children:"51-200 medewerkers"}),e.jsx(i,{value:"201-500",children:"201-500 medewerkers"}),e.jsx(i,{value:"500+",children:"500+ medewerkers"})]})]})]})]})]})]})}),e.jsx(je,{value:"crm",className:"space-y-6 mt-6",children:e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-orange-500/5 via-trans
10parent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-orange-500 to-orange-600 shadow-lg shadow-orange-500/25",children:e.jsx(Ls,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Relatiebeheer (CRM)"}),e.jsx(B,{children:"Klantrelatie en segmentatie"})]})]})}),e.jsxs(V,{className:"relative space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"relationStatus",children:"Relatiestatus"}),e.jsxs(X,{value:a.relationStatus,onValueChange:s=>x("relationStatus",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer status"})}),e.jsxs(se,{children:[e.jsx(i,{value:"lead",children:"Lead"}),e.jsx(i,{value:"prospect",children:"Prospect"}),e.jsx(i,{value:"active",children:"Actieve Klant"}),e.jsx(i,{value:"inactive",children:"Inactieve Klant"}),e.jsx(i,{value:"former",children:"Voormalige Klant"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"customerSegment",children:"Type Klant / Segmentatie"}),e.jsxs(X,{value:a.customerSegment,onValueChange:s=>x("customerSegment",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer segment"})}),e.jsxs(se,{children:[e.jsx(i,{value:"a-klant",children:"A-klant (Premium)"}),e.jsx(i,{value:"b-klant",children:"B-klant (Standaard)"}),e.jsx(i,{value:"c-klant",children:"C-klant (Basis)"}),e.jsx(i,{value:"reseller",children:"Reseller"}),e.jsx(i,{value:"partner",children:"Partner"}),e.jsx(i,{value:"eindgebruiker",children:"Eindgebruiker"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"leadSource",children:"Bron van Lead/Klant"}),e.jsxs(X,{value:a.leadSource,onValueChange:s=>x("leadSource",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer bron"})}),e.jsxs(se,{children:[e.jsx(i,{value:"google",children:"Google"}),e.jsx(i,{value:"linkedin",children:"LinkedIn"}),e.jsx(i,{value:"beurs",children:"Beurs/Event"}),e.jsx(i,{value:"verwijzing",children:"Verwijzing"}),e.jsx(i,{value:"cold-outreach",children:"Cold Outreach"}),e.jsx(i,{value:"website",children:"Website"}),e.jsx(i,{value:"email",children:"E-mail campagne"}),e.jsx(i,{value:"other",children:"Overig"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"communicationFrequency",children:"Gewenste communicatiefrequentie"}),e.jsxs(X,{value:a.communicationFrequency,onValueChange:s=>x("communicationFrequency",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer frequentie"})}),e.jsxs(se,{children:[e.jsx(i,{value:"weekly",children:"Wekelijks"}),e.jsx(i,{value:"biweekly",children:"Tweewekelijks"}),e.jsx(i,{value:"monthly",children:"Maandelijks"}),e.jsx(i,{value:"quarterly",children:"Per kwartaal"}),e.jsx(i,{value:"minimal",children:"Minimaal"})]})]})]})]})]})]})}),e.jsx(je,{value:"marketing",className:"space-y-6 mt-6",children:e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-pink-500/5 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-pink-500 to-pink-600 shadow-lg shadow-pink-500/25",children:e.jsx(Te,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Marketing en Voorkeuren"}),e.jsx(B,{children:"Communicatievoorkeuren en toestemmingen"})]})]})}),e.jsxs(V,{className:"relative space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{className:"text-base font-medium",children:"Toestemmingen (Opt-in)"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center space-x-3 p-4 rounded-xl bg-muted/30 border border-muted-foreground
10/10 hover:bg-muted/50 transition-colors",children:[e.jsx(is,{id:"emailMarketingConsent",checked:a.emailMarketingConsent,onCheckedChange:s=>x("emailMarketingConsent",s)}),e.jsxs("div",{className:"flex-1",children:[e.jsx(b,{htmlFor:"emailMarketingConsent",className:"font-medium cursor-pointer",children:"E-mail Marketing"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Mag nieuwsbrieven en promoties ontvangen via e-mail"})]})]}),e.jsxs("div",{className:"flex items-center space-x-3 p-4 rounded-xl bg-muted/30 border border-muted-foreground/10 hover:bg-muted/50 transition-colors",children:[e.jsx(is,{id:"phoneContactConsent",checked:a.phoneContactConsent,onCheckedChange:s=>x("phoneContactConsent",s)}),e.jsxs("div",{className:"flex-1",children:[e.jsx(b,{htmlFor:"phoneContactConsent",className:"font-medium cursor-pointer",children:"Telefonisch Contact"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Mag telefonisch worden benaderd voor commerciële doeleinden"})]})]}),e.jsxs("div",{className:"flex items-center space-x-3 p-4 rounded-xl bg-muted/30 border border-muted-foreground/10 hover:bg-muted/50 transition-colors",children:[e.jsx(is,{id:"postalConsent",checked:a.postalConsent,onCheckedChange:s=>x("postalConsent",s)}),e.jsxs("div",{className:"flex-1",children:[e.jsx(b,{htmlFor:"postalConsent",className:"font-medium cursor-pointer",children:"Post/Nieuwsbrief"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Mag fysieke post en nieuwsbrieven ontvangen"})]})]})]})]}),e.jsx("div",{className:"pt-6 border-t border-muted-foreground/10",children:e.jsx(K,{id:"linkedinProfile",label:"LinkedIn Profiel",icon:Za,placeholder:"https://linkedin.com/in/gebruikersnaam",value:a.linkedinProfile,onChange:s=>x("linkedinProfile",s)})})]})]})}),e.jsxs(je,{value:"invoices",children:[W&&o&&e.jsx(zr,{userId:o.id,userEmail:o.email||"",userName:Xe}),!W&&e.jsx(F,{children:e.jsx(V,{className:"py-8 text-center text-muted-foreground",children:"Alleen superadmins hebben toegang tot factuurinformatie."})})]}),e.jsxs(je,{value:"system",className:"space-y-6 mt-6",children:[e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-purple-500/5 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-purple-500 to-purple-600 shadow-lg shadow-purple-500/25",children:e.jsx(Is,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Rol & Rechten"}),e.jsx(B,{children:"Bepaal de toegangsrechten voor deze klant"})]})]})}),e.jsx(V,{className:"relative space-y-6",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"role",className:"text-sm font-medium",children:"Gebruikersrol"}),e.jsxs(X,{value:a.role,onValueChange:s=>x("role",s),children:[e.jsx(Y,{className:"h-12 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer een rol"})}),e.jsxs(se,{children:[e.jsx(i,{value:"user",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ce,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-medium",children:"Gebruiker"})]}),e.jsx("span",{className:"text-xs text-muted-foreground ml-7",children:"Standaard toegang"})]})}),e.jsx(i,{value:"admin",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Is,{className:"h-4 w-4 text-orange-500"}),e.jsx("span",{className:"font-medium",children:"Admin"})]}),e.jsx("span",{className:"text-xs text-muted-foreground ml-7",children:"Beheerdersrechten"})]})}),e.jsx(i,{value:"reseller",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Os,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"font-medium",children:"Reseller"})]}),e.jsx("span",{className:"text-xs text-muted-foreground ml-7",children:"Partner toegang"})]})}),e.jsx(i,{value:"superadmin",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Vs,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{className:"font-medium",children:"Super Admin"})]}),e.jsx("span",{className:"text-xs text-muted-foreground ml-7",children:"Volledige toegang"})]})})]})]})]})})]}),e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-green-500/5 via-trans
10parent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-green-500 to-green-600 shadow-lg shadow-green-500/25",children:e.jsx($e,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Plan"}),e.jsx(B,{children:"Beheer het plan van deze klant"})]})]})}),e.jsxs(V,{className:"relative space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-xl bg-muted/50 border border-muted-foreground/10",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(b,{className:"text-base font-medium",children:"Plan actief"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:_?`Gestart op ${ve(new Date(_.started_at),"d MMMM yyyy",{locale:me})}`:"Nog geen plan"})]}),e.jsx(Xa,{checked:n,onCheckedChange:N})]}),n&&e.jsxs("div",{className:"space-y-4 animate-in slide-in-from-top-2 duration-300",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"planId",children:"Plan"}),e.jsxs(X,{value:a.planId,onValueChange:s=>{x("planId",s);const r=H==null?void 0:H.find(m=>m.id===s);r&&x("mrrAmount",r.price_monthly)},children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer een plan"})}),e.jsx(se,{children:H==null?void 0:H.filter(s=>s.is_active).map(s=>e.jsx(i,{value:s.id,children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsxs("span",{className:"text-muted-foreground",children:["⬠",s.price_monthly.toLocaleString("nl-NL",{minimumFractionDigits:2,maximumFractionDigits:2}),"/mnd"]})]})},s.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"subscriptionStatus",children:"Status"}),e.jsxs(X,{value:a.subscriptionStatus,onValueChange:s=>x("subscriptionStatus",s),children:[e.jsx(Y,{className:"h-11 bg-muted/50 border-muted-foreground/20",children:e.jsx(ee,{placeholder:"Selecteer status"})}),e.jsxs(se,{children:[e.jsx(i,{value:"active",children:"Actief"}),e.jsx(i,{value:"inactive",children:"Inactief"}),e.jsx(i,{value:"cancelled",children:"Geannuleerd"})]})]})]})]})]})]}),e.jsx(Rr,{userId:t,subscription:_?{id:_.id,credits_used:(l=_.credits_used)!=null?l:0,pricing_tier_id:_.pricing_tier_id}:null,creditsLimit:d,isLoading:xe||fe,onCreditsUpdated:()=>{Ze()}}),e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-cyan-500/5 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-cyan-500 to-cyan-600 shadow-lg shadow-cyan-500/25",children:e.jsx(Bs,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Systeem- en Gebruikersgegevens"}),e.jsx(B,{children:"Inloggegevens en systeeminformatie"})]})]})}),e.jsxs(V,{className:"relative space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(K,{id:"username",label:"Gebruikersnaam",icon:Ce,placeholder:"Optionele gebruikersnaam",value:a.username,onChange:s=>x("username",s)}),e.jsx("div",{className:"p-4 rounded-xl bg-muted/30 border border-muted-foreground/10",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(us,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Laatste login"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:o.last_login_date?Xs(new Date(o.last_login_date),{addSuffix:!0,locale:me}):"Nog niet ingelogd"})]})]})})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-muted-foreground/10 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Oe,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Wachtwoord wijzigen"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Stel een nieuw w
10achtwoord in voor deze gebruiker"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{type:"password",placeholder:"Nieuw wachtwoord",value:Be,onChange:s=>Ue(s.target.value),className:"h-10 bg-background border-muted-foreground/20"}),e.jsx(q,{type:"button",variant:"outline",size:"sm",onClick:va,className:"h-10 px-3",title:"Genereer een sterk wachtwoord",children:e.jsx(Vs,{className:"h-4 w-4"})}),e.jsx(q,{type:"button",variant:"outline",size:"sm",onClick:ba,disabled:!Be||ps,className:"h-10 px-4",children:ps?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):"Wijzigen"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"notes",children:"Notities/Opmerkingen"}),e.jsx(Ya,{id:"notes",placeholder:"Interne notities over deze klant...",value:a.notes,onChange:s=>x("notes",s.target.value),rows:4,className:"bg-muted/50 border-muted-foreground/20 focus:border-primary focus:bg-background transition-all resize-none"})]})]})]}),e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-orange-500/5 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-orange-500 to-orange-600 shadow-lg shadow-orange-500/25",children:e.jsx(ls,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Push Notificaties"}),e.jsx(B,{children:"VAPID keys voor Web Push notificaties"})]})]})}),e.jsxs(V,{className:"relative space-y-6",children:[e.jsx("div",{className:"p-4 rounded-xl bg-muted/30 border border-muted-foreground/10 space-y-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Oe,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"VAPID Keys Configuratie"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Genereer keys via"," ",e.jsxs("a",{href:"https://vapidkeys.com/",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline inline-flex items-center gap-1",children:["vapidkeys.com",e.jsx(Rs,{className:"h-3 w-3"})]})]})]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"vapidPublicKey",className:"text-sm font-medium flex items-center gap-2",children:["Public Key",a.vapidPublicKey&&e.jsx(M,{variant:"outline",className:"text-xs bg-green-500/10 text-green-500 border-green-500/20",children:"Geconfigureerd"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(ae,{id:"vapidPublicKey",placeholder:"Plak hier de VAPID public key...",value:a.vapidPublicKey,onChange:s=>x("vapidPublicKey",s.target.value),className:"h-11 bg-muted/50 border-muted-foreground/20 focus:border-primary focus:bg-background transition-all pr-10 font-mono text-xs"}),a.vapidPublicKey&&e.jsx(q,{type:"button",variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 -translate-y-1/2 h-8 w-8",onClick:()=>{navigator.clipboard.writeText(a.vapidPublicKey),f({title:"Gekopieerd",description:"Public key gekopieerd naar klembord"})},children:e.jsx(er,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"vapidPrivateKey",className:"text-sm font-medium flex items-center gap-2",children:["Private Key",a.vapidPrivateKey&&e.jsx(M,{variant:"outline",className:"text-xs bg-green-500/10 text-green-500 border-green-500/20",children:"Geconfigureerd"})]}),e.jsx("div",{className:"relative",children:e.jsx(ae,{id:"vapidPrivateKey",type:"password",placeholder:"Plak hier de VAPID private key...",value:a.vapidPrivateKey,onChange:s=>x("vapidPrivateKey",s.target.value),className:"h-11 bg-muted/50 border-muted-foreground/20 focus:border-primary focus:bg-background transition-all font-mono text-xs"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Deze key wordt versleuteld opgeslagen en is alleen zichtbaar voor beheerders"})]})]}),a.vapidPublicKey&&a.vapidPrivateKey&&e.jsxs("div",{className:"p-3 rounded-lg bg-green-500/10 border border-green-500/20",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-500",children:[e.jsx(ss,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Push notificaties zijn geconfigureerd"})]}),e.jsx("p",{className:"text-xs text-green-500/80 mt-1",children:"Deze gebruiker kan nu push notificaties versturen via de Target Suite"})]}),(!a.vapidPublicKey||!a.vapidPrivateKey)&&e.jsxs("div",{className:"p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[e.jsxs("div",{className:"flex items-center gap-2 text-amber-500",children:[e.jsx(ls,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:"VAPID keys niet geconfigureerd"})]}),e.jsx("p",{className:"text-xs text-amber-500/80 mt-1",children:"Zonder VAPID keys kunnen geen push notificaties worden verstuurd"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{type:"button",variant:"outline",onClick:async()=>{vs(!0);try{const{data:s,error:r}=await c.functions.invoke("register-push-subscription",{body:{action:"check",owner_id:t}});if(r)throw r;if(s!=null&&s.success&&(s!=null&&s.configured))f({title:"VAPID Keys Geldig",description:"Keys zijn correct geconfigureerd en klaar voor gebruik."});else throw new Error((s==null?void 0:s.error)||"VAPID configuratie niet gevonden")}catch(s){f({title:"VAPID Test Mislukt",description:s.message||"Kon VAPID keys niet valideren.",variant:"destructive"})}finally{vs(!1)}},disabled:bs,className:"flex-1",children:bs?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Testen..."]}):e.jsxs(e.Fragment,{children:[e.jsx(gs,{className:"mr-2 h-4 w-4"}),"Test VAPID Keys"]})}),e.jsx(q,{type:"button",variant:"secondary",onClick:async()=>{Ns(!0);try{const{data:s,error:r}=await c.functions.invoke("send-push-notification",{body:{owner_id:t,title:"
10𧪠Test Push Notificatie",body:"Dit is een test push van het beheerpaneel. Als je dit ziet, werkt alles!",url:"/",generate_with_ai:!1}});if(r)throw r;if(s!=null&&s.success)s.sent>0?f({title:"Test Push Verstuurd",description:`${s.sent} van ${s.total} subscriber(s) bereikt.`}):f({title:"Geen Subscribers",description:"Er zijn nog geen actieve push subscribers voor deze gebruiker.",variant:"destructive"});else throw new Error((s==null?void 0:s.error)||"Kon push niet versturen")}catch(s){f({title:"Push Versturen Mislukt",description:s.message||"Kon test push niet versturen.",variant:"destructive"})}finally{Ns(!1)}},disabled:fs||!a.vapidPublicKey||!a.vapidPrivateKey,className:"flex-1",children:fs?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Versturen..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ls,{className:"mr-2 h-4 w-4"}),"Test Push Versturen"]})})]})]})]}),e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-orange-500/5 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-orange-500 to-orange-600 shadow-lg shadow-orange-500/25",children:e.jsx(sr,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"Opslag"}),e.jsx(B,{children:"Opslaggebruik en limiet op Cloudflare R2"})]})]})}),e.jsxs(V,{className:"relative space-y-4",children:[ie?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Verbruik"}),e.jsxs("span",{className:"font-medium",children:[ie.used_mb.toFixed(1)," MB / ",ie.limit_mb," MB (",ie.usage_pct.toFixed(0),"%)"]})]}),e.jsx(ar,{value:Math.min(ie.usage_pct,100),className:`h-2.5 ${ie.usage_pct>=100?"[&>div]:bg-destructive":ie.usage_pct>=90?"[&>div]:bg-orange-500":""}`})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-border/40 p-3 text-center",children:[e.jsx(rr,{className:"h-4 w-4 mx-auto mb-1 text-muted-foreground"}),e.jsxs("p",{className:"text-sm font-semibold",children:[ie.images_mb.toFixed(1)," MB"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Afbeeldingen"})]}),e.jsxs("div",{className:"rounded-lg border border-border/40 p-3 text-center",children:[e.jsx(Mr,{className:"h-4 w-4 mx-auto mb-1 text-muted-foreground"}),e.jsxs("p",{className:"text-sm font-semibold",children:[ie.docs_mb.toFixed(2)," MB"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Documenten"})]}),e.jsxs("div",{className:"rounded-lg border border-border/40 p-3 text-center",children:[e.jsx(tr,{className:"h-4 w-4 mx-auto mb-1 text-muted-foreground"}),e.jsxs("p",{className:"text-sm font-semibold",children:[ie.prompts_mb.toFixed(2)," MB"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Prompts"})]})]}),ie.warning&&e.jsx("div",{className:"rounded-md bg-destructive/10 border border-destructive/20 p-2.5",children:e.jsx("p",{className:"text-xs text-destructive font-medium",children:"â ï¸ Deze gebruiker nadert de opslaglimiet!"})})]}):e.jsxs("div",{className:"flex items-center justify-center py-4 text-sm text-muted-foreground",children:[e.jsx(ce,{className:"h-4 w-4 animate-spin mr-2"}),"Opslaggegevens laden..."]}),e.jsxs("div",{className:"space-y-2 pt-2 border-t border-border/40",children:[e.jsx(b,{htmlFor:"storage-limit-edit",children:"Aangepaste opslaglimiet (MB)"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{id:"storage-limit-edit",type:"number",placeholder:"Bijv. 500, 1024, 10240...",value:Qe,onChange:s=>ws(s.target.value),className:"flex-1"}),e.jsx(q,{onClick:ha,disabled:_s,size:"sm",children:_s?e.jsx(ce,{className:"h-4 w-4 animate-spin"}):e.jsx(Ws,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Bijv: 500 = 500 MB, 10240 = 10 GB. Laat leeg voor tier/batch-standaard."})]})]})]}),e.jsxs(F,{className:"group relative overflow-hidden border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-purple-500/5 via-trans
10parent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsx(E,{className:"relative",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-purple-500 to-purple-600 shadow-lg shadow-purple-500/25",children:e.jsx(qe,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xl",children:"E-mail Provider"}),e.jsx(B,{children:"Mailgun integratie voor e-mail marketing"})]})]})}),e.jsxs(V,{className:"relative space-y-6",children:[e.jsx("div",{className:"p-4 rounded-xl bg-muted/30 border border-muted-foreground/10 space-y-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Oe,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"Mailgun API Configuratie"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Maak een API key aan via"," ",e.jsxs("a",{href:"https://app.mailgun.com/settings/api_security",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline inline-flex items-center gap-1",children:["Mailgun Dashboard",e.jsx(Rs,{className:"h-3 w-3"})]})]})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"mailgunApiKey",className:"text-sm font-medium flex items-center gap-2",children:["API Key",a.mailgunApiKey&&e.jsx(M,{variant:"outline",className:"text-xs bg-green-500/10 text-green-500 border-green-500/20",children:"Geconfigureerd"})]}),e.jsx(ae,{id:"mailgunApiKey",type:"password",placeholder:"key-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",value:a.mailgunApiKey,onChange:s=>x("mailgunApiKey",s.target.value),className:"h-11 bg-muted/50 border-muted-foreground/20 focus:border-primary focus:bg-background transition-all font-mono text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"mailgunDomain",className:"text-sm font-medium flex items-center gap-2",children:["Sending Domain",a.mailgunDomain&&e.jsx(M,{variant:"outline",className:"text-xs bg-green-500/10 text-green-500 border-green-500/20",children:"Geconfigureerd"})]}),e.jsx(ae,{id:"mailgunDomain",placeholder:"mg.example.com",value:a.mailgunDomain,onChange:s=>x("mailgunDomain",s.target.value),className:"h-11 bg-muted/50 border-muted-foreground/20 focus:border-primary focus:bg-background transition-all"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"mailgunFromEmail",className:"text-sm font-medium",children:"Afzender E-mail"}),e.jsx(ae,{id:"mailgunFromEmail",type:"email",placeholder:"[email protected]",value:a.mailgunFromEmail,onChange:s=>x("mailgunFromEmail",s.target.value),className:"h-11 bg-muted/50 border-muted-foreground/20 focus:border-primary focus:bg-background transition-all"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"mailgunFromName",className:"text-sm font-medium",children:"Afzender Naam"}),e.jsx(ae,{id:"mailgunFromName",placeholder:"Bedrijfsnaam",value:a.mailgunFromName,onChange:s=>x("mailgunFromName",s.target.value),className:"h-11 bg-muted/50 border-muted-foreground/20 focus:border-primary focus:bg-background transition-all"})]})]}),a.mailgunApiKey&&a.mailgunDomain&&e.jsxs("div",{className:"p-3 rounded-lg bg-green-500/10 border border-green-500/20",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-500",children:[e.jsx(ss,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Mailgun is geconfigureerd"})]}),e.jsx("p",{className:"text-xs text-green-500/80 mt-1",children:"Deze gebruiker kan nu e-mails versturen via de Target Suite"})]}),(!a.mailgunApiKey||!a.mailgunDomain)&&e.jsxs("div",{className:"p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[e.jsxs("div",{className:"flex items-center gap-2 text-amber-500",children:[e.jsx(qe,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Mailgun niet geconfigureerd"})]}),e.jsx("p",{className:"text-xs text-amber-500/80 mt-1",children:"Zonder Mailgun configuratie kunnen geen marketing e-mails worden verstuurd"})]})]})]})]}),e.jsx(je,{value:"chatbots",className:"space-y-6 mt-6",children:e.jsxs(F,{className:"border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx(E,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-cyan-500 to-cyan-600 shadow-lg shadow-cyan-500/25",children:e.jsx(ns,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsxs(L,{className:"text-xl",children:["Lumen Assistenten (",re.length,")"]}),e.jsx(B,{children:"Alle Lumen Assistenten van deze klant"})]})]})}),e.jsx(V,{children:re.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(ns,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Deze klant heeft nog geen Lumen Assistenten"})]}):e.jsxs(na,{children:[e.jsx(ia,{children:e.jsxs(Ge,{children:[e.jsx(de,{children:"Naam"}),e.jsx(de,{children:"Beschrijving"}),e.jsx(de,{children:"Status"}),e.jsx(de,{children:"Aangemaakt"})]})}),e.jsx(la,{children:re.map(s=>e.jsxs(Ge,{children:[e.jsx(oe,{className:"font-medium",children:s.name}),e.jsx(oe,{className:"text-muted-foreground",children:s.description||"-"}),e.jsx(oe,{children:e.jsx(M,{variant:s.is_active?"default":"secondary",children:s.is_active?"Actief":"Inactief"})}),e.jsx(oe,{className:"text-muted-foreground",children:ve(new Date(s.created_at),"d MMM yyyy",{locale:me})})]},s.id))})]})})]})}),e.jsx(je,{value:"activity",className:"space-y-6 mt-6",children:e.jsxs(F,{className:"border-primary/10 shadow-xl shadow-primary/5",children:[e.jsx(E,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-gradient-to-br from-amber-500 to-amber-600 shadow-lg shadow-amber-500/25",children:e.jsx(Ie,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsxs(L,{className:"text-xl",children:["Activiteit (",ye.length,")"]}),e.jsx(B,{children:"Recente activiteit van deze klant"})]})]})}),e.jsx(V,{children:ye.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(Ie,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Nog geen activiteit gelogd"})]}):e.jsx(ta,{className:"h-[400px]",children:e.jsx("div",{className:"space-y-3",children:ye.map(s=>e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg hover:bg-muted/50",children:[e.jsx("div",{className:`p-2 rounded-lg ${_a(s.action_type)}`,children:wa(s.action_type)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:s.action_description}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Xs(new Date(s.created_at),{addSuffix:!0,locale:me})})]})]},s.id))})})})]})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 p-6 rounded-2xl bg-muted/30 border border-muted-foreground
10/10",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:'Wijzigingen worden pas opgeslagen wanneer je op "Opslaan" klikt'}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(q,{type:"button",variant:"outline",onClick:()=>h("/dashboard/tenant-management"),children:"Annuleren"}),e.jsxs(q,{onClick:fa,disabled:Ne,children:[e.jsx(Ws,{className:"mr-2 h-4 w-4"}),Ne?"Opslaan...":"Wijzigingen Opslaan"]})]})]})]})}),e.jsx($s,{open:R,onOpenChange:k,children:e.jsxs(Ts,{children:[e.jsxs(Hs,{children:[e.jsx(Gs,{children:"Klant verwijderen"}),e.jsxs(Us,{children:["Weet je zeker dat je ",e.jsx("strong",{children:Xe})," wilt verwijderen? Dit verwijdert ook alle bijbehorende Lumen Assistenten, gesprekken en gegevens. Deze actie kan niet ongedaan worden gemaakt."]})]}),e.jsxs(Qs,{children:[e.jsx(Js,{disabled:$,children:"Annuleren"}),e.jsx(Zs,{onClick:Na,disabled:$,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:$?"Verwijderen...":"Verwijderen"})]})]})}),e.jsx($s,{open:da,onOpenChange:s=>!s&&Cs(),children:e.jsxs(Ts,{children:[e.jsxs(Hs,{children:[e.jsx(Gs,{children:"Niet-opgeslagen wijzigingen"}),e.jsx(Us,{children:"Je hebt niet-opgeslagen wijzigingen. Weet je zeker dat je deze pagina wilt verlaten? Je wijzigingen gaan verloren."})]}),e.jsxs(Qs,{children:[e.jsx(Js,{onClick:Cs,children:"Blijven"}),e.jsx(Zs,{onClick:oa,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Verlaten"})]})]})})]})};export{mt 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.