1import{r as c,j as e,L as y}from"./vendor-B5DssOfd.js";import{D as F}from"./DashboardLayout-D0gZrLSq.js";import{U as A}from"./index-ClHmr1ee.js";import{u as q}from"./i18n-uURfBduE.js";const u="https://api.rstcc.net".replace(/\/$/,""),G=()=>localStorage.getItem("token")||"",h=()=>({"Content-Type":"application/json",Authorization:`Token ${G()}`}),C=[{id:"users",label:"Gebruikers",icon:"groups"},{id:"planning",label:"Planning",icon:"calendar_month"},{id:"products",label:"Producten",icon:"inventory_2"},{id:"orders",label:"Bestellingen",icon:"receipt_long"},{id:"statistics",label:"Statistieken",icon:"insights"},{id:"ai_usage",label:"AI Gebruik",icon:"smart_toy"},{id:"podcasts",label:"Podcasts",icon:"podcasts"},{id:"projects",label:"Projecten",icon:"folder_supervised"},{id:"media",label:"Media",icon:"perm_media"},{id:"webcontent",label:"WebContent",icon:"hub"},{id:"bookings",label:"Boekingen",icon:"meeting_room"},{id:"locations",label:"Locaties",icon:"location_on"},{id:"abbreviations",label:"Afkortingen",icon:"edit_note"},{id:"subscriptions",label:"Abonnementen",icon:"card_membership"},{id:"email_templates",label:"Text Templates",icon:"edit_document"},{id:"faq",label:"FAQ",icon:"quiz"},{id:"social_media",label:"Social Media",icon:"share"},{id:"administratie",label:"Administratie",icon:"receipt_long"}],S=t=>[...t].sort((d,o)=>`${d.user.last_name}${d.user.first_name}`.localeCompare(`${o.user.last_name}${o.user.first_name}`,"nl"));function V(){const{t}=q(),[d,o]=c.useState([]),[P,L]=c.useState(!0),[p,U]=c.useState(""),[f,b]=c.useState(!1),[j,N]=c.useState(""),[g,T]=c.useState([]),[E,k]=c.useState(!1),v=c.useRef(null);c.useEffect(()=>{(async()=>{try{const r=await fetch(`${u}/api/admin/users/`,{headers:h()});if(!r.ok)return;const i=(await r.json()).filter(n=>(n.role||"").split(",").map(x=>x.trim()).includes("admin")),l=await Promise.all(i.map(async n=>{let x={};try{const $=await fetch(`${u}/api/admin/module-permissions/?user_id=${n.id}`,{headers:h()});$.ok&&(x=await $.json())}catch{}return{user:n,perms:x,saving:!1,saved:!1,open:!1}}));o(S(l))}finally{L(!1)}})()},[]);const R=async()=>{if(b(!0),!(g.length>0)){k(!0);try{const a=await fetch(`${u}/api/admin/users/`,{headers:h()});if(a.ok){const r=await a.json();T(r.filter(s=>(s.role||"").split(",").map(i=>i.trim()).includes("admin")).sort((s,i)=>`${s.last_name}${s.first_name}`.localeCompare(`${i.last_name}${i.first_name}`,"nl")))}}finally{k(!1)}}};c.useEffect(()=>{const a=r=>{v.current&&!v.current.contains(r.target)&&b(!1)};return f&&document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[f]);const O=new Set(d.map(a=>a.user.id)),_=g.filter(a=>!O.has(a.id)&&`${a.first_name} ${a.last_name} ${a.email}`.toLowerCase().includes(j.toLowerCase())),z=a=>{o(r=>S([...r,{user:a,perms:{},saving:!1,saved:!1,open:!0}])),b(!1),N("")},m=(a,r)=>o(s=>s.map(i=>i.user.id===a?{...i,...r}:i)),D=(a,r,s)=>o(i=>i.map(l=>{if(l.user.id!==a)return l;const n=l.perms[r]||{view:!1,create:!1,edit:!1,delete:!1};return{...l,perms:{...l.perms,[r]:{...n,[s]:!n[s]}}}})),M=async(a,r)=>{m(a,{saving:!0});try{await fetch(`${u}/api/admin/module-permissions/`,{method:"POST",headers:h(),body:JSON.stringify({user_id:a,permissions:r})}),m(a,{saving:!1,saved:!0}),setTimeout(()=>m(a,{saved:!1}),2e3)}catch{m(a,{saving:!1})}},w=d.filter(a=>`${a.user.first_name} ${a.user.last_name} ${a.user.email}`.toLowerCase().includes(p.toLowerCase())),B=a=>C.filter(r=>{const s=a[r.id];return s&&(s.view||s.create||s.edit||s.delete)}).length;return e.jsx(F,{children:e.jsxs("div",{className:"px-8 md:px-12 py-10 space-y-10 max-w-6xl mx-auto",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-end justify-between gap-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs(y,{to:"/admin/dashboard",className:"inline-flex items-center gap-2 text-on-surface-variant/40 hover:text-primary text-[11px] font-black uppercase tracking-widest transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"arrow_back"}),t("admin.rights.panelTitle")]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"h-[2px] w-12 bg-primary"}),e.jsx("span",{className:"uppercase tracking-[0.4em] text-primary font-black text-xs",children:t("admin.r
1ights.title")})]}),e.jsx("h1",{className:"text-4xl md:text-6xl font-black uppercase tracking-tighter italic leading-none",children:t("admin.rights.heading")}),e.jsx("p",{className:"text-sm text-on-surface-variant/60",children:t("admin.rights.description")})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[e.jsxs("div",{className:"relative",ref:v,children:[e.jsxs("button",{type:"button",onClick:R,className:"flex items-center gap-2 px-5 py-4 bg-primary text-white rounded-2xl text-[11px] font-black uppercase tracking-widest hover:bg-primary/90 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-base",children:"person_add"}),t("admin.rights.addBtn")]}),f&&e.jsxs("div",{className:"absolute right-0 top-full mt-2 w-80 bg-surface-container border border-outline-variant/20 rounded-2xl shadow-2xl shadow-black/20 z-50 overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b border-outline-variant/10",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-on-surface-variant/50 mb-3",children:t("admin.rights.addUserPanel")}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-on-surface-variant/30 text-sm",children:"search"}
1),e.jsx("input",{autoFocus:!0,type:"text",placeholder:t("admin.rights.searchPlaceholder"),value:j,onChange:a=>N(a.target.value),className:"w-full bg-surface-container-high border border-outline-variant/10 rounded-xl pl-9 pr-4 py-2.5 text-sm focus:outline-none focus:border-primary/40 transition-all"})]})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto",children:E?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx("div",{className:"w-6 h-6 border-2 border-primary/30 border-t-primary rounded-full animate-spin"})}):_.length===0?e.jsx("p",{className:"text-[11px] text-on-surface-variant/40 font-black uppercase tracking-widest text-center py-6 italic",children:g.length===0?t("admin.rights.noAdminUsers"):t("admin.rights.allAdded")}):_.map(a=>e.jsxs("button",{type:"button",onClick:()=>z(a),className:"w-full flex items-center gap-3 px-4 py-3 hover:bg-primary/5 transition-colors text-left",children:[e.jsx(A,{src:a.profile_image,firstName:a.first_name,lastName:a.last_name,className:"w-8 h-8 rounded-full flex-shrink-0 bg-surface-container-high border border-outline-variant/10",initialsSize:"text-[9px]"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[12px] font-black text-on-surface truncate",children:[a.first_name," ",a.last_name]}),e.jsx("p",{className:"text-[10px] text-on-surface-variant/40 truncate",children:a.email})]}),e.jsx("span",{className:"material-symbols-outlined text-primary/50 text-sm flex-shrink-0",children:"add"})]},a.id))})]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-4 top-1/2 -translate-y-1/2 text-on-surface-variant/40 group-focus-within:text-primary transition-colors",children:"search"}),e.jsx("input",{type:"text",placeholder:t("admin.rights.searchUsers"),value:p,onChange:a=>U(a.target.value),className:"bg-surface-container-high border border-outline-variant/10 rounded-2xl pl-12 pr-6 py-4 text-sm focus:outline-none focus:border-primary/40 transition-all w-64"})]})]})]}),P?e.jsx("div",{className:"flex justify-center py-24",children:e.jsx("div",{className:"w-12 h-12 border-2 border-primary/30 border-t-primary rounded-full animate-spin"})}):w.length===0?e.jsxs("div",{className:"text-center py-24 space-y-4",children:[e.jsx("div",{className:"w-20 h-20 bg-surface-container rounded-[2rem] flex items-center justify-center mx-auto border border-outline-variant/10",children:e.jsx("span",{className:"material-symbols-outlined text-4xl text-on-surface-variant/20",children:"manage_accounts"})}),e.jsx("p",{className:"text-sm font-black uppercase tracking-widest text-on-surface-variant/40 italic",children:t(p?"admin.rights.noUsersFound":"admin.rights.noAdminRole")}),!p&&e.jsxs(y,{to:"/admin/users",className:"inline-flex items-center gap-2 text-primary text-xs font-black uppercase tracking-widest hover:underline",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:"arrow_forward"}),t("admin.rights.manageUsers")]})]}):e.jsx("div",{className:"space-y-3",children:w.map(a=>{const r=B(a.perms);return e.jsxs("div",{className:"bg-surface-container rounded-[2rem] border border-outline-variant/10 overflow-hidden transition-all",children:[e.jsxs("button",{type:"button",onClick:()=>m(a.user.id,{open:!a.open}),className:"w-full flex items-center gap-5 px-7 py-5 hover:bg-primary/3 transition-colors text-left",children:[e.jsx(A,{src:a.user.profile_image,firstName:a.user.first_name,lastName:a.user.last_name,className:"w-10 h-10 rounded-full flex-shrink-0 bg-surface-container-high border border-outline-variant/10",initialsSize:"text-xs"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"font-black text-sm text-on-surface truncate",children:[a.user.first_name," ",a.user.last_name]}),e.jsx("p",{className:"text-[10px] text-on-surface-variant/50 truncate",children:a.user.email})]}),e.jsx("div",{className:"hidden sm:flex items-center gap-2 flex-shrink-0",children:e.jsx("span",{className:`px-3 py-1 rounded-full text-[9px] font-black uppercase tracking-widest border ${r>0?"bg-primary/10 text-primary border-primary/20":"bg-error/10 text-error border-error/20"}
1`,children:r===0?t("admin.rights.noPerms"):t("admin.rights.modulesCount",{count:r})})}),e.jsx(y,{to:`/admin/user/edit/${a.user.id}?tab=rechten`,onClick:s=>s.stopPropagation(),className:"flex-shrink-0 w-8 h-8 rounded-xl bg-surface-container-high hover:bg-primary/10 flex items-center justify-center text-on-surface-variant/40 hover:text-primary transition-all",title:t("admin.rights.openProfile"),children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"open_in_new"})}),e.jsx("span",{className:`material-symbols-outlined text-on-surface-variant/30 text-xl transition-transform ${a.open?"rotate-180":""}`,children:"expand_more"})]}),a.open&&e.jsxs("div",{className:"border-t border-outline-variant/10 px-7 py-6 space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_repeat(4,5rem)] gap-2 items-center",children:[e.jsx("span",{className:"text-[9px] font-black uppercase tracking-widest text-on-surface-variant/40",children:"Module"}),[[t("admin.rights.permView"),"view"],[t("admin.rights.permCreate"),"create"],[t("admin.rights.permEdit"),"edit"],[t("admin.rights.permDelete"),"delete"]].map(([s])=>e.jsx("span",{className:"text-[9px] font-black uppercase tracking-widest text-on-surface-variant/40 text-center",children:s},s))]}),e.jsx("div",{className:"space-y-1",children:C.map(s=>{const i=a.perms[s.id]||{view:!1,create:!1,edit:!1,delete:!1},l=i.view||i.create||i.edit||i.delete;return e.jsxs("div",{className:`grid grid-cols-[1fr_repeat(4,5rem)] gap-2 items-center py-2 px-3 rounded-xl transition-colors ${l?"bg-primary/5":""}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`material-symbols-outlined text-[16px] ${l?"text-primary":"text-on-surface-variant/25"}`,children:s.icon}),e.jsx("span",{className:`text-[11px] font-black uppercase tracking-widest ${l?"text-on-surface":"text-on-surface-variant/40"}`,children:s.label})]}),["view","create","edit","delete"].map(n=>e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{type:"button",onClick:()=>D(a.user.id,s.id,n),className:`w-7 h-7 rounded-lg border-2 flex items-center justify-center transition-all ${i[n]?"bg-primary border-primary":"border-outline-variant/30 hover:border-primary/40"}`,children:i[n]&&e.jsx("span",{className:"material-symbols-outlined text-white text-[13px]",children:"check"})})},n))]},s.id)})}),e.jsxs("div",{className:"flex items-center gap-4 pt-2 border-t border-outline-variant/10",children:[e.jsxs("button",{type:"button",onClick:()=>M(a.user.id,a.perms),disabled:a.saving,className:"flex items-center gap-2 px-5 py-2.5 rounded-2xl bg-primary text-white text-[11px] font-black uppercase tracking-widest disabled:opacity-50 hover:bg-primary/90 transition-colors",children:[a.saving?e.jsx("span",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}):e.jsx("span",{className:"material-symbols-outlined text-base",children:a.saved?"check":"save"}),a.saved?t("admin.rights.saved"):t("admin.rights.save")]}),e.jsx("p",{className:"text-[10px] text-on-surface-variant/40",children:t("admin.rights.activeAfterLogin")})]})]})]},a.user.id)})})]})})}export{V 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.