1import{c as J,b as B,r as n,j as e,K as L,I as H,Z as W,B as $,g as X,s as j,W as C,q as Q,R as U,U as Y,S as ee,X as te}from"./index-BhaiL37n.js";import{D as re,a as ae,b as se,c as ne,d as oe}from"./dialog-DzCnG5qt.js";import{L as S}from"./label-Cdz8ycwG.js";import{T as V}from"./textarea-CGjUhreZ.js";import{A as q}from"./AllowedOwnersSelect-DyS42H7V.js";import{E as G}from"./eye-BY8MlSQZ.js";import{C as ie}from"./copy-Cq9pZcWN.js";import{T as K}from"./trash-2-at3KMSXG.js";import{E as le}from"./external-link-C33pQRSI.js";import{L as de}from"./loader-circle-DXegU5nq.js";import{u as ce}from"./useFITScan-DR8XS2Jy.js";import{A as me,a as xe,b as ue,c as pe,d as he,e as ge,f as fe,g as be}from"./alert-dialog-DrF_TRN9.js";import{P as je}from"./plus-BljO0GmB.js";import{T as ve}from"./trending-up-DO5EZ12x.js";import{C as ye}from"./calendar-Dkemo01P.js";import{A as we}from"./arrow-right-C6Al-lik.js";import{L as Ne}from"./link-BbGDhWaq.js";import"./popover-B2_jiIDO.js";import"./checkbox-BBOUCeuP.js";import"./index-CYMyvI6y.js";import"./check-B2pBSRyQ.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ke=J("Share2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]);function _e({open:l,onOpenChange:T,scanId:v,scanLabel:D}){const{toast:i}=B(),[p,g]=n.useState([]),[h,y]=n.useState(!1),[x,M]=n.useState(!1),[d,f]=n.useState(""),[c,w]=n.useState(""),[A,O]=n.useState("nl"),[I,N]=n.useState(""),[u,k]=n.useState(""),[F,m]=n.useState([]),_=async()=>{y(!0);const{data:r,error:s}=await j.from("fit_scan_shares").select("id, recipient_name, recipient_email, share_token, language, sent_at, first_viewed_at, last_viewed_at, view_count, allowed_owner_ids").eq("scan_id",v).order("sent_at",{ascending:!1});!s&&r&&g(r),y(!1)};n.useEffect(()=>{l&&_()},[l,v]);const t=async r=>{if(r.size>5e6){i({title:"Bestand te groot",description:"Maximaal 5 MB.",variant:"destructive"});return}const s=await r.text();k(s),i({title:"HTML geladen",description:`${r.name} (${Math.round(r.size/1024)} KB)`})},a=async()=>{if(!d.trim()||!c.trim()||!u.trim()){i({title:"Vul alle verplichte velden in",description:"Naam, e-mail en HTML-rapport zijn vereist.",variant:"destructive"});return}M(!0);try{const{data:{session:r}}=await j.auth.getSession(),s=await fetch("https://mqbbjseruaagvhwqxouw.supabase.co/functions/v1/share-fit-scan",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${(r==null?void 0:r.access_token)??""}`},body:JSON.stringify({scan_id:v,recipient_name:d.trim(),recipient_email:c.trim(),language:A,custom_message:I.trim()||null,html_content:u,allowed_owner_ids:F})}),z=await s.json();s.ok?(i({title:"Verstuurd",description:`Link ge-e-maild naar ${c}.`}),f(""),w(""),N(""),k(""),_()):i({title:"Versturen mislukt",description:z.error||"Probeer het opnieuw.",variant:"destructive"})}catch{i({title:"Versturen mislukt",description:"Netwerkfout.",variant:"destructive"})}M(!1)},o=r=>{const s=`${window.location.origin}/scan-rapport/${r}`;navigator.clipboard.writeText(s),i({title:"Link gekopieerd",description:s})},b=async r=>{if(!confirm("Deze deellink intrekken? De ontvanger kan het rapport daarna niet meer openen."))return;const{error:s}=await j.from("fit_scan_shares").delete().eq("id",r);s?i({title:"Intrekken mislukt",variant:"destructive"}):(i({title:"Ingetrokken"}),_())},P=async(r,s)=>{const z=p;g(Z=>Z.map(E=>E.id===r?{...E,allowed_owner_ids:s}:E));const{error:R}=await j.from("fit_scan_shares").update({allowed_owner_ids:s}).eq("id",r);R&&(g(z),i({title:"Toegang opslaan mislukt",description:R.message,variant:"destructive"}))};return e.jsx(re,{open:l,onOpenChange:T,children:e.jsxs(ae,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(se,{children:[e.jsxs(ne,{children:["Scan delen â ",D]}),e.jsx(oe,{children:"Stuur deze scan via een beveiligde link. De ontvanger moet zijn/haar e-mailadres bevestigen om het rapport te openen."})]}),p.length>0&&e.jsx("div",{className:"border rounded-lg divide-y",children:p.map(r=>e.jsxs("div",{className:"p-3 flex items-center gap-3 text-sm",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"font-medium truncate",children:[r.recipient_name," ",e.jsxs("span",{className:"text-muted-foreground font-normal",children:["· ",r.recipient_email]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5 flex items-center gap-3 flex-wrap",children:[e.jsxs("span",{children:["Verzonden ",L(new Date(r.sent_at),"d MMM yyyy HH:mm",{locale:C})]}),r.first_viewed_at?e.jsxs("span",{className:"inline-flex items-center gap-1 text-emerald-700",children:[e.jsx(G,{className:"h-3 w-3"}),r.view_count,"à bekeken · laatst ",L(new Date(r.last_viewed_at),"d MMM HH:mm",{locale:C})]}):e.jsx("span",{className:"text-amber-700",children:"Nog niet geopend"})]})]}),e.jsx(q,{value:r.allowed_owner_ids||[],onChange:s=>P(r.id,s)}),e.jsx("button",{onClick:()=>
6o(r.share_token),title:"Link kopiëren",className:"p-2 rounded hover:bg-muted",children:e.jsx(ie,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>b(r.id),title:"Intrekken",className:"p-2 rounded hover:bg-destructive/10 text-destructive",children:e.jsx(K,{className:"h-4 w-4"})})]},r.id))}),h&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ladenâ¦"}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsx("h3",{className:"font-medium",children:"Nieuwe deellink"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(S,{htmlFor:"rname",children:"Naam contactpersoon *"}),e.jsx(H,{id:"rname",value:d,onChange:r=>f(r.target.value),placeholder:"Anna Janssens"})]}),e.jsxs("div",{children:[e.jsx(S,{htmlFor:"remail",children:"E-mail *"}),e.jsx(H,{id:"remail",type:"email",value:c,onChange:r=>w(r.target.value),placeholder:"[email protected]"})]})]}),e.jsxs("div",{children:[e.jsx(S,{children:"Taal"}),e.jsx("div",{className:"flex gap-2 mt-1",children:["nl","en"].map(r=>e.jsx("button",{type:"button",onClick:()=>O(r),className:`px-3 py-1.5 rounded border text-sm ${A===r?"bg-primary text-primary-foreground border-primary":"border-border hover:border-primary/40"}`,children:r==="nl"?"Nederlands":"English"},r))})]}),e.jsxs("div",{children:[e.jsx(S,{htmlFor:"msg",children:"Persoonlijk bericht (optioneel)"}),e.jsx(V,{id:"msg",value:I,onChange:r=>N(r.target.value),rows:3,placeholder:"Een korte intro die in de e-mail komt te staan."})]}),e.jsxs("div",{children:[e.jsx(S,{htmlFor:"html",children:"HTML-rapport *"}),e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsxs("label",{className:"inline-flex items-center gap-2 px-3 py-1.5 border rounded text-sm cursor-pointer hover:bg-muted",children:[e.jsx(W,{className:"h-4 w-4"})," .html bestand kiezen",e.jsx("input",{type:"file",accept:".html,text/html",className:"hidden",onChange:r=>{var s;return((s=r.target.files)==null?void 0:s[0])&&t(r.target.files[0])}})]}),u&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[Math.round(u.length/1024)," KB geladen"]})]}),e.jsx(V,{id:"html",value:u,onChange:r=>k(r.target.value),rows:6,placeholder:"⦠of plak hier de volledige HTML van het rapport (incl. <html>, <head>, <body>).",className:"font-mono text-xs"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Zichtbaar voor:"}),e.jsx(q,{value:F,onChange:m})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx($,{variant:"outline",onClick:()=>T(!1),disabled:x,children:"Annuleren"}),e.jsxs($,{type:"button",variant:"outline",className:"gap-2",disabled:!u.trim(),onClick:()=>{const r=new Blob([u],{type:"text/html;charset=utf-8"}),s=URL.createObjectURL(r);window.open(s,"_blank","noopener,noreferrer"),setTimeout(()=>URL.revokeObjectURL(s),6e4)},children:[e.jsx(le,{className:"h-4 w-4"})," Voorbeeld"]}),e.jsxs($,{onClick:a,disabled:x,className:"gap-2",children:[x?e.jsx(de,{className:"h-4 w-4 animate-spin"}):e.jsx(X,{className:"h-4 w-4"}),"Versturen"]})]})]})]})]})})}function Se(l){return l<=30?"text-amber-600 bg-amber-50 border-amber-200":l<=60?"text-primary bg-primary/10 border-primary/20":"text-emerald-600 bg-emerald-50 border-emerald-200"}function Le(l){return l<=30?"Laag veld":l<=60?"Ontwikkelend":"Sterk veld"}const Ce=[{value:"all",label:"Alle"},{value:"low",label:"Laag veld (â¤30)"},{value:"mid",label:"Ontwikkelend (31-60)"},{value:"high",label:"Sterk veld (>60)"}];function We(){const{listScans:l,deleteScan:T,loading:v}=ce(),{toast:D}=B(),i=Q(),[p,g]=n.useState([]),[h,y]=n.useState(""),[x,M]=n.useState("all"),[d,f]=n.useState(null),[c,w]=n.useState(null),[A,O]=n.useState(null),[I,N]=n.useState(null),u=async t=>{O(t);const{data:a,error:o}=await j.from("fit_scan_shares").select("html_content").eq("scan_id",t).order("sent_at",{ascending:!1}).limit(1).maybeSingle();if(O(null),o||!(a!=null&&a.html_content)){D({title:"Geen rapport beschikbaar",description:"Upload of plak eer
6st een HTML-rapport via 'Delen met klant'."});return}const b=new Blob([a.html_content],{type:"text/html;charset=utf-8"}),P=URL.createObjectURL(b);window.open(P,"_blank","noopener,noreferrer"),setTimeout(()=>URL.revokeObjectURL(P),6e4)},k=async t=>{N(t);const{data:a,error:o}=await j.from("fit_scan_shares").select("share_token").eq("scan_id",t).order("sent_at",{ascending:!1}).limit(1).maybeSingle();if(N(null),o||!(a!=null&&a.share_token)){D({title:"Geen publieke link beschikbaar",description:"Deel de scan eerst via 'Delen met klant' â dan ontstaat een token."});return}const b=`${window.location.origin}/scan-public/${a.share_token}`;try{await navigator.clipboard.writeText(b)}catch{}window.location.href=b},F=async()=>{if(!d)return;await T(d.id)&&g(a=>a.filter(o=>o.id!==d.id)),f(null)};n.useEffect(()=>{l().then(g)},[l]);const m=n.useMemo(()=>{let t=p;if(h.trim()){const a=h.toLowerCase();t=t.filter(o=>(o.org_name??"").toLowerCase().includes(a)||(o.client_name??"").toLowerCase().includes(a))}return x!=="all"&&(t=t.filter(a=>{const o=a.fit_score??0;return x==="low"?o<=30:x==="mid"?o>30&&o<=60:o>60})),t},[p,h,x]),_=m.length?Math.round(m.reduce((t,a)=>t+(a.fit_score??0),0)/m.length):0;return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"font-display text-2xl font-bold text-foreground flex items-center gap-3",children:[e.jsx(U,{className:"h-6 w-6 text-primary"}),"FIT Scans"]}),e.jsx("p",{className:"font-body text-sm text-muted-foreground mt-1",children:"Overzicht van alle opgeslagen FIT veldmetingen"})]}),e.jsxs($,{onClick:()=>i("/admin/fit-scan/new"),className:"gap-2",children:[e.jsx(je,{className:"h-4 w-4"}),"Nieuwe scan"]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[{icon:Y,label:"Totaal scans",value:m.length},{icon:ve,label:"Gem. FIT score",value:`${_}/100`},{icon:ye,label:"Laatste scan",value:m[0]?L(new Date(m[0].created_at),"d MMM yyyy",{locale:C}):"â"}].map(t=>e.jsxs("div",{className:"bg-card rounded-xl border border-border p-5 flex items-center gap-4",children:[e.jsx("div",{className:"h-10 w-10 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(t.icon,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-body text-xs text-muted-foreground uppercase tracking-wider",children:t.label}),e.jsx("p",{className:"font-display text-lg font-bold text-foreground",children:t.value})]})]},t.label))}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ee,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(H,{placeholder:"Zoek op organisatie of contactpersoonâ¦",value:h,onChange:t=>y(t.target.value),className:"pl-9 pr-8"}),h&&e.jsx("button",{onClick:()=>y(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:e.jsx(te,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:Ce.map(t=>e.jsx("button",{onClick:()=>M(t.value),className:`font-body text-xs font-medium px-3 py-2 rounded-lg border transition-colors ${x===t.value?"bg-primary text-primary-foreground border-primary":"bg-card text-muted-foreground border-border hover:border-primary/40"}`,children:t.label},t.value))})]}),v?e.jsx("div",{className:"text-center py-16 bg-card rounded-xl border border-border",children:e.jsx("p",{className:"font-body text-muted-foreground",children:"Ladenâ¦"})}):m.length===0?e.jsxs("div",{className:"text-center py-16 bg-card rounded-xl border border-border",children:[e.jsx(U,{className:"h-12 w-12 text-muted-foreground/30 mx-auto mb-4"}),e.jsx("p",{className:"font-body text-muted-foreground",children:p.length===0?"Nog geen FIT scans opgeslagen.":"Geen scans gevonden voor deze zoekopdracht."})]}):e.jsx("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-muted/30",children:[e.jsx("th",{className:"text-left font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-5 py-3",children:"Organisatie"}),e.jsx("th",{className:"text-left font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-5 py-3",children:"Contactpersoon"}),e.jsx("th",{className:"text-left font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-5 py-3",children:"FIT Score"}),e.jsx("th",{className:"text-left font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-5 py-3",children:"Niveau"}),e.jsx("th",{className:"text-left font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-5 py-3",children:"Datum"}),e.jsx("th",{className:"text-center font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-2 py-3 w-16",children:"Openen"}),e.jsx("th",{className:"text-center font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-2 py-3 w-16",children:"Voorbeeld"}),e.jsx("th",{className:"text-center font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-2 py-3 w-16",children:"Publieke link"}),e.jsx("th",{className:"text-center font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-2 py-3 w-16",children:"Delen"}),e.jsx("th",{className:"text-center font-body text-xs font-semibold text-muted-foreground uppercase tracking-wider px-2 py-3 w-16",children:"Verwijderen"})]})}),e.jsx("tbody",{children:m.map(t=>e.jsxs("tr",{onClick:()=>i(`/admin/fit-scan/${t.id}`),className:"border-b border-border last:border-0 hover:bg-muted/20 cursor-pointer transition-colors",children:[e.jsx("td",{className:"px-5 py-4 font-body text-sm font-medium text-foreground",children:t.org_name||"â"}),e.jsx("td",{className:"px-5 py-4 font-body text-sm text-muted-foreground",children:t.client_name||"â"}),e.jsx("td",{className:"px-5 py-4",children:e.jsxs("span",{className:"font-display text-sm font-bold text-foreground",children:[t.fit_score??0,e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"/100"})]})}),e.jsx("td",{className:"px-5 py-4",children:e.jsx("span",{className:`inline-block font-body text-xs font-medium px-2.5 py-1 rounded-full border ${Se(t.fit_score??0)}`,children:Le(t.fit_score??0)})}),e.jsx("td",{className:"px-5 py-4 font-body text-sm text-muted-foreground",children:t.scan_date?L(new Date(t.scan_date),"d MMM yyyy",{locale:C}):L(new Date(t.created_at),"d MMM yyyy",{locale:C})}),e.jsx("td",{className:"px-3 py-4",children:e.jsx(we,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx("td",{className:"px-2 py-4",children:e.jsx("button",{onClick:a=>{a.stopPropagation(),u(t.id)},disabled:A===t.id,className:"p-1.5 rounded-md text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors disabled:opacity-50",title:"Voorbeeld rapport",children:e.jsx(G,{className:"h-4 w-4"})})}),e.jsx("td",{className:"px-2 py-4",children:e.jsx("button",{onClick:a=>{a.stopPropagation(),k(t.id)},disabled:I===t.id,className:"p-1.5 rounded-md text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors disabled:opacity-50",title:"Open publieke HTML-link (geen e-mailverificatie)",children:e.jsx(Ne,{className:"h-4 w-4"})})}),e.jsx("td",{className:"px-2 py-4",children:e.jsx("button",{onClick:a=>{a.stopPropagation(),w(t)},className:"p-1.5 rounded-md text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors",title:"Delen met klant",children:e.jsx(ke,{className:"h-4 w-4"})})}),e.jsx("td",{className:"px-2 py-4",children:e.jsx("button",{onClick:a=>{a.stopPropagation(),f(t)},className:"p-1.5 rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",title:"Verwijderen",children:e.jsx(K,{className:"h-4 w-4"})})})]},t.id))})]})})}),e.jsx(me,{open:!!d,onOpenChange:t=>!t&&f(null),children:e.jsxs(xe,{children:[e.jsxs(ue,{children:[e.jsx(pe,{children:"Scan verwijderen?"}),e.jsxs(he,{children:["Weet je zeker dat je de scan van"," ",e.jsx("span",{className:"font-semibold",children:(d==null?void 0:d.org_name)||"onbekende organisatie"})," ","wilt verwijderen? Dit kan niet ongedaan worden gemaakt."]})]}),e.jsxs(ge,{children:[e.jsx(fe,{children:"Annuleren"}),e.jsx(be,{onClick:F,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Verwijderen"})]})]})}),c&&e.jsx(_e,{open:!!c,onOpenChange:t=>!t&&w(null),scanId:c.id,scanLabel:c.org_name||c.client_name||"FIT scan"})]})}
6export{We 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.