1import{j as e}from"./vendor-markdown-3uENCkuS.js";import{e as xs,r as n,d as Us,u as Nt,m as Ft,b as Rt,c as We,N as nt}from"./vendor-react-router-fbnoKto0.js";import{qh as Ot,qi as qt,qj as Ut,qk as Wt,d$ as Ht,P as Ls,ql as Yt,qm as Gt,qn as Kt,qo as vt,qp as rt,qq as it,qr as Qt,qs as is,qt as Jt,qu as Zt,qv as cs,O,qw as Ts,qx as wt,qy as Xt,qz as Vt,qA as el,qB as sl,qC as tl,qD as ll,qE as al,qF as Ws,qG as nl,qH as rl,qI as il,qJ as cl,qK as ol,qL as dl,qM as xl}from"./index-B9eRcFVf.js";import{u as Qe,j as ge}from"./vendor-redux-De8h7f6b.js";import{bg as Ps,U as Ze,ap as Ms,K as Xe,fE as Et,aC as Ve,dT as Is,a3 as H,L as Ns,bb as ml,b7 as hl,dS as Oe,a9 as Ct,J as js,bA as pl,aj as Bt,az as Fs,a5 as we,av as Ge,cy as ns,bz as ul,G as Dt,S as ds,fF as vs,as as ws,ar as Rs,fG as Os,D as bl,bD as fl}from"./vendor-icons-l8SD0IkB.js";import{S as gl,s as as,M as yl}from"./vendor-antd-CYdTsTmT.js";import"./vendor-react-dom-CekZHfxh.js";import"./vendor-reactflow-IXhngCNR.js";import"./vendor-recharts-CJ0LSBh7.js";import"./vendor-syntax-highlighter-1lJlPebH.js";const Ke=(t,x,d="")=>{const c=t.get(x);return c==null?d:String(c)},jl=(t,x,d=1)=>{const c=Number(t.get(x));return Number.isFinite(c)&&c>0?Math.floor(c):d},Te=(t,x,d,c="")=>{const h=String(d??"").trim();if(!h||h===c){t.delete(x);return}t.set(x,h)},Nl=["ac_batches_status","ac_batches_location","ac_batches_q","ac_batches_page","ac_batch_students_q","ac_batch_students_page"],At=["ac_employees_status","ac_employees_role","ac_employees_q","ac_employees_page"],St=["ac_locations_q","ac_locations_filter"],Fl=["ac_bypass_page"],vl=[...Nl,...At,...St,...Fl],Bs=(t,x=[])=>{const d=new Set(x);vl.forEach(c=>{d.has(c)||t.delete(c)})},Hs=(t,x,d={replace:!0})=>{t(c=>{const h=new URLSearchParams(c);return x(h),h},d)},qs=(t,x,d="/admin/access-control")=>{const c=t||d,h=x.toString();return h?`${c}?${h}`:c},ct={batch:{icon:Ms,color:"text-[#2333CB]",bg:"bg-[#EEF4FF]",label:"Batch"},location:{icon:Xe,color:"text-[#067647]",bg:"bg-[#ECFDF3]",label:"Location"},student:{icon:Ze,color:"text-[#B54708]",bg:"bg-[#FFFAEB]",label:"Student"},employee:{icon:Et,color:"text-[#6941C6]",bg:"bg-[#F9F5FF]",label:"Employee"}};function wl(t){if(!t)return"";const x=Date.now()-new Date(t).getTime(),d=Math.floor(x/6e4);if(d<1)return"Just now";if(d<60)return`${d}m ago`;const c=Math.floor(d/60);return c<24?`${c}h ago`:`${Math.floor(c/24)}d ago`}function El(t){return String(t||"").split(" ").filter(Boolean).slice(0,2).map(x=>{var d;return(d=x[0])==null?void 0:d.toUpperCase()}).join("")}function Cl(t){const x=String(t||"").trim(),d=String(Ht).trim().replace(/\/$/,"");if(!x)return"";if(x.startsWith("http://")||x.startsWith("https://")||!d)return x;if(x.startsWith("/api/v1/assets?")||x.startsWith("api/v1/assets?"))return`${d}${x.startsWith("/")?x:`/${x}`}`;const c=x.startsWith("/")?x:`/${x}`;return`${d}/api/v1/assets?path=${encodeURIComponent(c)}`}const ot=t=>t==="paid"?"paid":"free",kt=({onNavigate:t})=>{var X;const x=Qe(),[d,c]=xs(),{data:h,loading:B,error:S}=ge(r=>{var j;return((j=r.accessControl)==null?void 0:j.dashboard)||{}}),E=ge(r=>{var j;return((j=r.accessControl)==null?void 0:j.accessAnalytics)||{}}),v=ge(r=>{var j;return((j=r.accessControl)==null?void 0:j.locationAnalytics)||{}}),p=ge(r=>{var j;return((j=r.accessControl)==null?void 0:j.batchAnalytics)||{}}),D=ge(r=>{var j;return(j=r.accessControl)==null?void 0:j.metadata});n.useEffect(()=>{x(Ot()),x(qt()),x(Ut())},[x]);const _=Ke(d,"ac_overview_batch_location"),T=ot(Ke(d,"ac_overview_template_tier","free"));n.useEffect(()=>{x(Wt(_?{location:_}:{}))},[_,x]);const W=n.useMemo(()=>{var r;return((r=D==null?void 0:D.data)==null?void 0:r.templates)||[]},[(X=D==null?void 0:D.data)==null?void 0:X.templates]),L=E.data||{},C=n.useMemo(()=>Array.isArray(v.data)?v.data:[],[v.data]),J=n.useMemo(()=>Array.isArray(p.data)?p.data:[],[p.data]),b=n.useMemo(()=>C.map(r=>r.location).filter(Boolean),[C]),[P,y]=n.useState({}),z=n.useCallback(r=>{Hs(c,r)},[c]),oe=n.useCallback(r=>{z(j=>{Te(j,"ac_overview_batch_location",r)})},[z]),Z=n.useCallback(r=>{z(j=>{Te(j,"ac_overview_template_tier",ot(r),"free")})},[z]),M=()=>
1{if(_){t("batches",{batchLocation:_});return}t("batches")},V=[{label:"Templates Assigned",count:(h==null?void 0:h.totalTemplatesAssigned)??0,icon:Ps,iconBg:"bg-[#EEF4FF]",iconColor:"text-[#2563EB]"},{label:"Employee Policies",count:(h==null?void 0:h.totalEmployeePolicies)??0,icon:Ze,iconBg:"bg-[#FDF2FA]",iconColor:"text-[#C026D3]",tab:"employees"},{label:"Batch Policies",count:(h==null?void 0:h.totalBatchPolicies)??0,icon:Ze,iconBg:"bg-[#ECFDFF]",iconColor:"text-[#0E7090]",tab:"batches"},{label:"Student Policies",count:(h==null?void 0:h.totalStudentPolicies)??0,icon:Ze,iconBg:"bg-[#FEF2F2]",iconColor:"text-[#EF4444]"}],se=n.useMemo(()=>(h==null?void 0:h.recentPolicies)||[],[h==null?void 0:h.recentPolicies]),Q=n.useMemo(()=>L.templateAccessDistribution&&typeof L.templateAccessDistribution=="object"?L.templateAccessDistribution:{},[L.templateAccessDistribution]),f=n.useMemo(()=>W.map((r,j)=>{const Y=String((r==null?void 0:r.name)||"").trim()||String((r==null?void 0:r.id)||"").trim()||`Template ${j+1}`;return{...r,label:Y,logoUrl:Cl(r==null?void 0:r.logo),tier:(r==null?void 0:r.freeTier)===!1?"paid":"free",usageCount:Q[r==null?void 0:r.id]??Q[r==null?void 0:r.name]??0}}).sort((r,j)=>j.usageCount-r.usageCount||r.label.localeCompare(j.label)),[Q,W]),F=n.useMemo(()=>f.filter(r=>r.tier==="free"),[f]),q=n.useMemo(()=>f.filter(r=>r.tier==="paid"),[f]),ae=n.useMemo(()=>T==="paid"?q:F,[F,q,T]),U=n.useMemo(()=>se.slice(0,6),[se]);n.useEffect(()=>{if(T==="free"&&F.length===0){q.length>0&&Z("paid");return}T==="paid"&&q.length===0&&F.length>0&&Z("free")},[F.length,q.length,Z,T]);const ee=[{label:"Manage Batches",desc:"Set batch-level policies",tab:"batches",icon:Ms},{label:"Manage Locations",desc:"Set location-level policies",tab:"locations",icon:Xe},{label:"Manage Employees",desc:"Set employee-level policies",tab:"employees",icon:Ze},{label:"Compliance Bypass",desc:"Bypass fee/attendance/status",tab:"bypass",icon:Et}];return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4",children:ee.map(r=>{const j=r.icon;return e.jsx("button",{type:"button",onClick:()=>t(r.tab),className:"min-h-[12rem] rounded-2xl border border-[#E4E7EC] bg-white px-6 py-5 text-left shadow-sm transition hover:border-[#C7D7FE] hover:shadow-md",children:e.jsxs("div",{className:"flex h-full flex-col gap-6",children:[e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl bg-[#2333CB] text-white",children:e.jsx(j,{size:24})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[1.125rem] font-semibold text-[#181D27]",children:r.label}),e.jsx("p",{className:"text-base text-[#667085]",children:r.desc})]})]})},r.tab)})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-[1.3rem] font-semibold tracking-tight text-[#414651]",children:"Key Metrics"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-4",children:B?Array.from({length:4}).map((r,j)=>e.jsx("div",{className:"min-h-[8.5rem] rounded-2xl border border-[#E9EAEB] bg-white px-6 py-5 shadow-[0_10px_24px_rgba(2,2,76,0.06)] animate-pulse",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"h-5 w-32 rounded bg-[#E9EAEB]"}),e.jsx("div",{className:"h-10 w-14 rounded bg-[#F2F4F7]"})]}),e.jsx("div",{className:"h-14 w-14 rounded-2xl bg-[#F2F4F7]"})]})}
1,j)):V.map(r=>{const j=r.icon,Y=r.tab?"button":"div",ne=r.tab?{type:"button",onClick:()=>t(r.tab)}:{};return e.jsx(Y,{...ne,className:`min-h-[8.5rem] rounded-2xl border border-[#E4E7EC] bg-white px-6 py-5 text-left shadow-[0_10px_24px_rgba(2,2,76,0.06)] transition ${r.tab?"cursor-pointer hover:border-[#C7D7FE] hover:shadow-[0_14px_28px_rgba(2,2,76,0.08)]":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[1.125rem] font-medium text-[#535862]",children:r.label}),e.jsx("p",{className:"mt-4 text-[2.125rem] font-semibold leading-none text-[#181D27]",children:r.count})]}),e.jsx("div",{className:`flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl ${r.iconBg} ${r.iconColor}`,children:e.jsx(j,{size:18})})]})},r.label)})})]}),!E.loading&&L&&(L.studentsWithoutCoverage>0||L.employeesWithoutPolicy>0)&&e.jsxs("div",{className:"space-y-2",children:[L.studentsWithoutCoverage>0&&e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-xl border border-[#FEC84B] bg-[#FFFAEB]",children:[e.jsx(Ve,{size:16,className:"text-[#B54708] shrink-0"}),e.jsxs("p",{className:"text-sm text-[#B54708] font-medium",children:[L.studentsWithoutCoverage," students have no policy coverage"]})]}),L.employeesWithoutPolicy>0&&e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-xl border border-[#FEC84B] bg-[#FFFAEB]",children:[e.jsx(Ve,{size:16,className:"text-[#B54708] shrink-0"}),e.jsxs("p",{className:"text-sm text-[#B54708] font-medium",children:[L.employeesWithoutPolicy," employees have no access policy"]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-3",children:[e.jsxs("div",{className:"overflow-hidden rounded-3xl border border-[#E4E7EC] bg-white shadow-sm xl:col-span-2",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b border-[#F2F4F7] px-4 py-4 sm:gap-4 sm:px-5 sm:py-5",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-[#EEF4FF] text-[#2333CB] sm:h-14 sm:w-14",children:e.jsx(Xe,{size:24})}),e.jsx("div",{className:"min-w-0",children:e.jsx("h3",{className:"text-[1.1rem] font-semibold tracking-tight text-[#414651] sm:text-[1.4rem]",children:"Users by Location"})})]}),v.loading?e.jsx("div",{className:"p-5",children:e.jsx("div",{className:"h-[21rem] animate-pulse rounded-2xl bg-[#F9FAFB]"})}):C.length===0?e.jsx("div",{className:"px-5 py-10 text-center text-sm text-[#667085]",children:"No location analytics available right now."}):e.jsx("div",{className:"overflow-auto leaderboard-scrollbar-custom",children:e.jsxs("table",{className:"min-w-[780px] w-full text-left",children:[e.jsx("thead",{className:"bg-[#F9FAFB]",children:e.jsxs("tr",{className:"border-b border-[#E9EAEB]",children:[e.jsx("th",{className:"px-5 py-4 text-sm font-medium text-[#667085]",children:"Location"}),e.jsx("th",{className:"px-4 py-4 text-sm font-medium text-[#667085]",children:"Synced Stu"}),e.jsx("th",{className:"px-4 py-4 text-sm font-medium text-[#667085]",children:"Synced Emp"}),e.jsx("th",{className:"px-4 py-4 text-center text-sm font-medium text-[#667085]",children:"Batches"}),e.jsx("th",{className:"px-4 py-4 text-center text-sm font-medium text-[#667085]",children:"Stu Policies"}),e.jsx("th",{className:"px-4 py-4 text-center text-sm font-medium text-[#667085]",children:"Emp Policies"}),e.jsx("th",{className:"px-5 py-4 text-center text-sm font-medium text-[#667085]",children:"Loc Policy"})]})}),e.jsx("tbody",{children:C.map(r=>e.jsxs("tr",{className:"border-b last:border-0 border-[#E9EAEB] hover:bg-[#F9FAFB] transition",children:[e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-full border border-[#D5D7DA] bg-white text-[#667085]",children:e.jsx(Xe,{size:15})}),e.jsx("span",{className:"text-base font-medium text-[#344054] sm:text-[1.125rem]",children:r.location})]})}),e.jsxs("td",{className:"px-4 py-5 align-middle",children:[e.jsxs("p",{className:"text-base font-semibold text-[#181D27] sm:text-[1.125rem]",children:[r.syncedStudents||0,"/",r.students||0]}),e.jsx("p",{className:"text-sm text-[#667085]",children:"Synced"})]}),e.jsxs("td",{className:"px-4 py-5 align-middle",children:[e.jsxs("p",{className:"text-base font-semibold text-[#181D27] sm:text-[1.125rem]",children:[r.syncedEmployees||0,"/",r.employees||0]}),e.jsx("p",{className:"text-sm text-[#667085]",children:"Synced"})]}),e.jsx("td",{className:"px-4 py-5 text-center text-base font-medium text-[#344054] sm:text-[1.125rem]",children:r.batches||0}),e.jsx("td",{className:"px-4 py-5 text-center text-base font-medium text-[#344054] sm:text-[1.125rem]",children:r.studentPolicies||0}),e.jsx("td",{className:"px-4 py-5 text-center text-base font-medium text-[#344054] sm:text-[1.125rem]",children:r.employeePolicies||0}),e.jsx("td",{className:"px-5 py-5 text-center",children:e.jsx("span",{className:`inline-flex min-w-[3rem] items-center justify-center rounded-xl border px-3 py-1 text-sm font-medium ${r.hasLocationPolicy?"border-[#D9D6FE] bg-[#F4F3FF] text-[#6941C6]":"border-[#
1E4E7EC] bg-[#F8FAFC] text-[#475467]"}`,children:r.hasLocationPolicy?"Yes":"No"})})]},r.location))})]})})]}),e.jsxs("div",{className:"overflow-hidden rounded-3xl border border-[#E4E7EC] bg-white shadow-sm",children:[e.jsxs("div",{className:"flex items-start gap-3 border-b border-[#F2F4F7] px-4 py-4 sm:gap-4 sm:px-5 sm:py-5",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-[#EEF4FF] text-[#2333CB] sm:h-14 sm:w-14",children:e.jsx(Is,{size:24})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[1.1rem] font-semibold tracking-tight text-[#414651] sm:text-[1.4rem]",children:"Recent Policy Changes"}),e.jsx("p",{className:"mt-1 text-sm text-[#667085] sm:text-base",children:"Track policy changes."})]})]}),B?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(H,{size:20,className:"animate-spin text-[#2333CB]"})}):U.length===0?e.jsx("div",{className:"px-5 py-10 text-center text-sm text-[#667085]",children:"No recent policy changes."}):e.jsx("div",{className:"max-h-[34rem] space-y-3 overflow-y-auto px-4 py-4 no-scrollbar sm:max-h-[41rem] sm:space-y-4 sm:px-5 sm:py-5",children:U.map((r,j)=>{const Y=ct[r.policyType]||ct.batch,ne=r.name||r.target||Y.label,re=r.policyType==="student"?[r.batchNo,r.location].filter(Boolean).join(" · "):r.policyType==="employee"?[r.role,r.location].filter(Boolean).join(" · "):r.policyType==="batch"?[r.location,Y.label].filter(Boolean).join(" · "):Y.label,le=String(re||"").replace(/\s*\u00C2\u00B7\s*/g," / "),ie=El(ne)||Y.label[0];return e.jsxs("div",{className:"flex flex-col items-start gap-3 rounded-2xl border border-[#E4E7EC] bg-white px-4 py-4 shadow-[0_4px_12px_rgba(16,24,40,0.04)] sm:flex-row sm:items-center sm:gap-4",children:[e.jsxs("div",{className:"flex w-full min-w-0 items-start gap-3 sm:flex-1 sm:items-center",children:[e.jsx("div",{className:`flex h-12 w-12 shrink-0 items-center justify-center rounded-full border border-white text-sm font-semibold shadow-sm ${Y.bg} ${Y.color}`,children:ie}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-base font-semibold text-[#181D27] sm:text-[1.125rem]",children:ne}),e.jsx("p",{className:"truncate text-sm text-[#667085] sm:text-base",children:le})]})]}),e.jsxs("span",{className:"ml-[3.75rem] inline-flex shrink-0 items-center gap-1.5 rounded-xl border border-[#D9D6FE] bg-[#F4F3FF] px-3 py-1 text-xs font-medium text-[#6941C6] sm:ml-0 sm:self-auto sm:text-sm",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-[#7A5AF8]"}),wl(r.updatedAt)]})]},`${ne}-${r.updatedAt||j}`)})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-3",children:[e.jsxs("div",{className:"overflow-hidden rounded-3xl border border-[#E4E7EC] bg-white shadow-sm xl:col-span-2",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-[#F2F4F7] px-4 py-4 sm:px-5 sm:py-5 xl:flex-row xl:items-start xl:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-[#ECFDF3] text-[#067647] sm:h-14 sm:w-14",children:e.jsx(Ms,{size:24})}),e.jsx("div",{className:"min-w-0",children:e.jsx("h3",{className:"text-[1.1rem] font-semibold tracking-tight text-[#414651] sm:text-[1.4rem]",children:"Batch Sync Coverage"})})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:flex-row xl:w-auto",children:[b.length>0&&e.jsxs("select",{value:_,onChange:r=>oe(r.target.value),className:"h-10 w-full rounded-xl border border-[#D5D7DA] bg-white px-3 text-sm text-[#475467] outline-none sm:w-auto xl:min-w-[11rem]",children:[e.jsx("option",{value:"",children:"All Locations"}),b.map(r=>e.jsx("option",{value:r,children:r},r))]}),e.jsxs("button",{type:"button",onClick:M,className:"inline-flex h-10 w-full items-center justify-center gap-1 rounded-xl border border-[#D5D7DA] bg-white px-3 text-sm font-semibold text-[#344054] transition hover:bg-[#F9FAFB] sm:w-auto",children:["View all ",e.jsx(Ns,{size:16})]})]})]}),p.loading?e.jsx("div",{className:"p-5",children:e.jsx("div",{className:"h-[20rem] animate-pulse rounded-2xl bg-[#F9FAFB]"})}):J.length===0?e.jsx("div",{className:"px-5 py-10 text-center text-sm text-[#667085]",children:"No batch analytics available right now."}):e.jsx("div",{className:"overflow-auto leaderboard-scrollbar-custom",children:e.jsxs("table",{className:"min-w-[760px] w-full text-left",children:[e.jsx("thead",{className:"bg-[#F9FAFB]",children:e.jsxs("tr",{className:"border-b border-[#
1E9EAEB]",children:[e.jsx("th",{className:"px-5 py-4 text-sm font-medium text-[#667085]",children:"Batch/Location"}),e.jsx("th",{className:"px-4 py-4 text-center text-sm font-medium text-[#667085]",children:"Status"}),e.jsx("th",{className:"px-4 py-4 text-sm font-medium text-[#667085]",children:"Synced"}),e.jsx("th",{className:"px-4 py-4 text-center text-sm font-medium text-[#667085]",children:"Stu Policies"}),e.jsx("th",{className:"px-5 py-4 text-center text-sm font-medium text-[#667085]",children:"Batch Policy"})]})}),e.jsx("tbody",{children:J.slice(0,7).map(r=>e.jsxs("tr",{className:"border-b last:border-0 border-[#E9EAEB] hover:bg-[#F9FAFB] transition",children:[e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-base font-semibold text-[#181D27] sm:text-[1.125rem]",children:r.batch}),e.jsx("p",{className:"text-sm text-[#667085] sm:text-base",children:r.location||"-"})]})}),e.jsx("td",{className:"px-4 py-5 text-center",children:e.jsxs("span",{className:`inline-flex items-center rounded-full border px-3 py-1 text-sm font-medium ${r.status==="Active"?"border-[#A6F4C5] bg-[#ECFDF3] text-[#027A48]":"border-[#D0D5DD] bg-[#F2F4F7] text-[#667085]"}`,children:[e.jsx("span",{className:`mr-2 h-2 w-2 rounded-full ${r.status==="Active"?"bg-[#12B76A]":"bg-[#98A2B3]"}`}),r.status||"-"]})}),e.jsxs("td",{className:"px-4 py-5",children:[e.jsxs("p",{className:"text-base font-semibold text-[#181D27] sm:text-[1.125rem]",children:[r.syncedStudents||0,"/",r.studentCount||0]}),e.jsx("p",{className:"text-sm text-[#667085]",children:"Synced"})]}),e.jsx("td",{className:"px-4 py-5 text-center text-base font-medium text-[#344054] sm:text-[1.125rem]",children:r.studentPolicies||0}),e.jsx("td",{className:"px-5 py-5 text-center",children:e.jsx("span",{className:`inline-flex min-w-[3rem] items-center justify-center rounded-xl border px-3 py-1 text-sm font-medium ${r.hasBatchPolicy?"border-[#D9D6FE] bg-[#F4F3FF] text-[#6941C6]":"border-[#E4E7EC] bg-[#F8FAFC] text-[#475467]"}`,children:r.hasBatchPolicy?"Yes":"No"})})]},r.batch))})]})})]}),e.jsxs("div",{className:"overflow-hidden rounded-3xl border border-[#E4E7EC] bg-white shadow-sm",children:[e.jsxs("div",{className:"flex items-start gap-3 border-b border-[#F2F4F7] px-4 py-4 sm:gap-4 sm:px-5 sm:py-5",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-[#EEF4FF] text-[#2333CB] sm:h-14 sm:w-14",children:e.jsx(Ps,{size:24})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[1.1rem] font-semibold tracking-tight text-[#414651] sm:text-[1.4rem]",children:"Templates Overview"}),e.jsx("p",{className:"mt-1 text-sm text-[#667085] sm:text-base",children:"Track how templates are being used."})]})]}
1),e.jsxs("div",{className:"space-y-4 px-4 py-4 sm:space-y-5 sm:px-5 sm:py-5",children:[e.jsxs("div",{className:"inline-flex max-w-full items-center overflow-x-auto rounded-full border border-[#E4E7EC] bg-white p-1 shadow-sm",children:[e.jsxs("button",{type:"button",onClick:()=>Z("free"),className:`whitespace-nowrap rounded-full px-4 py-2 text-sm font-semibold transition ${T==="free"?"border border-[#C7D7FE] bg-[#EEF4FF] text-[#2333CB]":"text-[#475467]"}`,children:["Free (",F.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>Z("paid"),className:`whitespace-nowrap rounded-full px-4 py-2 text-sm font-semibold transition ${T==="paid"?"border border-[#FEDF89] bg-[#FFFAEB] text-[#B54708]":"text-[#475467]"}`,children:["Paid (",q.length,")"]})]}),ae.length===0?e.jsxs("div",{className:"rounded-2xl border border-dashed border-[#D0D5DD] bg-[#F9FAFB] px-4 py-10 text-center text-sm text-[#667085]",children:["No ",T," templates available."]}):e.jsx("div",{className:"max-h-[38rem] space-y-3 overflow-y-auto pr-1 no-scrollbar sm:space-y-4",children:ae.map(r=>{const j=r.id||r.label,Y=r.logoUrl&&!P[j];return e.jsxs("div",{className:"flex flex-col items-start gap-3 rounded-2xl border border-[#E4E7EC] bg-white px-4 py-4 shadow-[0_4px_12px_rgba(16,24,40,0.04)] sm:flex-row sm:items-center sm:gap-4",children:[e.jsxs("div",{className:"flex w-full min-w-0 items-start gap-3 sm:flex-1 sm:items-center",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-2xl bg-gradient-to-br from-[#EEF4FF] via-[#F5F3FF] to-[#FFF7ED] text-[#2333CB] sm:h-14 sm:w-14",children:Y?e.jsx("img",{src:r.logoUrl,alt:`${r.label} logo`,loading:"lazy",onError:()=>y(ne=>({...ne,[j]:!0})),className:"h-full w-full object-contain p-2"}):e.jsx(Ps,{size:24})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-base font-semibold text-[#181D27] sm:text-[1.125rem]",children:r.label}),e.jsxs("p",{className:"text-sm text-[#667085] sm:text-base",children:[r.usageCount," assignment",r.usageCount===1?"":"s"]})]})]}),e.jsx("span",{className:`ml-[3.75rem] inline-flex shrink-0 items-center rounded-xl border px-3 py-1 text-sm font-medium sm:ml-0 sm:self-auto ${r.tier==="free"?"border-[#ABEFC6] bg-[#ECFDF3] text-[#067647]":"border-[#FEDF89] bg-[#FFFAEB] text-[#B54708]"}`,children:r.tier==="free"?"Free":"Paid"})]},j)})})]})]})]})]}),S&&e.jsx("p",{className:"text-sm text-[#B42318] mt-2",children:S})]})};kt.propTypes={onNavigate:Ls.func.isRequired};const He={freePeriodDays:30,monthlyPrice:10,paymentRequired:!0,prePaymentAllowed:!0},bs={freePeriodDays:"",monthlyPrice:"",paymentRequired:null,prePaymentAllowed:null};function Bl({targetType:t,targetValue:x,targetLabel:d}){const[c,h]=n.useState(null),[B,S]=n.useState(!0),[E,v]=n.useState(!1),[p,D]=n.useState({...bs}),[_,T]=n.useState(!1),W=async()=>{S(!0);try{const b=await Yt({[t]:x}),P=b==null?void 0:b.deploymentConfig;P?(D({freePeriodDays:P.freePeriodDays??"",monthlyPrice:P.monthlyPrice??"",paymentRequired:P.paymentRequired??null,prePaymentAllowed:P.prePaymentAllowed??null}),h(P),T(!0)):(D({...bs}),h(null),T(!1))}catch{D({...bs}),h(null),T(!1)}S(!1)};n.useEffect(()=>{x&&W()},[t,x]);const L=async()=>{const b={[t]:x};let P=!1;if(p.freePeriodDays!==""&&p.freePeriodDays!=null&&(b.freePeriodDays=Number(p.freePeriodDays),P=!0),p.monthlyPrice!==""&&p.monthlyPrice!=null&&(b.monthlyPrice=Number(p.monthlyPrice),P=!0),p.paymentRequired!==null&&(b.paymentRequired=p.paymentRequired,P=!0),p.prePaymentAllowed!==null&&(b.prePaymentAllowed=p.prePaymentAllowed,P=!0),!P){as.warning("Set at least one field");return}v(!0);try{await Gt(b),as.success("Deployment config saved"),W()}catch(y){as.error(y.message)}v(!1)},C=()=>{yl.confirm({title:"Revert to Defaults",content:`Remove deployment config for "${d||x}"? Settings will fall back to the next level.`,okText:"Revert",okButtonProps:{danger:!0},onOk:async()=>{try{await Kt({[t]:x}),D({...bs}),h(null),T(!1),as.success("Reverted to defaults"),W()}catch(b){as.error(b.message)}}})};if(B)return e.jsx("div",{className:"py-6 text-center",children:e.jsx(gl,{size:"small"})});const J=b=>b!==""&&b!==null&&b!==void 0;
1return e.jsxs("div",{className:"rounded-xl border border-[#E4E7EC] bg-[#FAFBFC] overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 bg-white border-b border-[#E4E7EC]",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-[#2333CB]/10 flex items-center justify-center",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#2333CB",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]})}),e.jsx("span",{className:"text-sm font-semibold text-[#181D27]",children:"Deployment Settings"}),_?e.jsx("span",{className:"text-sm font-medium bg-emerald-50 text-emerald-600 border border-emerald-200 px-2 py-0.5 rounded-full",children:"Configured"}):e.jsx("span",{className:"text-sm font-medium bg-gray-100 text-gray-500 px-2 py-0.5 rounded-full",children:"Using defaults"})]}),_&&(c==null?void 0:c.updatedAt)&&e.jsxs("span",{className:"text-sm text-gray-400",children:["Updated ",new Date(c.updatedAt).toLocaleDateString("en-IN")]})]}),e.jsxs("div",{className:"p-5 space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-lg border border-[#E4E7EC] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-sm font-medium text-[#344054]",children:"Free Period"}),J(p.freePeriodDays)?e.jsx("span",{className:"text-sm font-medium bg-blue-50 text-blue-600 px-1.5 py-0.5 rounded",children:"Custom"}):e.jsxs("span",{className:"text-sm text-gray-400",children:["Default: ",He.freePeriodDays," days"]})]}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("input",{type:"number",value:p.freePeriodDays,onChange:b=>{const P=b.target.value;D(y=>({...y,freePeriodDays:P===""?"":Math.min(365,Math.max(0,Number(P)))}))},placeholder:String(He.freePeriodDays),min:0,max:365,className:"w-20 text-2xl font-bold text-[#181D27] bg-transparent outline-none border-none placeholder:text-gray-300 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),e.jsx("span",{className:"text-sm text-gray-400",children:"days"})]})]}),e.jsxs("div",{className:"bg-white rounded-lg border border-[#E4E7EC] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-sm font-medium text-[#344054]",children:"Monthly Price"}),J(p.monthlyPrice)?e.jsx("span",{className:"text-sm font-medium bg-blue-50 text-blue-600 px-1.5 py-0.5 rounded",children:"Custom"}):e.jsx("span",{className:"text-sm text-gray-400",children:`Default: â¹${He.monthlyPrice}`})]}),e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:"text-2xl font-bold text-[#181D27]",children:"â¹"}),e.jsx("input",{type:"number",value:p.monthlyPrice,onChange:b=>{const P=b.target.value;D(y=>({...y,monthlyPrice:P===""?"":Math.max(0,Number(P))}))},placeholder:String(He.monthlyPrice),min:0,className:"w-20 text-2xl font-bold text-[#181D27] bg-transparent outline-none border-none placeholder:text-gray-300 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),e.jsx("span",{className:"text-sm text-gray-400",children:"/month"})]})]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[{key:"paymentRequired",label:"Payment Required",desc:"Charge students after free period ends"},{key:"prePaymentAllowed",label:"Allow Pre-Payment",desc:"Let students pay before suspension"}].map(({key:b,label:P,desc:y})=>{const z=p[b]===null?He[b]:p[b],oe=p[b]===null;return e.jsx("div",{onClick:()=>D(Z=>({...Z,[b]:!z})),className:`rounded-lg border-2 p-4 cursor-pointer transition-all select-none ${z?"border-emerald-300 bg-emerald-50/50":"border-[#E4E7EC] bg-white hover:border-gray-300"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 mt-0.5 ${z?"bg-emerald-500":"bg-gray-200"}`,children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:z?e.jsx("polyline",{points:"20 6 9 17 4 12"}):e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-[#181D27]",children:P}),e.jsx("p",{className:"text-sm text-gray-400 mt-0.5 leading-relaxed",children:y})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1 shrink-0",children:[e.jsx("span",{className:`text-sm font-bold px-2 py-0.5 rounded ${z?"bg-emerald-100 text-emerald-700":"bg-gray-100 text-gray-500"}`,children:z?"ON":"OFF"}),oe&&e.jsx("span",{className:"text-sm text-gray-400",children:"default"})]})]})},b)})}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-400 bg-gray-50 rounded-lg px-3 py-2",children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),e.jsxs("span",{children:["Fallback: Student â Batch â Location â Global (",He.freePeriodDays,"d free, ","â¹",He.monthlyPrice,"/mo, payment"," ","on",", pre-pay"," ","on",")"]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsxs("button",{onClick:L,disabled:E,className:"flex items-center gap-1.5 text-sm font-semibold px-4 py-2 bg-[#2333CB] text-white rounded-lg hover:bg-[#1a28a0] transition-colors disabled:opacity-50",children:[e.jsx(ml,{className:"w-3.5 h-3.5"}),E?"Saving...":"Save"]}),_&&e.jsxs("button",{onClick:C,className:"flex items-center gap-1.5 text-sm font-medium px-4 py-2 text-red-600 border border-red-200 rounded-lg hover:bg-red-50 transition-colors",children:[e.jsx(hl,{className:"w-3.5 h-3.5"}),"Revert to Defaults"]})]})]})]})}const dt={accessPolicy:{label:"Access Policy",icon:Oe,color:"#444CE7",bg:"#EEF4FF",border:"#C7D7FE"},complianceConfig:{label:"Compliance Config",icon:Oe,color:"#6941C6",bg:"#F9F5FF",border:"#D6BBFB"},deploymentConfig:{label:"Deployment Config",icon:Oe,color:"#E04F16",bg:"#FEF6EE",border:"#F9DBAF"},complianceBypass:{label:"Compliance Bypass",icon:Oe,color:"#B54708",bg:"#FFFAEB",border:"#FEDF89"}},xt={create:{label:"Created",cls:"bg-[#ECFDF3] text-[#067647] border-[#ABEFC6]"},update:{label:"Modified",cls:"bg-[#EFF8FF] text-[#175CD3] border-[#B2DDFF]"},delete:{label:"Deleted",cls:"bg-[#FEF3F2] text-[#B42318] border-[#FECDCA]"}},Dl={learningContent:"Learning Content",exams:"Exams",studio:"Worksp
1ace",codePlayground:"Code Playground",mockInterviews:"Mock Interviews",placementSupport:"Placement Support"},Al=new Set(["updatedBy","updatedAt","createdAt","createdBy","_id","__v"]),_t=t=>Al.has(t)||t.startsWith("updated")||t.startsWith("created"),mt=t=>t===!0||typeof t=="object"&&t&&Object.values(t).some(Boolean),ht=t=>typeof t=="object"&&t?Object.entries(t).filter(([,x])=>x).map(([x])=>x.replace("can","")):null;function Sl({name:t,before:x,after:d}){const c=Dl[t]||t,h=mt(x),B=mt(d),S=JSON.stringify(x)!==JSON.stringify(d),E=ht(x),v=ht(d),p=(D,_)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`inline-flex h-5 min-w-[2.5rem] items-center justify-center rounded text-[0.65rem] font-bold ${D?"bg-[#ECFDF3] text-[#067647]":"bg-[#F2F4F7] text-[#98A2B3]"}`,children:D?"ON":"OFF"}),D&&(_==null?void 0:_.length)>0&&e.jsx("span",{className:"text-xs text-[#535862]",children:_.join(" · ")}),D&&(!_||!_.length)&&e.jsx("span",{className:"text-xs text-[#535862]",children:"Full access"})]});return e.jsxs("div",{className:`px-4 py-3 transition-colors ${S?"bg-[#F5FAFF]":"bg-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1.5",children:[e.jsx("span",{className:`text-sm font-semibold ${S?"text-[#2333CB]":"text-[#344054]"}`,children:c}),S&&e.jsx("span",{className:"text-[0.6rem] font-bold text-[#444CE7] bg-[#EEF4FF] border border-[#C7D7FE] rounded px-1.5 py-px uppercase tracking-wider",children:"Changed"})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_auto_1fr] items-center gap-3",children:[p(h,E),S?e.jsx("span",{className:"text-[#444CE7] text-sm font-medium",children:"â"}):e.jsx("span",{className:"text-[#E4E7EC]",children:"â"}),p(B,v)]})]})}function kl({entry:t}){const x=t.before||{},d=t.after||{},c=x.moduleAccess||{},h=d.moduleAccess||{},B=[...new Set([...Object.keys(c),...Object.keys(h)])],S=x.templateAccess,E=d.templateAccess,v=(S==null?void 0:S.allowedTemplates)||[],p=(E==null?void 0:E.allowedTemplates)||[],D=p.filter(C=>!v.includes(C)),_=v.filter(C=>!p.includes(C)),T=p.filter(C=>v.includes(C)),W=(S==null?void 0:S.deployLimit)!==(E==null?void 0:E.deployLimit),L=D.length>0||_.length>0||W;return e.jsxs("div",{className:"space-y-5",children:[B.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between px-4 mb-1",children:[e.jsx("p",{className:"text-xs font-semibold text-[#98A2B3] uppercase tracking-wider",children:"Before"}),e.jsx("p",{className:"text-xs font-semibold text-[#98A2B3] uppercase tracking-wider",children:"After"})]}),e.jsx("div",{className:"rounded-xl border border-[#E4E7EC] divide-y divide-[#F2F4F7] overflow-hidden",children:B.map(C=>e.jsx(Sl,{name:C,before:c[C],after:h[C]},C))})]}),L&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-[#98A2B3] uppercase tracking-wider mb-2",children:"Templates"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[D.map(C=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-sm font-medium rounded-lg border border-[#ABEFC6] bg-[#F6FEF9] text-[#067647] px-3 py-1.5",children:[e.jsx("span",{className:"text-xs",children:"ï¼"})," ",C]},C)),_.map(C=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-sm font-medium rounded-lg border border-[#FECDCA] bg-[#FFFBFA] text-[#B42318] px-3 py-1.5 line-through",children:[e.jsx("span",{className:"text-xs",children:"â"})," ",C]},C)),T.map(C=>e.jsx("span",{className:"text-sm font-medium rounded-lg border border-[#E4E7EC] bg-white text-[#535862] px-3 py-1.5",children:C},C))]}),W&&e.jsxs("p",{className:"text-sm text-[#535862] mt-2",children:["Deploy limit:"," ",e.jsx("span",{className:"line-through text-[#98A2B3]",children:(S==null?void 0:S.deployLimit)??"â"}),e.jsx("span",{className:"mx-1.5 text-[#444CE7]",children:"â"}),e.jsx("span",{className:"font-semibold text-[#181D27]",children:(E==null?void 0:E.deployLimit)??"â"})]})]})]})}function _l({entry:t}){const x=(t.changes||[]).filter(h=>!_t(h.field));if(!x.length)return null;const d={paymentRequired:"Payment Required",freePeriodDays:"Free Perio
1d (days)",monthlyPrice:"Monthly Price",feeThreshold:"Fee Threshold (%)",attendanceThreshold:"Attendance Threshold (%)",gracePeriodDays:"Grace Period (days)",checks:"Bypass Checks",modules:"Bypass Modules",deadline:"Deadline",reason:"Reason"},c=h=>h===!0?"Yes":h===!1?"No":h==null?"â":Array.isArray(h)?h.join(", ")||"â":String(h);return e.jsx("div",{className:"rounded-xl border border-[#E4E7EC] divide-y divide-[#F2F4F7] overflow-hidden",children:x.map((h,B)=>{const S=h.from==null,E=h.to==null,v=d[h.field]||h.field.replace(/([A-Z])/g," $1").replace(/^./,p=>p.toUpperCase());return e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-white hover:bg-[#FAFBFC] transition-colors",children:[e.jsx("span",{className:`shrink-0 w-6 h-6 rounded-lg flex items-center justify-center text-xs font-bold ${S?"bg-[#ECFDF3] text-[#067647]":E?"bg-[#FEF3F2] text-[#B42318]":"bg-[#EFF8FF] text-[#175CD3]"}`,children:S?"+":E?"â":"~"}),e.jsx("span",{className:"text-sm font-medium text-[#344054] flex-1",children:v}),e.jsx("div",{className:"text-sm text-right shrink-0",children:S?e.jsx("span",{className:"font-semibold text-[#067647]",children:c(h.to)}):E?e.jsx("span",{className:"text-[#B42318] line-through",children:c(h.from)}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[#98A2B3] line-through",children:c(h.from)}),e.jsx("span",{className:"text-[#444CE7] mx-1.5",children:"â"}),e.jsx("span",{className:"font-semibold text-[#181D27]",children:c(h.to)})]})})]},B)})})}function Pl({entry:t,configType:x,expanded:d,onToggle:c}){const h=(t.changes||[]).filter(E=>!_t(E.field)),B=h.length===0,S=xt[t.action]||xt.update;return e.jsxs("div",{className:`rounded-xl border overflow-hidden transition-all duration-200 ${d?"border-[#C7D7FE] shadow-[0_2px_12px_rgba(68,76,231,0.08)]":"border-[#E4E7EC] hover:border-[#D0D5DD]"}`,children:[e.jsxs("button",{type:"button",onClick:c,className:"w-full px-4 py-3.5 flex items-center justify-between gap-3 bg-white hover:bg-[#FAFBFC] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-wrap",children:[e.jsxs("span",{className:"text-xs font-bold text-white bg-[#444CE7] rounded-md px-2 py-0.5 tabular-nums",children:["v",t.version]}),e.jsx("span",{className:`text-xs font-semibold rounded-md border px-2 py-0.5 ${S.cls}`,children:S.label}),!B&&e.jsxs("span",{className:"hidden sm:inline text-xs text-[#667085] bg-[#F9FAFB] rounded px-1.5 py-0.5",children:[h.length," change",h.length!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-[#667085]",children:[e.jsx(js,{size:12,className:"shrink-0"}),e.jsx("span",{children:t.changedAt})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-[#344054] font-medium",children:[e.jsx(pl,{size:12,className:"shrink-0 text-[#98A2B3]"}),e.jsx("span",{children:t.changedByName||t.changedBy||"â"})]})]}),e.jsx(Ct,{size:16,className:`shrink-0 text-[#98A2B3] transition-transform duration-200 ${d?"rotate-0":"-rotate-90"}`})]}),d&&e.jsx("div",{className:"border-t border-[#E4E7EC] bg-[#FAFBFC] p-4",children:B?e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-sm text-[#667085]",children:"Initial version â no prior state to compare"}),e.jsx("p",{className:"text-xs text-[#98A2B3] mt-1",children:"This is the first recorded state of this configuration"})]}):x==="accessPolicy"?e.jsx(kl,{entry:t}):e.jsx(_l,{entry:t})})]})}function $l({configType:t,count:x,isOpen:d,onToggle:c}){const h=dt[t]||dt.accessPolicy;return e.jsxs("button",{type:"button",onClick:c,className:"w-full flex items-center gap-3 py-2 group",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg",style:{backgroundColor:h.bg,border:`1px solid ${h.border}`},children:e.jsx(h.icon,{size:16,style:{color:h.color}})}),e.jsx("h4",{className:"text-sm font-semibold text-[#181D27] group-hover:text-[#444CE7] transition-colors",children:h.label}),e.jsx("span",{className:"text-xs font-semibold rounded-full px-2 py-0.5",style:{backgroundColor:h.bg,color:h.color,border:`1px solid ${h.border}`},children:x}),e.jsx(Ct,{size:14,className:`ml-auto text-[#98A2B3] transition-transform duration-200 ${d?"rotate-0":"-rotate-90"}`})]})}const zl=({historyEntries:t,historyLoading:x})=>{const[d,c]=n.useState(null),[h,B]=n.useState({}),S=["accessPolicy","complianceConfig","deploymentConfig","complianceBypass"],E=S.reduce((v,p)=>{var D;return v+(((D=t==null?void 0:t[p])==null?void 0:D.length)||0)},0);return x?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:[e.jsx(H,{size:28,className:"animate-spin text-[#444CE7]"}),e.jsx("p",{className:"text-sm text-[#667085]",children:"Loading historyâ¦"})]}):E===0?e.jsxs("div",{className:"text-center py-20 space-y-4",children:[e.jsx("div",{className:"mx-auto w-16 h-16 rounded-2xl bg-gradient-to-br from-[#F2F4F7] to-[#E4E7EC] flex items-center justify-center shadow-sm",children:e.jsx(Is,{size:28,className:"text-[#98A2B3]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-semibold text-[#344054]",children:"No changes recorded yet"}),e.jsx("p",{className:"text-sm text-[#98A2B3] mt-1 max-w-[20rem] mx-auto",children:"Changes are automatically tracked when policies are created, modified, or deleted"})]})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-xl bg-[#F9FAFB] border border-[#
1E4E7EC]",children:[e.jsx(Is,{size:16,className:"text-[#667085] shrink-0"}),e.jsxs("p",{className:"text-sm text-[#535862]",children:[e.jsx("span",{className:"font-semibold text-[#181D27]",children:E})," ","change",E!==1?"s":""," across"," ",e.jsx("span",{className:"font-semibold text-[#181D27]",children:S.filter(v=>{var p;return(p=t==null?void 0:t[v])==null?void 0:p.length}).length})," ","config type",S.filter(v=>{var p;return(p=t==null?void 0:t[v])==null?void 0:p.length}).length!==1?"s":""]})]}),S.map(v=>{const p=t==null?void 0:t[v];if(!(p!=null&&p.length))return null;const D=h[v]!==!1;return e.jsxs("div",{children:[e.jsx($l,{configType:v,count:p.length,isOpen:D,onToggle:()=>B(_=>({..._,[v]:!D}))}),D&&e.jsx("div",{className:"space-y-2.5 mt-2 ml-[2.75rem]",children:p.map((_,T)=>{const W=`${v}-${T}`;return e.jsx(Pl,{entry:_,configType:v,expanded:d===W,onToggle:()=>c(d===W?null:W)},W)})})]},v)})]})},Ye=["learningContent","exams","studio","codePlayground","mockInterviews","placementSupport"],pt={learningContent:"Learning Content",exams:"Exams",studio:"Workspace",codePlayground:"Code Playground",mockInterviews:"Mock Interviews",placementSupport:"Placement Support"},fs=["canView","canCreate","canEdit","canDelete"],ut={canView:"View",canCreate:"Create",canEdit:"Edit",canDelete:"Delete"},Es=t=>{if(!t)return null;const x=String(t).replace(/\s*IST\s*$/i,"").trim(),d=new Date(x);return isNaN(d.getTime())?new Date(t):d},bt=t=>{if(!t)return"";const x=Es(t);return x&&!isNaN(x.getTime())?x.toISOString().split("T")[0]:String(t).split(" ")[0]||""},gs=t=>{const x=Es(t);return!x||isNaN(x.getTime())?0:Math.ceil((x-new Date)/864e5)},Ie=()=>({canView:!1,canCreate:!1,canEdit:!1,canDelete:!1}),Cs=({visible:t,onClose:x,targetType:d,targetValue:c,targetLabel:h,targetStatus:B,isSynced:S,onSaved:E,onDeleted:v})=>{var Xs,Vs,et,st,tt,lt,at;const p=Qe(),D=ge(s=>{var a,m;return(m=(a=s.accessControl)==null?void 0:a.metadata)==null?void 0:m.data}),_=ge(s=>{var a,m;return(m=(a=s.accessControl)==null?void 0:a.policy)==null?void 0:m.saving}),T=ge(s=>{var a,m;return(m=(a=s.accessControl)==null?void 0:a.policy)==null?void 0:m.deleting}),[W,L]=n.useState(!1),[C,J]=n.useState(!1),[b,P]=n.useState(null),[y,z]=n.useState({}),[oe,Z]=n.useState(null),[M,V]=n.useState([]),[se,Q]=n.useState({}),[f,F]=n.useState(1),[q,ae]=n.useState(""),[U,ee]=n.useState({batch:[],location:[]}),[X,r]=n.useState({}),[j,Y]=n.useState(null),[ne,re]=n.useState(!1),[le,ie]=n.useState(!1),[ye,G]=n.useState(null),[je,Ee]=n.useState(!1),[me,i]=n.useState(null),[g,I]=n.useState([]),[K,ce]=n.useState(!0),[Ce,he]=n.useState([]),[Pe,be]=n.useState(""),[De,pe]=n.useState(""),[o,A]=n.useState(""),[k,fe]=n.useState(!1),[de,Ae]=n.useState(!1),[qe,Se]=n.useState(!1),[ue,Le]=n.useState("modules"),[Ne,xe]=n.useState(null),[ss,$e]=n.useState({feeThreshold:"",attendanceThreshold:"",gracePeriodDays:""}),[ke,Me]=n.useState(!1),[ts,Je]=n.useState(!1),[Ds,Fe]=n.useState(!1),[_e,ze]=n.useState({}),[As,ls]=n.useState(!1),[Ys,ms]=n.useState(null),Ss=()=>{if(!c||!d)return;const s=d==="userId"?{userId:c}:d==="batch"?{batch:c}:{location:c};ls(!0),ms(null),Zt(s).then(a=>{const m=(a==null?void 0:a.history)||{};Array.isArray(m)?ze({accessPolicy:m}):ze(m)}).catch(()=>ze({})).finally(()=>ls(!1))},hs=()=>{!c||!d||(L(!0),p(rt({[d]:c})).unwrap().then(s=>{if(s!=null&&s.studentInfo&&P(s.studentInfo),s&&!s.message){J(!0);const a=s.moduleAccess||{},m={};Ye.forEach(N=>{const $=a[N];$==null?m[N]={enabled:!1,granular:!1,perms:Ie()}:typeof $=="boolean"?m[N]={enabled:$,granular:!1,perms:{canView:$,canCreate:$,canEdit:$,canDelete:$}}:typeof $=="object"&&(m[N]={enabled:!!($.canView||$.canCreate||$.canEdit||$.canDelete),granular:!0,perms:{canView:!!$.canView,canCreate:!!$.canCreate,canEdit:!!$.canEdit,canDelete:!!$.canDelete}})}),z(m);const w=s.templateAccess||{};V(w.allowedTemplates||[]),Q(w.templateLimits||{}),F(w.deployLimit??0)}}).catch(()=>{}).finally(()=>L(!1)))},ps=()=>{if(!c||d!=="userId"&&d!=="batch")return;it(d==="userId"?{userId:c}:{batch:c}).then(a=>{const m=(a==null?void 0:a.complianceConfig)||null;xe(m),m&&($e({feeThreshold:m.feeThreshold??"",attendanceThreshold:m.attendanceThreshold??"",gracePeriodDays:m.gracePeriodDays??""}),Fe(!0))}).catch(()=>xe(null))},us=()=>{!c||d!=="userId"||p(is(c)).unwrap().then(s=>{const a=(s==null?void 0:s.complianceBypass)||null;if(i(a),a){I(a.checks||[]),ce(a.modules===null||a.modules===void 0),he(a.modules||[]);const m=Es(a.deadline);if(m&&!isNaN(m.getTime())){be(m.toISOString().split("T")[0]);const w=m.getHours(),N=m.getMinutes();pe(w===23&&N===59?"":`${String(w).padStart(2,"0")}
1:${String(N).padStart(2,"0")}`)}else be(bt(a.deadline)),pe("");A(a.reason||""),Se(!0)}}).catch(()=>i(null))},l=s=>{Le(s),s==="modules"||s==="templates"?hs():s==="compliance"?ps():s==="bypass"?us():s==="history"&&Ss()},u=(D==null?void 0:D.templates)||[];n.useEffect(()=>{D||p(vt())},[p,D]),n.useEffect(()=>{if(!t||!c)return;L(!0),J(!1),P(null),Z(null),ae(""),re(!1),ie(!1),G(null),Ee(!1),i(null),I([]),ce(!0),he([]),be(""),pe(""),A(""),Se(!1),Le("modules"),xe(null),$e({feeThreshold:"",attendanceThreshold:"",gracePeriodDays:""}),Me(!1),Je(!1),Fe(!1),ze({}),ls(!1),ms(null);const s={[d]:c};p(rt(s)).unwrap().then(a=>{if(a!=null&&a.studentInfo&&P(a.studentInfo),a&&!a.message){J(!0);const m=a.moduleAccess||{},w={};Ye.forEach($=>{const te=m[$];te==null?w[$]={enabled:!1,granular:!1,perms:Ie()}:typeof te=="boolean"?w[$]={enabled:te,granular:!1,perms:{canView:te,canCreate:te,canEdit:te,canDelete:te}}:typeof te=="object"&&(w[$]={enabled:!!(te.canView||te.canCreate||te.canEdit||te.canDelete),granular:!0,perms:{canView:!!te.canView,canCreate:!!te.canCreate,canEdit:!!te.canEdit,canDelete:!!te.canDelete}})}),z(w);const N=a.templateAccess||{};V(N.allowedTemplates||[]),Q(N.templateLimits||{}),F(N.deployLimit??0)}else R()}).catch(()=>R()).finally(()=>L(!1)),(d==="userId"||d==="batch")&&it(d==="userId"?{userId:c}:{batch:c}).then(m=>{const w=(m==null?void 0:m.complianceConfig)||null;xe(w),w&&($e({feeThreshold:w.feeThreshold??"",attendanceThreshold:w.attendanceThreshold??"",gracePeriodDays:w.gracePeriodDays??""}),Fe(!0))}).catch(()=>xe(null)),Ss(),d==="userId"?(p(Qt({id:c})).unwrap().then(a=>{a&&a.userType==="student"&&P(m=>({...m,status:a.status,blocked:a.blocked,reasons:a.reasons||[],attendance:a.attendance||(m==null?void 0:m.attendance)||null}))}).catch(()=>{}),p(is(c)).unwrap().then(a=>{const m=(a==null?void 0:a.complianceBypass)||null;if(i(m),m){I(m.checks||[]),ce(m.modules===null||m.modules===void 0),he(m.modules||[]);const w=Es(m.deadline);if(w&&!isNaN(w.getTime())){be(w.toISOString().split("T")[0]);const N=w.getHours(),$=w.getMinutes();pe(N===23&&$===59?"":`${String(N).padStart(2,"0")}:${String($).padStart(2,"0")}`)}else be(bt(m.deadline)),pe("");A(m.reason||""),Se(!0)}}).catch(()=>i(null)),p(Jt(c)).unwrap().then(a=>{ee({batch:Array.isArray(a==null?void 0:a.batch)?a.batch:[],location:Array.isArray(a==null?void 0:a.location)?a.location:[]}),r(a!=null&&a.deployLimits&&typeof a.deployLimits=="object"?a.deployLimits:{}),Y((a==null?void 0:a.currentDeployments)??null)}).catch(()=>{ee({batch:[],location:[]}),r({}),Y(null)})):(ee({batch:[],location:[]}),r({}),Y(null))},[p,t,c,d]);const R=()=>{const s={};Ye.forEach(a=>{s[a]={enabled:!1,granular:!1,perms:Ie()}}),z(s),V([]),Q({}),F(0),ee({batch:[],location:[]}),r({}),Y(null),re(!1),ie(!1),G(null),Ee(!1),i(null),I([]),ce(!0),he([]),be(""),pe(""),A(""),Se(!1),xe(null),$e({feeThreshold:"",attendanceThreshold:"",gracePeriodDays:""}),Fe(!1),ze({}),ms(null)},Be=async()=>{const s=d==="userId"?{userId:c}:{batch:c},{feeThreshold:a,attendanceThreshold:m,gracePeriodDays:w}=ss;if(a!==""&&a!==null&&(s.feeThreshold=Number(a)),m!==""&&m!==null&&(s.attendanceThreshold=Number(m)),w!==""&&w!==null&&(s.gracePeriodDays=Number(w)),!("feeThreshold"in s)&&!("attendanceThreshold"in s)&&!("gracePeriodDays"in s)){O.error("Set at least one threshold value");return}Me(!0);try{const N=await Vt(s);xe((N==null?void 0:N.complianceConfig)||s),O.success("Compliance config saved")}catch(N){O.error((N==null?void 0:N.message)||"Failed to save compliance config")}finally{Me(!1)}},ve=async()=>{const s=d==="userId"?{userId:c}:{batch:c};Je(!0);try{await Xt(s),xe(null),$e({feeThreshold:"",attendanceThreshold:"",gracePeriodDays:""}),O.success("Compliance config deleted â reverted to defaults")}catch(a){O.error((a==null?void 0:a.message)||"Failed to delete compliance config")}finally{Je(!1)}},Ue=async()=>{if(!g.length||!Pe||!o.trim()){O.error("Fill all bypass fields: checks, deadline, reason");return}fe(!0);try{await p(wt({userId:c,checks:g,modules:K?null:Ce,deadline:De?`${Pe}T${De}:00`:Pe,reason:o.trim()})).unwrap(),O.success("Compliance bypass saved");const s=await p(is(c)).unwrap();i((s==null?void 0:s.complianceBypass)||null)}catch(s){O.error((s==null?void 0:s.message)||"Failed to set bypass")}finally{fe(!1)}},ks=async()=>{Ae(!0);try{await p(Ts(c)).unwrap(),O.success("Bypass revoked"),i(null),I([]),ce(!0),he([]),be(""),pe(""),A("")}catch(s){O.error((s==null?void 0:s.message)||"Failed to revoke bypass")}finally{Ae(!1)}},zt=s=>{z(a=>{const m=a[s],w=!m.enabled;return s==="studio"&&w&&d!=="location"&&!S&&!ye?(re(!0),a):(s==="studio"&&!w&&re(!1),{...a,[s]:{...m,enabled:w,perms:w?{canView:!0,canCreate:!0,canEdit:!0,canDelete:!0}:Ie()}})})},Lt=async()=>{ie(!0);try{const a=await p(cs(d==="batch"?{batch:c}:{id:c})).unwrap();
1G(a),re(!1),z(w=>{const N=w.studio||{enabled:!1,granular:!1,perms:Ie()};return{...w,studio:{...N,enabled:!0,perms:{canView:!0,canCreate:!0,canEdit:!0,canDelete:!0}}}}),d==="batch"?O.success(`Synced: ${(a==null?void 0:a.successful)||0} successful, ${(a==null?void 0:a.failed)||0} failed`):O.success(a!=null&&a.alreadyExists?"Already synced":"Synced successfully")}catch(s){O.error((s==null?void 0:s.message)||"Sync failed")}finally{ie(!1)}},Gs=s=>{var a;z(m=>{const w=m[s];if(!!w.granular){const $=fs.some(te=>w.perms[te]);return{...m,[s]:{...w,granular:!1,enabled:$,perms:$?{canView:!0,canCreate:!0,canEdit:!0,canDelete:!0}:Ie()}}}return{...m,[s]:{...w,granular:!0}}}),(a=y[s])!=null&&a.granular||Z(s)},Tt=(s,a)=>{z(m=>{const w=m[s],N={...w.perms,[a]:!w.perms[a]},$=fs.some(te=>N[te]);return{...m,[s]:{...w,perms:N,enabled:$}}})},Ks=s=>{const a={};Ye.forEach(m=>{const w=y[m]||{},N=s?{canView:!0,canCreate:!0,canEdit:!0,canDelete:!0}:Ie();a[m]={...w,enabled:s,perms:N}}),z(a)},Mt=s=>{V(a=>a.includes(s)?(Q(m=>{const w={...m};return delete w[s],w}),a.filter(m=>m!==s)):(Q(m=>({...m,[s]:m[s]??0})),[...a,s]))},Qs=async()=>{const s={};Ye.forEach(N=>{const $=y[N];if(!$){s[N]=!1;return}$.granular?s[N]={...$.perms}:s[N]=$.enabled});const a={[d]:c,moduleAccess:s},m=y.studio;if(m!=null&&m.enabled&&M.length>0){a.templateAccess={allowedTemplates:M,deployLimit:f};const N={};M.forEach($=>{N[$]=se[$]!=null&&se[$]>=0?se[$]:0}),a.templateAccess.templateLimits=N}else a.templateAccess=null;const w=await p(sl(a));w.error?O.error(w.payload||"Failed to save policy"):(O.success(`Policy saved for "${h||c}"`),E==null||E(),x())},Js=async()=>{const s=await p(el({[d]:c}));s.error?O.error(s.payload||"Failed to delete policy"):(O.success(`Policy deleted for "${h||c}"`),v==null||v(),x())},Zs=q?u.filter(s=>`${s.name||""} ${s.id}`.toLowerCase().includes(q.toLowerCase())):u;if(!t)return null;const _s=(Xs=y.studio)==null?void 0:Xs.enabled,It=[{key:"modules",label:"Modules"},..._s?[{key:"templates",label:"Templates"}]:[],...d==="userId"||d==="batch"?[{key:"compliance",label:"Compliance"}]:[],{key:"deployment",label:"Deployment"},...d==="userId"?[{key:"bypass",label:"Bypass"}]:[],{key:"history",label:"History"}];return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-black/40 backdrop-blur-sm",onClick:x}),e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-8",children:e.jsxs("div",{className:"w-full max-w-4xl max-h-[90vh] bg-white rounded-2xl shadow-2xl flex flex-col overflow-hidden",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"px-6 py-4 border-b border-[#E9EAEB] flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#2333CB]/10 flex items-center justify-center",children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#2333CB",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-bold text-[#181D27]",children:[C?"Edit":"Set"," Policy"]}),e.jsx("p",{className:"text-sm text-[#667085]",children:h||c})]})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("button",{type:"button",onClick:x,className:"h-9 w-9 rounded-lg border border-[#E9EAEB] flex items-center justify-center hover:bg-[#F9FAFB] transition-colors",children:e.jsx(Bt,{size:16,className:"text-[#667085]"})})})]}),d==="userId"&&b&&e.jsxs("div",{className:"px-6 py-3 bg-[#F9FAFB] border-b border-[#E9EAEB] flex items-center gap-3 flex-wrap shrink-0",children:[e.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border ${b.status==="Active"?"border-emerald-200 bg-emerald-50":"border-gray-200 bg-gray-50"}`,children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${b.status==="Active"?"bg-emerald-500":"bg-gray-400"}`}),e.jsx("span",{className:`text-sm font-semibold ${b.status==="Active"?"text-emerald-700":"text-gray-500"}`,children:b.status})]}),b.blocked&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg border border-red-300 bg-red-50",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-red-500"}),e.jsx("span",{className:"text-sm font-semibold text-red-600",children:"Blocked"})]}),b.fee&&e.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border ${b.fee.paidPercent<40?"border-red-200 bg-red-50":"border-emerald-200 bg-emerald-50"}`,children:[e.jsxs("span",{className:`text-sm font-semibold ${b.fee.paidPercent<40?"text-red-600":"text-emerald-700"}`,children:["Fee: ",b.fee.paidPercent,"%"]}),e.jsxs("span",{className:"text-sm text-gray-400",children:["(",b.fee.paid,"/",b.fee.total,")"]})]}),((Vs=b.fee)==null?void 0:Vs.dueDate)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-gray-200 bg-white",children:[e.jsx(Fs,{size:12,className:"text-gray-400"}),e.jsxs("span",{className:"text-sm text-gray-500",children:["Due: ",b.fee.dueDate]})]}),((et=b.attendance)==null?void 0:et.overall)&&e.jsx("div",{className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border ${(((st=b.attendance.overall)==null?void 0:st.percentage)??(typeof b.attendance.overall=="number"?b.attendance.overall:0))<75?"border-red-200 bg-red-50":"border-emerald-200 bg-emerald-50"}`,children:e.jsxs("span",{className:`text-sm font-semibold ${(((tt=b.attendance.overall)==null?void 0:tt.percentage)??(typeof b.attendance.overall=="number"?b.attendance.overall:0))<75?"text-red-600":"text-emerald-700"}`,children:["Attend:"," ",typeof b.attendance.overall=="number"?b.attendance.overall.toFixed(0):typeof((lt=b.attendance.overall)==null?void 0:lt.percentage)=="number"?b.attendance.overall.percentage.toFixed(0):"-","%"]})}),((at=b.reasons)==null?void 0:at.length)>0&&e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:b.reasons.map((s,a)=>e.jsx("span",{className:"text-sm font-medium px-2 py-1 rounded-md border border-red-200 bg-red-50 text-red-600",children:s},a))})]}
1),!W&&e.jsx("div",{className:"px-6 border-b border-[#E9EAEB] flex items-center gap-0 shrink-0 overflow-x-auto",children:It.map(s=>e.jsx("button",{onClick:()=>l(s.key),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${ue===s.key?"border-[#2333CB] text-[#2333CB]":"border-transparent text-gray-400 hover:text-gray-600"}`,children:s.label},s.key))}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:W?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(H,{size:24,className:"animate-spin text-[#2333CB]"})}):e.jsxs(e.Fragment,{children:[ue==="modules"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-base font-semibold text-[#181D27]",children:"Module Access"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Ks(!0),className:"text-sm font-medium px-3 py-1.5 rounded-lg border border-emerald-200 bg-emerald-50 text-emerald-700 hover:bg-emerald-100 transition-colors",children:"Enable All"}),e.jsx("button",{type:"button",onClick:()=>Ks(!1),className:"text-sm font-medium px-3 py-1.5 rounded-lg border border-red-200 bg-red-50 text-red-600 hover:bg-red-100 transition-colors",children:"Disable All"})]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Ye.map(s=>{const a=y[s]||{enabled:!1,granular:!1,perms:Ie()},m=a.enabled,w=fs.filter(N=>a.perms[N]);return e.jsxs("div",{className:`rounded-xl border-2 overflow-hidden transition-all ${m?"border-[#2333CB]/30 bg-white":"border-[#
1E9EAEB] bg-[#FAFBFC]"}`,children:[e.jsxs("div",{className:"px-4 py-3.5 flex items-center justify-between cursor-pointer",onClick:()=>zt(s),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center shrink-0 transition-colors ${m?"bg-[#2333CB]":"bg-gray-200"}`,children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:m?e.jsx("polyline",{points:"20 6 9 17 4 12"}):e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-base font-semibold text-[#181D27]",children:pt[s]}),e.jsx("p",{className:`text-xs ${m?"text-emerald-600":"text-gray-400"}`,children:a.granular?w.length?w.map(N=>ut[N]).join(", "):"No permissions":m?"Full access":"Disabled"})]})]}),e.jsx("span",{className:`text-sm font-bold px-2.5 py-1 rounded-md ${m?"bg-emerald-100 text-emerald-700":"bg-gray-100 text-gray-500"}`,children:m?"ON":"OFF"})]}),m&&e.jsx("div",{className:"border-t border-[#E9EAEB] px-4 py-3 bg-[#FAFBFC] space-y-2.5",children:a.granular?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 gap-2",children:fs.map(N=>e.jsxs("button",{type:"button",onClick:$=>{$.stopPropagation(),Tt(s,N)},className:`flex items-center justify-between px-3 py-2 rounded-lg border text-sm font-medium transition-all ${a.perms[N]?"border-[#2333CB]/30 bg-[#2333CB]/5 text-[#2333CB]":"border-[#E9EAEB] bg-white text-gray-400 hover:border-gray-300"}`,children:[e.jsx("span",{children:ut[N]}),e.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center ${a.perms[N]?"bg-[#2333CB]":"bg-gray-200"}`,children:a.perms[N]&&e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"4",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})})]},N))}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),z($=>({...$,[s]:{...$[s],enabled:!0,perms:{canView:!0,canCreate:!0,canEdit:!0,canDelete:!0}}}))},className:"text-sm font-medium text-emerald-600 hover:underline",children:"All On"}),e.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),z($=>({...$,[s]:{...$[s],enabled:!0,perms:{canView:!0,canCreate:!1,canEdit:!1,canDelete:!1}}}))},className:"text-sm font-medium text-gray-500 hover:underline",children:"View Only"})]}),e.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),Gs(s)},className:"text-sm font-medium text-gray-400 hover:text-gray-600 hover:underline",children:"Back to simple"})]})]}):e.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),Gs(s)},className:"text-sm text-[#2333CB] font-medium hover:underline",children:"Set individual permissions â"})})]},s)})})]}),ue==="modules"&&ne&&e.jsxs("div",{className:"rounded-xl border border-[#FEC84B] bg-[#FFFAEB] p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ve,{size:16,className:"text-[#B54708] shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[#B54708]",children:"Sync Required"}),e.jsx("p",{className:"text-sm text-[#B54708] mt-1",children:d==="batch"?"Students in this batch must be synced to the Studio Workspace engine before enabling workspace access. Please sync first.":"This user must be synced to the Studio Workspace engine before enabling workspace access. Please sync first."})]})]}),ye&&d==="batch"&&e.jsxs("div",{className:"flex gap-3 text-xs",children:[e.jsxs("span",{className:"text-[#067647] font-medium",children:[ye.successful||0," synced"]}),(ye.failed||0)>0&&e.jsxs("span",{className:"text-[#B42318] font-medium",children:[ye.failed," failed"]})]}),e.jsxs("button",{type:"button",onClick:()=>Ee(!0),disabled:le,className:"h-9 px-4 rounded-lg bg-[#B54708] text-white text-sm font-semibold inline-flex items-center gap-1.5 hover:bg-[#93370D] transition disabled:opacity-50",children:[le?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(we,{size:14}),le?"Syncing...":"Sync Now"]})]}),je&&e.jsx("div",{className:"fixed inset-0 z-[70] flex items-center justify-center bg-black/40",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-sm mx-4 p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-[#FFFAEB] flex items-center justify-center",children:e.jsx(we,{size:20,className:"text-[#B54708]"})}),e.jsx("h3",{className:"text-xl font-bold text-[#181D27]",children:"Sync to Studio"})]}),e.jsx("p",{className:"text-sm text-[#535862] mb-3",children:d==="batch"?`Sync all students in "${h||c}" to the Studio Workspace engine?`:`Sync "${h||c}" to the Studio Workspace engine?`}),B&&e.jsx("div",{className:"mb-3",children:e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-sm font-semibold ${B==="Active"?"bg-[#ECFDF3] text-[#067647] border border-[#ABEFC6]":"bg-[#F2F4F7] text-[#667085] border border-[#D0D5DD]"}`,children:B})}),e.jsx("p",{className:"text-sm text-[#B54708] mb-5",children:"This is required to enable workspace access. Already synced users will be skipped."}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>Ee(!1),className:"px-4 py-2 text-base font-semibold text-[#344054] border border-[#D0D5DD] rounded-lg hover:bg-[#F9FAFB]",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:()=>{Ee(!1),Lt()},className:"px-4 py-2 text-base font-semibold text-white bg-[#B54708] rounded-lg hover:bg-[#93370D] inline-flex items-center gap-1.5",children:[e.jsx(we,{size:14})," Sync Now"]})]})]})}),ue==="bypass"&&d==="userId"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-base font-semibold text-[#181D27] inline-flex items-center gap-2",children:["Compliance Bypass",me&&e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${gs(me.deadline)<=0?"bg-red-50 text-red-600 border border-red-200":gs(me.deadline)<=7?"bg-amber-50 text-amber-700 border border-amber-200":"bg-emerald-50 text-emerald-700 border border-emerald-200"}`,children:gs(me.deadline)<=0?"Expired":`${gs(me.deadline)}d left`})]}),e.jsxs("div",{className:"space-y-3 rounded-xl border border-[#
1E4E7EC] bg-white p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[#475467] mb-1.5",children:"Checks to Bypass"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:[{value:"fee",label:"Fee"},{value:"attendance",label:"Attendance"},{value:"status",label:"Status"}].map(s=>e.jsx("button",{type:"button",onClick:()=>I(a=>a.includes(s.value)?a.filter(m=>m!==s.value):[...a,s.value]),className:`h-9 px-3 rounded-lg border text-sm font-medium transition ${g.includes(s.value)?"border-[#B54708] bg-[#B54708] text-white":"border-[#D5D7DA] bg-white text-[#344054] hover:bg-[#F9FAFB]"}`,children:s.label},s.value))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[#475467] mb-1.5",children:"Module Scope"}),e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("button",{type:"button",onClick:()=>ce(!0),className:`h-8 px-3 rounded-lg text-sm font-semibold transition ${K?"bg-[#B54708] text-white":"bg-white border border-[#D5D7DA] text-[#344054]"}`,children:"All"}),e.jsx("button",{type:"button",onClick:()=>ce(!1),className:`h-8 px-3 rounded-lg text-sm font-semibold transition ${K?"bg-white border border-[#D5D7DA] text-[#344054]":"bg-[#B54708] text-white"}`,children:"Specific"})]}),!K&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ye.map(s=>e.jsx("button",{type:"button",onClick:()=>he(a=>a.includes(s)?a.filter(m=>m!==s):[...a,s]),className:`h-8 px-3 rounded-lg text-sm font-medium transition ${Ce.includes(s)?"border-[#C7D7FE] bg-[#EEF4FF] text-[#2333CB]":"border-[#E9EAEB] bg-white text-[#344054]"} border`,children:pt[s]},s))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[#475467] mb-1.5",children:"Deadline"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Fs,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-[#667085] pointer-events-none z-[1]"}),e.jsx("input",{type:"date",min:new Date(Date.now()+864e5).toISOString().split("T")[0],value:Pe,onChange:s=>be(s.target.value),onClick:s=>{var a,m;return(m=(a=s.target).showPicker)==null?void 0:m.call(a)},className:"w-full h-8 pl-7 pr-2 rounded-md border border-[#D5D7DA] text-sm text-[#344054] outline-none focus:border-[#B54708] cursor-pointer [&::-webkit-calendar-picker-indicator]:cursor-pointer [&::-webkit-calendar-picker-indicator]:opacity-100"})]}),e.jsx("div",{className:"relative w-[90px]",children:e.jsx("input",{type:"time",value:De,onChange:s=>pe(s.target.value),onClick:s=>{var a,m;return(m=(a=s.target).showPicker)==null?void 0:m.call(a)},className:"w-full h-8 px-2 rounded-md border border-[#D5D7DA] text-sm text-[#344054] outline-none focus:border-[#B54708] cursor-pointer [&::-webkit-calendar-picker-indicator]:cursor-pointer [&::-webkit-calendar-picker-indicator]:opacity-100"})})]}),e.jsx("p",{className:"text-sm text-[#98A2B3] mt-0.5",children:"Time optional â defaults to 11:59 PM IST"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[#475467] mb-1.5",children:"Reason"}),e.jsx("textarea",{value:o,onChange:s=>A(s.target.value),placeholder:"Reason for bypass...",rows:2,className:"w-full px-2 py-1.5 rounded-md border border-[#D5D7DA] text-sm text-[#344054] outline-none focus:border-[#B54708] resize-none"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[me?e.jsxs("button",{type:"button",onClick:ks,disabled:de,className:"h-9 px-4 rounded-lg border border-[#FEE2E2] text-[#B42318] text-sm font-semibold hover:bg-[#FEF3F2] inline-flex items-center gap-1 disabled:opacity-50",children:[de?e.jsx(H,{size:10,className:"animate-spin"}):e.jsx(Ge,{size:10})," ","Revoke"]}):e.jsx("div",{}),e.jsxs("button",{type:"button",onClick:Ue,disabled:k||!g.length||!Pe||!o.trim(),className:"h-9 px-4 rounded-lg bg-[#B54708] text-white text-sm font-semibold inline-flex items-center gap-1 hover:bg-[#93370D] disabled:opacity-50",children:[k?e.jsx(H,{size:10,className:"animate-spin"}):e.jsx(ns,{size:10})," ",me?"Update":"Set"," Bypass"]})]})]})]}),ue==="compliance"&&(d==="userId"||d==="batch")&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-base font-semibold text-[#181D27] inline-flex items-center gap-2",children:["Compliance Thresholds",Ne&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-medium bg-[#F9F5FF] text-[#6941C6] border border-[#D6BBFB]",children:"Custom"})]}),e.jsxs("div",{className:"space-y-3 rounded-xl border border-[#
1E4E7EC] bg-white p-4",children:[[{key:"feeThreshold",label:"Fee Threshold (%)",min:0,max:100,placeholder:"Default: 40%"},{key:"attendanceThreshold",label:"Attendance Threshold (%)",min:0,max:100,placeholder:"Default: 75%"},{key:"gracePeriodDays",label:"Grace Period (days)",min:0,max:365,placeholder:"Default: 40 days"}].map(s=>e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[#475467] mb-1",children:s.label}),e.jsx("input",{type:"text",inputMode:"numeric",value:ss[s.key],onChange:a=>{const m=a.target.value.replace(/[^0-9]/g,"");if(m===""){$e(N=>({...N,[s.key]:""}));return}const w=Math.min(Number(m),s.max);$e(N=>({...N,[s.key]:w}))},onKeyDown:a=>{["e","E","+","-","."].includes(a.key)&&a.preventDefault()},placeholder:s.placeholder,className:"w-full h-8 px-2.5 rounded-md border border-[#D5D7DA] text-sm text-[#344054] outline-none focus:border-[#6941C6] placeholder-[#98A2B3]"})]},s.key)),e.jsxs("p",{className:"text-sm text-[#98A2B3]",children:["Leave blank to use"," ",d==="userId"?"batch/":"","global defaults. Resolution: Student â Batch â Global."]}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[Ne?e.jsxs("button",{type:"button",onClick:ve,disabled:ts,className:"h-9 px-4 rounded-lg border border-[#FEE2E2] text-[#B42318] text-sm font-semibold hover:bg-[#FEF3F2] inline-flex items-center gap-1 disabled:opacity-50",children:[ts?e.jsx(H,{size:10,className:"animate-spin"}):e.jsx(Ge,{size:10})," ","Revert"]}):e.jsx("div",{}),e.jsxs("button",{type:"button",onClick:Be,disabled:ke,className:"h-9 px-4 rounded-lg bg-[#6941C6] text-white text-sm font-semibold inline-flex items-center gap-1 hover:bg-[#5925DC] disabled:opacity-50",children:[ke?e.jsx(H,{size:10,className:"animate-spin"}):e.jsx(ns,{size:10})," ",Ne?"Update":"Set"," Config"]})]})]})]}),ue==="deployment"&&(d==="userId"||d==="batch"||d==="location")&&e.jsx(Bl,{targetType:d,targetValue:c,targetLabel:h}),ue==="templates"&&_s&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-[#181D27] mb-3",children:"Template Access"}),d==="userId"&&(U.batch.length>0||U.location.length>0||Object.keys(X).length>0)&&e.jsxs("div",{className:"mb-4 space-y-2",children:[U.batch.length>0&&e.jsxs("div",{className:"px-3 py-2.5 rounded-lg border border-[#E9EAEB] bg-[#F9FAFB]",children:[e.jsx("p",{className:"text-sm font-semibold text-[#475467] uppercase tracking-wider mb-1.5",children:"From Batch Policy"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:U.batch.map(s=>{const a=u.find(m=>m.id===s.templateId);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-1 rounded-md border border-[#E4E7EC] bg-white text-sm text-[#344054]",children:[(a==null?void 0:a.name)||s.templateId,s.limit!=null?e.jsxs("span",{className:"text-sm text-[#667085]",children:[s.used,"/",s.limit]}):e.jsxs("span",{className:"text-sm text-[#667085]",children:[s.used," used"]})]},s.templateId)})})]}),U.location.length>0&&e.jsxs("div",{className:"px-3 py-2.5 rounded-lg border border-[#E9EAEB] bg-[#F9FAFB]",children:[e.jsx("p",{className:"text-sm font-semibold text-[#475467] uppercase tracking-wider mb-1.5",children:"From Location Policy"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:U.location.map(s=>{const a=u.find(m=>m.id===s.templateId);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-1 rounded-md border border-[#E4E7EC] bg-white text-sm text-[#344054]",children:[(a==null?void 0:a.name)||s.templateId,s.limit!=null?e.jsxs("span",{className:"text-sm text-[#667085]",children:[s.used,"/",s.limit]}):e.jsxs("span",{className:"text-sm text-[#667085]",children:[s.used," used"]})]},s.templateId)})})]}),(Object.keys(X).filter(s=>s!=="user").length>0||j!==null)&&e.jsxs("div",{className:"px-3 py-2.5 rounded-lg border border-[#E9EAEB] bg-[#F9FAFB]",children:[e.jsx("p",{className:"text-sm font-semibold text-[#475467] uppercase tracking-wider mb-1.5",children:"Deploy Info"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Object.entries(X).filter(([s])=>s!=="user").map(([s,a])=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-md border border-[#
1E4E7EC] bg-white text-sm text-[#344054]",children:[e.jsxs("span",{className:"text-sm text-[#667085] capitalize",children:[s,":"]})," ",a]},s)),j!==null&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-md border border-[#C7D7FE] bg-[#EEF4FF] text-sm text-[#2333CB]",children:["Current: ",j," deployed"]})]})]})]}),e.jsx("p",{className:"text-sm font-medium text-[#475467] mb-2",children:d==="userId"?"User-Level Templates":"Allowed Templates"}),e.jsxs("div",{className:"border border-[#E9EAEB] rounded-xl overflow-hidden",children:[e.jsx("div",{className:"px-3 py-2 border-b border-[#E9EAEB] bg-[#F9FAFB]",children:e.jsx("input",{type:"text",placeholder:"Search templates...",value:q,onChange:s=>ae(s.target.value),className:"w-full text-sm outline-none bg-transparent text-[#344054] placeholder-[#98A2B3]"})}),e.jsxs("div",{className:"max-h-52 overflow-y-auto no-scrollbar",children:[Zs.length===0&&e.jsx("p",{className:"text-sm text-[#667085] px-3 py-3",children:"No templates found."}),Zs.map(s=>{const a=M.includes(s.id);return e.jsxs("button",{type:"button",onClick:()=>Mt(s.id),className:`w-full text-left px-3 py-2.5 flex items-center justify-between border-b border-[#F2F4F7] last:border-0 hover:bg-[#F9FAFB] transition ${a?"bg-[#EEF4FF]":""}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:`text-sm truncate ${a?"text-[#2333CB] font-medium":"text-[#344054]"}`,children:s.name||s.id}),e.jsx("p",{className:"text-sm text-[#667085] font-mono",children:s.id})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.freeTier&&e.jsx("span",{className:"text-sm text-[#067647] bg-[#ECFDF3] px-1.5 py-0.5 rounded border border-[#ABEFC6]",children:"Free"}),a&&e.jsx(ul,{size:14,className:"text-[#2333CB]"})]})]},s.id)})]})]}),e.jsxs("p",{className:"text-sm text-[#667085] mt-2",children:[M.length," template",M.length!==1?"s":""," selected"]}),M.length>0&&e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-[#475467] uppercase tracking-wider",children:"Workspace Limits per Template"}),M.map(s=>{const a=u.find(m=>m.id===s);return e.jsxs("div",{className:"flex items-center justify-between py-2 px-3 rounded-lg border border-[#E9EAEB] bg-[#F9FAFB]",children:[e.jsx("span",{className:"text-sm text-[#344054] font-medium truncate mr-3",children:(a==null?void 0:a.name)||s}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Q(m=>({...m,[s]:Math.max(0,(m[s]??0)-1)})),className:"w-7 h-7 rounded border border-[#D5D7DA] flex items-center justify-center hover:bg-white text-sm font-bold",children:"â"}),e.jsx("input",{type:"number",min:"0",value:se[s]??0,onChange:m=>{const w=parseInt(m.target.value,10);Q(N=>({...N,[s]:w>=0?w:0}))},className:"w-12 h-7 text-center text-sm border border-[#D5D7DA] rounded outline-none focus:border-[#2333CB] [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),e.jsx("button",{type:"button",onClick:()=>Q(m=>({...m,[s]:(m[s]??0)+1})),className:"w-7 h-7 rounded border border-[#D5D7DA] flex items-center justify-center hover:bg-white text-sm font-bold",children:"+"})]})]},s)}),e.jsx("p",{className:"text-sm text-[#98A2B3]",children:"Set 0 to block workspace creation for a template."})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-semibold text-[#475467] uppercase tracking-wider mb-1.5",children:"Deploy Limit"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>F(s=>Math.max(0,s-1)),className:"w-8 h-8 rounded-lg border border-[#D5D7DA] flex items-center justify-center hover:bg-[#F9FAFB] text-sm font-bold",children:"â"}),e.jsx("input",{type:"number",min:"0",value:f,onChange:s=>{const a=parseInt(s.target.value,10);F(a>=0?a:0)},className:"w-12 h-8 text-center text-base font-semibold text-[#181D27] border border-[#D5D7DA] rounded-lg outline-none focus:border-[#2333CB] [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),e.jsx("button",{type:"button",onClick:()=>F(s=>s+1),className:"w-8 h-8 rounded-lg border border-[#D5D7DA] flex items-center justify-center hover:bg-[#F9FAFB] text-sm font-bold",children:"+"})]})]})]})]})}),ue==="history"&&e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-6",children:e.jsx(zl,{historyEntries:_e,historyLoading:As})}),!W&&ue==="modules"&&e.jsx("div",{className:"border-t border-[#
1E9EAEB] px-6 py-4 flex items-center justify-between shrink-0 bg-[#FAFBFC]",children:_s?e.jsxs(e.Fragment,{children:[e.jsx("div",{}),e.jsx("button",{type:"button",onClick:()=>Le("templates"),className:"h-9 px-5 rounded-lg bg-[#2333CB] text-white text-sm font-semibold hover:opacity-95 transition inline-flex items-center gap-1.5",children:"Next: Templates â"})]}):e.jsxs(e.Fragment,{children:[C?e.jsxs("button",{type:"button",onClick:Js,disabled:T,className:"h-9 px-4 rounded-lg border border-[#FEE2E2] text-[#B42318] text-sm font-semibold hover:bg-[#FEF3F2] transition inline-flex items-center gap-1.5 disabled:opacity-50",children:[T?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Ge,{size:12})," ","Delete Policy"]}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:x,className:"h-9 px-4 rounded-lg border border-[#D5D7DA] text-[#344054] text-sm font-semibold hover:bg-[#F9FAFB]",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:Qs,disabled:_,className:"h-9 px-4 rounded-lg bg-[#2333CB] border border-[#4F5CD5] text-white text-sm font-semibold inline-flex items-center gap-1.5 hover:opacity-95 disabled:opacity-50",children:[_?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(ns,{size:14})," ","Save Policy"]})]})]})}),!W&&ue==="templates"&&e.jsxs("div",{className:"border-t border-[#E9EAEB] px-6 py-4 flex items-center justify-between shrink-0 bg-[#FAFBFC]",children:[C?e.jsxs("button",{type:"button",onClick:Js,disabled:T,className:"h-9 px-4 rounded-lg border border-[#FEE2E2] text-[#B42318] text-sm font-semibold hover:bg-[#FEF3F2] transition inline-flex items-center gap-1.5 disabled:opacity-50",children:[T?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Ge,{size:12})," ","Delete Policy"]}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:x,className:"h-9 px-4 rounded-lg border border-[#D5D7DA] text-[#344054] text-sm font-semibold hover:bg-[#F9FAFB]",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:Qs,disabled:_,className:"h-9 px-4 rounded-lg bg-[#2333CB] border border-[#4F5CD5] text-white text-sm font-semibold inline-flex items-center gap-1.5 hover:opacity-95 disabled:opacity-50",children:[_?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(ns,{size:14})," ","Save Policy"]})]})]})]})})]})},Re=20,$s="/admin/access-control/batches",Ll=[{label:"Inactive",value:"Inactive"},{label:"Active",value:"Active"},{label:"Completed",value:"Completed"},{label:"All",value:""}],Tl=()=>{var hs,ps,us;const t=Qe(),x=Us(),d=Nt(),{items:c,total:h,loading:B,error:S}=ge(l=>{var u;return((u=l.accessControl)==null?void 0:u.batches)||{}}),E=ge(l=>{var u,R;return(R=(u=l.accessControl)==null?void 0:u.locations)==null?void 0:R.data}),[v,p]=n.useState(1),[D,_]=n.useState(""),[T,W]=n.useState(""),[L,C]=n.useState(""),[J,b]=n.useState(""),P=n.useRef(null),[y,z]=n.useState(null),[oe,Z]=n.useState({}),[M,V]=n.useState([]),[se,Q]=n.useState(!1),[f,F]=n.useState(!1),[q,ae]=n.useState(null),[U,ee]=n.useState({items:[],total:0}),[X,r]=n.useState(!1),[j,Y]=n.useState(1),[ne,re]=n.useState(""),[le,ie]=n.useState(""),ye=n.useRef(null),[G,je]=n.useState(null),[Ee,me]=n.useState({}),[i,g]=n.useState([]),[I,K]=n.useState(!1),[ce,Ce]=n.useState(!1),[he,Pe]=n.useState(!1),[be,De]=n.useState(null),pe=Ft(`${$s}/view/:batchId`,d.pathname),o=(hs=pe==null?void 0:pe.params)!=null&&hs.batchId?decodeURIComponent(pe.params.batchId):null,A=l=>{C(l),P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{b(l.trim()),p(1)},400)},k=l=>{re(l),ye.current&&clearTimeout(ye.current),ye.current=setTimeout(()=>{ie(l.trim()),Y(1)},400)},fe=n.useCallback(()=>{const l={page:v,pageSize:Re};D&&(l.status=D),T&&(l.location=T),J&&(l.search=J),t(tl(l))},[t,v,D,T,J]),de=n.useCallback(async(l,u=1)=>{r(!0);try{const R={page:u,pageSize:Re};le&&(R.search=le);const[Be,ve]=await Promise.all([t(ll(l)).unwrap(),t(al({batch:l,...R})).unwrap()]);ae(Be),ee(ve)}catch{ae(null),ee({items:[],total:0})}finally{r(!1)}},[le,t]),Ae=l=>{Y(1),re(""),ie(""),g([]),De(null),x(`${$s}/view/${encodeURIComponent(l)}`),de(l,1)},qe=()=>{x($s),ae(null),ee({items:[],total:0}),re(""),ie(""),De(null),g([]),je(null)},Se=async()=>
1{if(o){Pe(!0);try{const l=await t(cs({batch:o})).unwrap();De(l),O.success(`Batch synced: ${(l==null?void 0:l.successful)||0} successful, ${(l==null?void 0:l.failed)||0} failed`),de(o,j)}catch(l){O.error((l==null?void 0:l.message)||"Batch sync failed")}finally{Pe(!1)}}},ue=async()=>{if(i.length){K(!0);try{const l=i.map(ve=>{var Ue;return(Ue=(U.items||[]).find(ks=>ks.id===ve))==null?void 0:Ue.email}).filter(Boolean),u=await t(cs(l.length>0?{emails:l}:{ids:i})).unwrap(),R=Array.isArray(u)?u.filter(ve=>ve.success).length:(u==null?void 0:u.successful)||i.length,Be=Array.isArray(u)?u.filter(ve=>!ve.success).length:(u==null?void 0:u.failed)||0;O.success(`Synced: ${R} successful, ${Be} failed`),g([]),de(o,j)}catch(l){O.error((l==null?void 0:l.message)||"Bulk sync failed")}finally{K(!1)}}},Le=async()=>{if(M.length){Q(!0);try{const l=await t(cs({batches:M})).unwrap();O.success(`Bulk sync: ${(l==null?void 0:l.totalSuccessful)||0} successful, ${(l==null?void 0:l.totalFailed)||0} failed across ${M.length} batches`),V([]),fe()}catch(l){O.error((l==null?void 0:l.message)||"Bulk sync failed")}finally{Q(!1)}}},Ne=l=>{V(u=>u.includes(l)?u.filter(R=>R!==l):[...u,l])},xe=l=>{g(u=>u.includes(l)?u.filter(R=>R!==l):[...u,l])},ss=()=>{const l=(c||[]).filter(u=>u.Status==="Active"&&!u.isSynced);V(l.map(u=>u.Batch))},$e=()=>{const l=(U.items||[]).filter(u=>u.status==="Active"&&!u.isSynced);g(l.map(u=>u.id))};n.useEffect(()=>{fe()},[fe]),n.useEffect(()=>{E||t(Ws())},[t,E]),n.useEffect(()=>{c!=null&&c.length&&Z(l=>{const u={...l};return c.forEach(R=>{R.hasPolicy!==void 0&&(u[R.Batch]=R.hasPolicy)}),u})},[c]),n.useEffect(()=>{o&&de(o,j)},[o,j,le,de]),n.useEffect(()=>{o||(ae(null),ee({items:[],total:0}),re(""),ie(""),Y(1),De(null),g([]))},[o]),n.useEffect(()=>{var l;!o||!((l=U.items)!=null&&l.length)||t(nl({batch:o,hasPolicy:!0,pageSize:100})).unwrap().then(u=>{var R;(R=u==null?void 0:u.items)!=null&&R.length&&me(Be=>{const ve={...Be};return u.items.forEach(Ue=>{Ue.id&&(ve[Ue.id]=!0)}),ve})}).catch(()=>{})},[t,o,U.items]);const ke=c||[],Me=Math.ceil((h||0)/Re),ts=B&&ke.length===0,Je=B&&ke.length>0,Ds=(E==null?void 0:E.locations)||[],Fe=ke.filter(l=>l.Status==="Active"&&!l.isSynced),_e=(U.items||[]).filter(l=>l.status==="Active"&&!l.isSynced),ze=Math.ceil((U.total||0)/Re),As=(q==null?void 0:q.studentCount)??U.total,ls=M.length>0?`${M.length} batch${M.length!==1?"es":""} selected`:`${Fe.length} active batch${Fe.length!==1?"es":""} not synced`,Ys=i.length>0?`${i.length} student${i.length!==1?"s":""} selected`:`${_e.length} active student${_e.length!==1?"s":""} not synced`;return e.jsx("div",{className:"w-full space-y-4",children:o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:qe,className:"inline-flex h-10 w-10 items-center justify-center rounded-xl border border-[#D5D7DA] bg-white text-[#344054] shadow-sm transition hover:bg-[#F9FAFB]",children:e.jsx(Dt,{size:18})}),e.jsx("div",{className:"min-w-0",children:e.jsx("h2",{className:"truncate text-[1.15rem] font-semibold tracking-tight text-[#181D27] sm:text-[1.25rem] lg:text-[1.35rem]",children:o})})]}),e.jsx("div",{className:"min-w-0 flex overflow-hidden rounded-[24px] border border-[#E4E7EC] bg-white shadow-sm",style:{height:"clamp(31rem, calc(100dvh - 12rem), 70rem)"},children:e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"shrink-0 flex flex-col gap-3 border-b border-[#E9EAEB] px-4 py-4 sm:px-5 sm:py-5 2xl:flex-row 2xl:items-center 2xl:justify-between",children:[e.jsxs("span",{className:"inline-flex w-fit items-center rounded-xl border border-[#FEDF89] bg-[#FFF7ED] px-3 py-1.5 text-xs font-medium text-[#C4320A] sm:text-sm",children:[As," Students"]}),e.jsxs("label",{className:"flex min-w-0 w-full items-center gap-3 rounded-xl border border-[#D5D7DA] bg-white px-3.5 py-2.5 text-sm text-[#667085] shadow-sm sm:px-4 sm:py-3 2xl:max-w-[31rem]",children:[e.jsx(ds,{size:18,className:"shrink-0 text-[#667085]"}),e.jsx("input",{type:"text",placeholder:"Search",value:ne,onChange:l=>k(l.target.value),className:"w-full border-0 bg-transparent p-0 text-sm text-[#344054] outline-none placeholder:text-[#98A2B3]"})]})]}),e.jsx("div",{className:"min-h-0 min-w-0 flex-1 overflow-hidden",children:e.jsx("div",{className:"h-full w-full overflow-auto leaderboard-scrollbar-custom",children:e.jsxs("table",{className:"min-w-[920px] w-full text-left sm:min-w-[1040px] xl:min-w-[1120px]",children:[e.jsx("thead",{className:"bg-[#FCFCFD]",children:e.jsxs("tr",{className:"border-b border-[#
1E9EAEB]",children:[e.jsx("th",{className:"sticky top-0 z-20 w-14 bg-[#FCFCFD] px-4 py-3.5 shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4",children:e.jsx("input",{type:"checkbox",checked:i.length===_e.length&&_e.length>0,onChange:l=>l.target.checked?$e():g([]),disabled:_e.length===0,className:"h-5 w-5 rounded-md border-[#D0D5DD] text-[#2333CB] focus:ring-[#C7D7FE] disabled:opacity-40"})}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4 sm:text-sm",children:"Name/Location"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Batch"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Status"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Student ID/Location"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Synced"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-right text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4 sm:text-sm",children:"Action"})]})}),e.jsx("tbody",{children:X?Array.from({length:8}).map((l,u)=>e.jsxs("tr",{className:"border-b border-[#E9EAEB] last:border-0",children:[e.jsx("td",{className:"px-5 py-5",children:e.jsx("div",{className:"h-5 w-5 rounded-md bg-[#EAECF0]"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-[#EAECF0]"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 w-32 rounded bg-[#EAECF0]"}),e.jsx("div",{className:"h-3 w-40 rounded bg-[#F2F4F7]"})]})]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-28 rounded-xl bg-[#F4F3FF]"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-20 rounded-full bg-[#ECFDF3]"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 w-24 rounded bg-[#EAECF0]"}),e.jsx("div",{className:"h-3 w-24 rounded bg-[#F2F4F7]"})]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-24 rounded-full bg-[#EEF4FF]"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("div",{className:"ml-auto h-11 w-32 rounded-xl bg-[#EAECF0]"})})]},`student-skeleton-${u}`)):(U.items||[]).map(l=>{const u=(l.name||"?").split(" ").filter(Boolean).slice(0,2).map(R=>{var Be;return(Be=R[0])==null?void 0:Be.toUpperCase()}).join("");return e.jsxs("tr",{className:"border-b border-[#E9EAEB] transition hover:bg-[#F9FAFB] last:border-0",children:[e.jsx("td",{className:"px-5 py-5",children:e.jsx("input",{type:"checkbox",checked:i.includes(l.id),onChange:()=>xe(l.id),disabled:!(l.status==="Active"&&!l.isSynced),className:"h-5 w-5 rounded-md border-[#D0D5DD] text-[#2333CB] focus:ring-[#C7D7FE] disabled:opacity-40"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-[#EEF4FF] text-sm font-semibold text-[#2333CB]",children:u}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-[1.05rem] font-semibold text-[#181D27]",children:l.name||"-"}),e.jsx("p",{className:"truncate text-sm text-[#667085]",children:l.email||l.location||"-"})]})]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("span",{className:"inline-flex items-center rounded-xl border border-[#D9D6FE] bg-[#F4F3FF] px-3 py-1 text-sm font-medium text-[#6941C6]",children:o})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("span",{className:`inline-flex items-center gap-2 rounded-full border px-3 py-1 text-sm font-medium ${l.status==="Active"?"border-[#A6F4C5] bg-[#ECFDF3] text-[#027A48]":"border-[#D0D5DD] bg-[#F2F4F7] text-[#667085]"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${l.status==="Active"?"bg-[#12B76A]":"bg-[#98A2B3]"}`}),l.status||"-"]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[1.05rem] font-semibold text-[#181D27]",children:l.studentId||"-"}),e.jsx("p",{className:"text-sm text-[#667085]",children:l.location||(q==null?void 0:q.location)||"-"})]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("span",{className:`inline-flex items-center gap-2 rounded-full border px-3 py-1 text-sm font-medium ${l.isSynced?"border-[#B2DDFF] bg-[#EFF8FF] text-[#1570EF]":"border-[#FEC84B] bg-[#FFFAEB] text-[#B54708]"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${l.isSynced?"bg-[#2E90FA]":"bg-[#F79009]"}`}),l.isSynced?"Synced":"Not Synced"]})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:()=>je(l),className:`inline-flex h-11 min-w-[8.75rem] items-center justify-center gap-2 rounded-xl px-4 text-sm font-semibold transition ${Ee[l.id]?"border border-[#D0D5DD] bg-white text-[#344054] hover:bg-[#F9FAFB]":"bg-[#2333CB] text-white hover:opacity-95"}`,children:Ee[l.id]?e.jsxs(e.Fragment,{children:[e.jsx(vs,{size:16})," Edit Policy"]}):e.jsxs(e.Fragment,{children:[e.jsx(ws,{size:16})," Set Policy"]})})})})]},l.id)})})]})})}),!X&&(U.items||[]).length===0&&e.jsx("div",{className:"shrink-0 border-t border-[#
1E9EAEB] px-4 py-10 text-center",children:e.jsx("p",{className:"text-sm font-medium text-[#344054]",children:"No students found."})}),ze>1&&e.jsxs("div",{className:"shrink-0 flex gap-3 border-t border-[#E9EAEB] px-4 py-4 items-center justify-between flex-nowrap",children:[e.jsxs("p",{className:"text-xs text-[#667085] sm:text-sm",children:[(j-1)*Re+1,"-",Math.min(j*Re,U.total)," of"," ",U.total]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Y(l=>Math.max(1,l-1)),disabled:j===1,className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border border-[#D5D7DA] text-[#344054] transition hover:bg-[#F9FAFB] disabled:opacity-40",children:e.jsx(Rs,{size:16})}),e.jsxs("span",{className:"px-2 text-sm font-medium text-[#344054]",children:[j," / ",ze]}),e.jsx("button",{type:"button",onClick:()=>Y(l=>Math.min(ze,l+1)),disabled:j>=ze,className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border border-[#D5D7DA] text-[#344054] transition hover:bg-[#F9FAFB] disabled:opacity-40",children:e.jsx(Ns,{size:16})})]})]}),e.jsxs("div",{className:"shrink-0 flex flex-col gap-3 border-t border-[#E9EAEB] px-4 py-4 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("label",{className:"inline-flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:i.length===_e.length&&_e.length>0,onChange:l=>l.target.checked?$e():g([]),disabled:_e.length===0,className:"h-5 w-5 rounded-md border-[#D0D5DD] text-[#2333CB] focus:ring-[#C7D7FE] disabled:opacity-40"}),e.jsxs("span",{className:"rounded-xl border border-[#E4E7EC] bg-white px-3 py-2 text-xs font-medium text-[#344054] sm:text-sm",children:[i.length," Selected"]})]}),e.jsx("p",{className:"text-xs text-[#667085] sm:text-sm",children:_e.length>0?Ys:"All active students in this batch are synced"})]}),e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:flex-row xl:w-auto",children:[e.jsxs("button",{type:"button",onClick:()=>Ce(!0),disabled:i.length===0||he||I,className:"inline-flex h-11 w-full items-center justify-center gap-2 rounded-xl border border-[#D0D5DD] bg-white px-5 text-sm font-semibold text-[#344054] shadow-sm transition hover:bg-[#F9FAFB] disabled:cursor-not-allowed disabled:border-[#E4E7EC] disabled:bg-[#F9FAFB] disabled:text-[#98A2B3] xl:h-12 xl:w-auto",children:[I?e.jsx(H,{size:16,className:"animate-spin"}):e.jsx(we,{size:16}),i.length>0?`Sync Students (${i.length})`:"Sync Students"]}),e.jsxs("button",{type:"button",onClick:Se,disabled:he||I,className:"inline-flex h-11 w-full items-center justify-center gap-2 rounded-xl bg-[#2333CB] px-5 text-sm font-semibold text-white shadow-sm transition hover:opacity-95 disabled:opacity-50 xl:h-12 xl:w-auto",children:[he?e.jsx(H,{size:16,className:"animate-spin"}):e.jsx(we,{size:16}),be?`Sync Batch (${be.successful}/${be.total})`:"Sync Batch"]})]})]})]})}),ce&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40",children:e.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-white p-6 shadow-xl",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-[#FFFAEB]",children:e.jsx(we,{size:20,className:"text-[#B54708]"})}),e.jsx("h3",{className:"text-lg font-semibold text-[#181D27]",children:"Sync Students"})]}),e.jsxs("p",{className:"mb-2 text-sm text-[#535862]",children:["Sync"," ",e.jsxs("span",{className:"font-semibold text-[#181D27]",children:[i.length," student",i.length!==1?"s":""]})," ","to the Studio Workspace engine?"]}),e.jsx("div",{className:"mb-4 flex max-h-24 flex-wrap gap-1.5 overflow-y-auto no-scrollbar",children:i.map(l=>{const u=(U.items||[]).find(R=>R.id===l);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-md border border-[#E9EAEB] bg-[#F9FAFB] px-2 py-0.5 text-xs text-[#344054]",children:[(u==null?void 0:u.name)||(u==null?void 0:u.email)||l,(u==null?void 0:u.status)&&e.jsx("span",{className:`rounded px-1.5 py-px text-[9px] font-semibold ${u.status==="Active"?"bg-[#ECFDF3] text-[#067647]":"bg-[#F2F4F7] text-[#667085]"}`,children:u.status})]},l)})}),e.jsx("p",{className:"mb-5 text-xs text-[#B54708]",children:"Already synced users will be skipped."}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>Ce(!1),className:"rounded-lg border border-[#D0D5DD] px-4 py-2 text-sm font-semibold text-[#344054] hover:bg-[#F9FAFB]",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:()=>{Ce(!1),ue()},disabled:I,className:"inline-flex items-center gap-1.5 rounded-lg bg-[#B54708] px-4 py-2 text-sm font-semibold text-white hover:bg-[#93370D] disabled:opacity-50",children:[I?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(we,{size:14}),"Sync Now"]})]})]})}),e.jsx(Cs,{visible:!!G,onClose:()=>je(null),targetType:"userId",targetValue:G==null?void 0:G.id,targetLabel:G?`${G.name||"Student"} (${o})`:"",targetStatus:G==null?void 0:G.status,isSynced:!!(G!=null&&G.isSynced),onSaved:()=>{me(l=>({...l,[G==null?void 0:G.id]:!0})),de(o,j)},onDeleted:()=>{me(l=>({...l,[G==null?void 0:G.id]:!1})),de(o,j)}})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"min-w-0 flex overflow-hidden rounded-[24px] border border-[#
1E4E7EC] bg-white shadow-sm",style:{height:"clamp(33rem, calc(100dvh - 12.5rem), 72rem)"},children:e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"shrink-0 flex flex-col gap-4 border-b border-[#E9EAEB] px-4 py-4 sm:px-5 sm:py-5 2xl:flex-row 2xl:items-center 2xl:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 max-w-full items-center gap-3 overflow-x-auto pb-1 no-scrollbar",children:[e.jsx("div",{className:"inline-flex items-center rounded-full border border-[#D5D7DA] bg-white p-1",children:Ll.map(l=>e.jsx("button",{type:"button",onClick:()=>{_(l.value),p(1)},className:`whitespace-nowrap rounded-full px-3.5 py-2 text-xs font-semibold transition sm:px-4 sm:text-sm ${D===l.value?"border border-[#4F5CD5] bg-[#EEF4FF] text-[#2333CB]":"text-[#475467] hover:bg-[#F8FAFC]"}`,children:l.label},l.label))}),Je&&e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-2 rounded-full border border-[#D5D7DA] bg-[#F8FAFC] px-3 py-1 text-xs font-medium text-[#475467]",children:[e.jsx(H,{size:12,className:"animate-spin"}),"Refreshing"]})]}),e.jsxs("div",{className:"flex min-w-0 w-full flex-col gap-3 xl:flex-row 2xl:w-auto",children:[e.jsxs("label",{className:"flex min-w-0 w-full items-center gap-3 rounded-xl border border-[#D5D7DA] bg-white px-3.5 py-2.5 text-sm text-[#667085] shadow-sm sm:px-4 sm:py-3 xl:flex-1 2xl:min-w-[26rem]",children:[e.jsx(ds,{size:18,className:"shrink-0 text-[#667085]"}),e.jsx("input",{type:"text",placeholder:"Search",value:L,onChange:l=>A(l.target.value),className:"w-full border-0 bg-transparent p-0 text-sm text-[#344054] outline-none placeholder:text-[#98A2B3]"})]}),Ds.length>0&&e.jsxs("label",{className:"inline-flex w-full items-center gap-2 rounded-xl border border-[#D5D7DA] bg-white px-3.5 py-2.5 text-sm font-medium text-[#475467] shadow-sm sm:px-4 sm:py-3 xl:w-auto",children:[e.jsx(Xe,{size:18,className:"shrink-0 text-[#667085]"}),e.jsx("select",{value:T,onChange:l=>{W(l.target.value),p(1)},className:"min-w-0 flex-1 border-0 bg-transparent p-0 pr-6 text-sm font-medium text-[#475467] outline-none md:min-w-[8rem]",children:Ds.map(l=>e.jsx("option",{value:l=="all"?"":l,children:l=="all"?"All Locations":l},l))})]})]})]}),S&&e.jsx("p",{className:"shrink-0 px-4 py-4 text-sm text-[#B42318]",children:S}),e.jsxs("div",{className:"relative min-h-0 min-w-0 flex-1 overflow-hidden",children:[Je&&e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 z-30 h-1 bg-[#EEF4FF]",children:e.jsx("div",{className:"h-full w-1/3 animate-pulse rounded-full bg-[#2333CB]"})}),e.jsx("div",{className:"h-full w-full overflow-auto leaderboard-scrollbar-custom",children:e.jsxs("table",{className:"min-w-[980px] w-full text-left sm:min-w-[1080px] xl:min-w-[1180px]",children:[e.jsx("thead",{className:"bg-[#FCFCFD]",children:e.jsxs("tr",{className:"border-b border-[#E9EAEB]",children:[e.jsx("th",{className:"sticky top-0 z-20 w-14 bg-[#FCFCFD] px-4 py-3.5 shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4",children:e.jsx("input",{type:"checkbox",checked:M.length===Fe.length&&Fe.length>0,onChange:l=>l.target.checked?ss():V([]),disabled:Fe.length===0,className:"h-5 w-5 rounded-md border-[#D0D5DD] text-[#2333CB] focus:ring-[#C7D7FE] disabled:opacity-40"})}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4 sm:text-sm",children:"Batch/Location"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Policy"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Status"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Students Count"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Synced"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-right text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4 sm:text-sm",children:"Action"})]})}),e.jsx("tbody",{children:ts?Array.from({length:8}).map((l,u)=>
1e.jsxs("tr",{className:"border-b border-[#E9EAEB] last:border-0",children:[e.jsx("td",{className:"px-5 py-5",children:e.jsx("div",{className:"h-5 w-5 rounded-md bg-[#EAECF0]"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 w-28 rounded bg-[#EAECF0]"}),e.jsx("div",{className:"h-3 w-24 rounded bg-[#F2F4F7]"})]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-32 rounded-xl bg-[#F4F3FF]"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-20 rounded-full bg-[#ECFDF3]"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-4 w-24 rounded bg-[#EAECF0]"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-24 rounded-full bg-[#EEF4FF]"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"ml-auto flex justify-end gap-3",children:[e.jsx("div",{className:"h-10 w-16 rounded-xl bg-[#F2F4F7]"}),e.jsx("div",{className:"h-11 w-32 rounded-xl bg-[#EAECF0]"})]})})]},`batch-skeleton-${u}`)):ke.map(l=>{const u=l.Batch,R=oe[u],Be=l.studentCount,ve=l.Status==="Active"&&!l.isSynced;return e.jsxs("tr",{className:"border-b border-[#E9EAEB] transition hover:bg-[#F9FAFB] last:border-0",children:[e.jsx("td",{className:"px-5 py-5",children:e.jsx("input",{type:"checkbox",checked:M.includes(u),onChange:()=>Ne(u),disabled:!ve,className:"h-5 w-5 rounded-md border-[#D0D5DD] text-[#2333CB] focus:ring-[#C7D7FE] disabled:opacity-40"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[1.05rem] font-semibold text-[#181D27]",children:u}),e.jsx("p",{className:"text-sm text-[#667085]",children:l.location||"-"})]})}),e.jsx("td",{className:"px-4 py-5",children:R===!0?e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-xl border border-[#D9D6FE] bg-[#F4F3FF] px-3 py-1 text-sm font-medium text-[#6941C6]",children:[e.jsx(Oe,{size:14}),"Policy Configured"]}):R===!1?e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-xl border border-[#E4E7EC] bg-[#F8FAFC] px-3 py-1 text-sm font-medium text-[#475467]",children:[e.jsx(Os,{size:14}),"No Policy"]}):e.jsx("span",{className:"inline-flex items-center rounded-xl border border-[#E4E7EC] bg-[#F8FAFC] px-3 py-1 text-sm font-medium text-[#98A2B3]",children:"Loading"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("span",{className:`inline-flex items-center gap-2 rounded-full border px-3 py-1 text-sm font-medium ${l.Status==="Active"?"border-[#A6F4C5] bg-[#ECFDF3] text-[#027A48]":"border-[#D0D5DD] bg-[#F2F4F7] text-[#667085]"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${l.Status==="Active"?"bg-[#12B76A]":"bg-[#98A2B3]"}`}),l.Status||"-"]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("p",{className:"text-[1.05rem] font-medium text-[#344054]",children:[Be??0," Students"]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("span",{className:`inline-flex items-center gap-2 rounded-full border px-3 py-1 text-sm font-medium ${l.isSynced?"border-[#B2DDFF] bg-[#EFF8FF] text-[#1570EF]":"border-[#FEC84B] bg-[#FFFAEB] text-[#B54708]"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${l.isSynced?"bg-[#2E90FA]":"bg-[#F79009]"}`}),l.isSynced?"Synced":"Not Synced"]})}),e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>Ae(u),className:"inline-flex h-10 items-center gap-2 rounded-xl border border-transparent bg-transparent px-2 text-sm font-semibold text-[#344054] transition hover:text-[#181D27]",children:[e.jsx(bl,{size:16}),"View"]}),e.jsx("button",{type:"button",onClick:()=>z(u),className:`inline-flex h-11 min-w-[8.75rem] items-center justify-center gap-2 rounded-xl px-4 text-sm font-semibold transition ${R?"border border-[#D0D5DD] bg-white text-[#344054] hover:bg-[#F9FAFB]":"bg-[#2333CB] text-white hover:opacity-95"}`,children:R?e.jsxs(e.Fragment,{children:[e.jsx(vs,{size:16})," Edit Policy"]}):e.jsxs(e.Fragment,{children:[e.jsx(ws,{size:16})," Set Policy"]})})]})})]},u)})})]})})]}),!ts&&ke.length===0&&e.jsx("div",{className:"shrink-0 border-t border-[#
1E9EAEB] px-4 py-10 text-center",children:e.jsx("p",{className:"text-sm font-medium text-[#344054]",children:L.trim()?`No batches found for "${L}".`:"No batches found."})}),Me>1&&e.jsxs("div",{className:"shrink-0 flex gap-3 border-t border-[#E9EAEB] px-4 py-4 items-center justify-between",children:[e.jsxs("p",{className:"text-xs text-[#667085] sm:text-sm",children:[(v-1)*Re+1,"-",Math.min(v*Re,h)," of ",h]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>p(l=>Math.max(1,l-1)),disabled:v===1,className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border border-[#D5D7DA] text-[#344054] transition hover:bg-[#F9FAFB] disabled:opacity-40",children:e.jsx(Rs,{size:16})}),e.jsxs("span",{className:"px-2 text-sm font-medium text-[#344054]",children:[v," / ",Me]}),e.jsx("button",{type:"button",onClick:()=>p(l=>Math.min(Me,l+1)),disabled:v>=Me,className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border border-[#D5D7DA] text-[#344054] transition hover:bg-[#F9FAFB] disabled:opacity-40",children:e.jsx(Ns,{size:16})})]})]}),e.jsxs("div",{className:"shrink-0 flex flex-col gap-3 border-t border-[#E9EAEB] px-4 py-4 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("label",{className:"inline-flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:M.length===Fe.length&&Fe.length>0,onChange:l=>l.target.checked?ss():V([]),disabled:Fe.length===0,className:"h-5 w-5 rounded-md border-[#D0D5DD] text-[#2333CB] focus:ring-[#C7D7FE] disabled:opacity-40"}),e.jsxs("span",{className:"rounded-xl border border-[#E4E7EC] bg-white px-3 py-2 text-xs font-medium text-[#344054] sm:text-sm",children:[M.length," Selected"]})]}),e.jsx("p",{className:"text-xs text-[#667085] sm:text-sm",children:Fe.length>0?ls:"All active batches are synced"})]}),e.jsxs("button",{type:"button",onClick:()=>F(!0),disabled:M.length===0||se,className:"inline-flex h-11 w-full items-center justify-center gap-2 rounded-xl bg-[#2333CB] px-5 text-sm font-semibold text-white shadow-sm transition hover:opacity-95 disabled:opacity-50 xl:h-12 xl:w-auto",children:[se?e.jsx(H,{size:16,className:"animate-spin"}):e.jsx(we,{size:16}),"Sync Batches"]})]})]})}),f&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40",children:e.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-white p-6 shadow-xl",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-[#FFFAEB]",children:e.jsx(we,{size:20,className:"text-[#B54708]"})}),e.jsx("h3",{className:"text-lg font-semibold text-[#181D27]",children:"Sync Batches"})]}),e.jsxs("p",{className:"mb-2 text-sm text-[#535862]",children:["Sync"," ",e.jsxs("span",{className:"font-semibold text-[#181D27]",children:[M.length," batch",M.length!==1?"es":""]})," ","to the Studio Workspace engine?"]}),e.jsx("div",{className:"mb-4 flex max-h-24 flex-wrap gap-1.5 overflow-y-auto no-scrollbar",children:M.map(l=>{const u=(ke||[]).find(R=>R.Batch===l);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-md border border-[#E9EAEB] bg-[#F9FAFB] px-2 py-0.5 text-xs text-[#344054]",children:[l,(u==null?void 0:u.Status)&&e.jsx("span",{className:`rounded px-1.5 py-px text-[9px] font-semibold ${u.Status==="Active"?"bg-[#ECFDF3] text-[#067647]":"bg-[#F2F4F7] text-[#667085]"}`,children:u.Status})]},l)})}),e.jsx("p",{className:"mb-5 text-xs text-[#B54708]",children:"All students in these batches will be synced. Already synced users will be skipped."}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>F(!1),className:"rounded-lg border border-[#D0D5DD] px-4 py-2 text-sm font-semibold text-[#344054] hover:bg-[#F9FAFB]",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:()=>{F(!1),Le()},disabled:se,className:"inline-flex items-center gap-1.5 rounded-lg bg-[#B54708] px-4 py-2 text-sm font-semibold text-white hover:bg-[#93370D] disabled:opacity-50",children:[se?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(we,{size:14}),"Sync Now"]})]})]})}),e.jsx(Cs,{visible:!!y,onClose:()=>z(null),targetType:"batch",targetValue:y,targetLabel:y,isSynced:!!((ps=(ke||[]).find(l=>l.Batch===y))!=null&&ps.isSynced),targetStatus:(us=(ke||[]).find(l=>l.Batch===y))==null?void 0:us.Status,onSaved:()=>{Z(l=>({...l,[y]:!0}))},onDeleted:()=>{Z(l=>({...l,[y]:!1}))}})]})})},Pt=[{label:"All",value:"all"},{label:"No Policy",value:"missing"},{label:"Policy",value:"configured"}],Ml=new Set(Pt.map(t=>t.value)),ft=t=>Ml.has(t)?t:"all",Il={learningContent:"Learning Content",exams:"Exams",studio:"Worksp
1ace",codePlayground:"Code Playground",mockInterviews:"Mock Interviews",placementSupport:"Placement Support"},Rl=()=>{var Q;const t=Qe(),[x,d]=xs(),{items:c,loading:h,error:B}=ge(f=>{var F;return((F=f.accessControl)==null?void 0:F.locationPolicies)||{}}),S=ge(f=>{var F;return((F=f.accessControl)==null?void 0:F.locations)||{}}),E=Ke(x,"ac_locations_q"),v=ft(Ke(x,"ac_locations_filter","all")),[p,D]=n.useState(null),_=f=>{Hs(d,F=>{Bs(F,St),f(F)})},T=f=>{_(F=>{Te(F,"ac_locations_q",f)})},W=f=>{_(F=>{Te(F,"ac_locations_filter",ft(f),"all")})},L=n.useCallback(()=>{t(rl()),S.data||t(Ws())},[t,S.data]);n.useEffect(()=>{L()},[L]);const C=f=>f!=null&&f.moduleAccess?Object.entries(f.moduleAccess).filter(([,F])=>typeof F=="boolean"?F:!!(F!=null&&F.canView)).map(([F])=>Il[F]||F):[],J={};(c||[]).forEach(f=>{f!=null&&f.location&&(J[f.location]=f)});const b=((Q=S.data)==null?void 0:Q.locations)||[],P=b.map(f=>{var F;return{location:f,hasPolicy:!!J[f],policy:((F=J[f])==null?void 0:F.accessPolicy)||null}});(c||[]).forEach(f=>{f!=null&&f.location&&!b.includes(f.location)&&P.push({location:f.location,hasPolicy:!0,policy:f.accessPolicy||null})});const y=P.filter(f=>f.hasPolicy).length,z=P.length-y,oe=P.filter(f=>{const F=E.trim()?f.location.toLowerCase().includes(E.trim().toLowerCase()):!0,q=v==="all"?!0:v==="configured"?f.hasPolicy:!f.hasPolicy;return F&&q}),Z=h||S.loading,M=Z&&P.length===0,V=Z&&P.length>0;return e.jsxs("div",{className:"w-full space-y-4",children:[e.jsx("section",{className:"min-w-0 flex overflow-hidden rounded-[24px] border border-[#E4E7EC] bg-white shadow-sm",style:{height:"clamp(31rem, calc(100dvh - 19rem), 70rem)"},children:e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:"shrink-0 border-b border-[#E9EAEB] px-4 py-4 sm:px-5 sm:py-5",children:e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex flex-1 items-center gap-3 overflow-x-auto pb-1 md:pb-0",children:[e.jsx("div",{className:"inline-flex w-fit shrink-0 items-center rounded-full border border-[#D5D7DA] bg-[#F8FAFC] p-1",children:Pt.map(f=>{const F=f.value==="all"?P.length:f.value==="configured"?y:z;return e.jsxs("button",{type:"button",onClick:()=>W(f.value),className:`whitespace-nowrap rounded-full px-4 py-2 text-xs font-semibold transition sm:px-5 sm:text-sm ${v===f.value?"border border-[#4F5CD5] bg-[#EEF4FF] text-[#2333CB]":"text-[#475467] hover:bg-white"}`,children:[f.label,e.jsx("span",{className:"ml-2 text-[11px] opacity-80",children:F})]},f.value)})}),V&&e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-2 rounded-full border border-[#D5D7DA] bg-[#F8FAFC] px-3 py-1 text-xs font-medium text-[#475467]",children:[e.jsx(H,{size:12,className:"animate-spin"}),"Refreshing"]})]}),e.jsxs("label",{className:"flex w-full shrink-0 items-center gap-3 rounded-2xl border border-[#D5D7DA] bg-white px-3.5 py-3 text-sm text-[#667085] shadow-sm md:max-w-[18rem] xl:max-w-[20rem]",children:[e.jsx(ds,{size:18,className:"shrink-0 text-[#667085]"}),e.jsx("input",{type:"text",placeholder:"Search",value:E,onChange:f=>T(f.target.value),className:"w-full border-0 bg-transparent p-0 text-sm text-[#344054] outline-none placeholder:text-[#98A2B3]"})]})]})}),B&&e.jsx("p",{className:"shrink-0 border-b border-[#FEE4E2] bg-[#FFFBFA] px-4 py-3 text-sm text-[#B42318] sm:px-5",children:B}),e.jsx("div",{className:"min-h-0 min-w-0 flex-1 overflow-hidden",children:e.jsx("div",{className:"h-full w-full overflow-auto leaderboard-scrollbar-custom",children:e.jsxs("table",{className:"min-w-[760px] w-full text-left sm:min-w-[860px] xl:min-w-[1080px]",children:[e.jsx("thead",{className:"bg-[#FCFCFD]",children:e.jsxs("tr",{className:"border-b border-[#E9EAEB]",children:[e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-3 py-3 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4 sm:text-sm",children:"Location"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-3 py-3 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-4 sm:py-4 sm:text-sm",children:"Modules Enabled"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-3 py-3 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-4 sm:py-4 sm:text-sm",children:"Templates"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-3 py-3 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-4 sm:py-4 sm:text-sm",children:"Status"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-3 py-3 text-right text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4 sm:text-sm",children:"Action"})]})}),e.jsx("tbody",{children:M?Array.from({length:6}).map((f,F)=>
1e.jsxs("tr",{className:"border-b border-[#E9EAEB] last:border-0",children:[e.jsx("td",{className:"px-3 py-4 sm:px-5 sm:py-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-full bg-[#EAECF0] sm:h-10 sm:w-10"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 w-28 rounded bg-[#EAECF0] sm:w-32"}),e.jsx("div",{className:"h-3 w-24 rounded bg-[#F2F4F7]"})]})]})}),e.jsx("td",{className:"px-3 py-4 sm:px-4 sm:py-5",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 w-16 rounded bg-[#EAECF0]"}),e.jsx("div",{className:"h-3 w-28 rounded bg-[#F2F4F7] sm:w-36"})]})}),e.jsx("td",{className:"px-3 py-4 sm:px-4 sm:py-5",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 w-12 rounded bg-[#EAECF0]"}),e.jsx("div",{className:"h-3 w-24 rounded bg-[#F2F4F7]"})]})}),e.jsx("td",{className:"px-3 py-4 sm:px-4 sm:py-5",children:e.jsx("div",{className:"h-7 w-16 rounded-full bg-[#F2F4F7]"})}),e.jsx("td",{className:"px-3 py-4 sm:px-5 sm:py-5",children:e.jsx("div",{className:"ml-auto h-10 w-28 rounded-xl bg-[#EAECF0] sm:h-11 sm:w-32"})})]},`location-skeleton-${F}`)):oe.map(f=>{var U,ee,X;const F=C(f.policy),q=((X=(ee=(U=f.policy)==null?void 0:U.templateAccess)==null?void 0:ee.allowedTemplates)==null?void 0:X.length)||0,ae=F.slice(0,2).join(", ");return e.jsxs("tr",{className:"border-b border-[#E9EAEB] transition hover:bg-[#F9FAFB] last:border-0",children:[e.jsx("td",{className:"px-3 py-4 sm:px-5 sm:py-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-[#F2F4F7] text-[#475467] sm:h-10 sm:w-10",children:e.jsx(Xe,{size:18})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-[0.95rem] font-semibold text-[#181D27] sm:text-[1.05rem]",children:f.location}),e.jsx("p",{className:"truncate text-xs text-[#667085] sm:text-sm",children:f.hasPolicy?"Policy configured":"No policy configured"})]})]})}),e.jsx("td",{className:"px-3 py-4 sm:px-4 sm:py-5",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-[0.95rem] font-semibold text-[#181D27] sm:text-[1.05rem]",children:[F.length,"/6"]}),e.jsx("p",{className:"max-w-[14rem] truncate text-xs text-[#667085] sm:max-w-[18rem] sm:text-sm",children:F.length>0?ae||`${F.length} modules enabled`:"No modules enabled"})]})}),e.jsx("td",{className:"px-3 py-4 sm:px-4 sm:py-5",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[0.95rem] font-semibold text-[#181D27] sm:text-[1.05rem]",children:q}),e.jsx("p",{className:"text-xs text-[#667085] sm:text-sm",children:q===1?"Allowed template":"Allowed templates"})]})}),e.jsx("td",{className:"px-3 py-4 sm:px-4 sm:py-5",children:e.jsxs("span",{className:`inline-flex items-center gap-2 rounded-full border px-2.5 py-1 text-xs font-medium sm:px-3 sm:text-sm ${f.hasPolicy?"border-[#A6F4C5] bg-[#ECFDF3] text-[#027A48]":"border-[#D0D5DD] bg-[#F2F4F7] text-[#667085]"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${f.hasPolicy?"bg-[#12B76A]":"bg-[#98A2B3]"}`}),f.hasPolicy?"Active":"None"]})}),e.jsx("td",{className:"px-3 py-4 sm:px-5 sm:py-5",children:e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:()=>D(f.location),className:`inline-flex h-10 min-w-[7.75rem] items-center justify-center gap-2 rounded-xl px-3 text-xs font-semibold transition sm:h-11 sm:min-w-[8.75rem] sm:px-4 sm:text-sm ${f.hasPolicy?"border border-[#D0D5DD] bg-white text-[#344054] hover:bg-[#F9FAFB]":"bg-[#2333CB] text-white hover:opacity-95"}`,children:f.hasPolicy?e.jsxs(e.Fragment,{children:[e.jsx(vs,{size:15})," Edit Policy"]}):e.jsxs(e.Fragment,{children:[e.jsx(ws,{size:15})," Set Policy"]})})})})]},f.location)})})]})})}),!M&&oe.length===0&&e.jsxs("div",{className:"shrink-0 border-t border-[#E9EAEB] px-4 py-10 text-center sm:px-5",children:[e.jsx("p",{className:"text-base font-semibold text-[#181D27]",children:"No matching locations"}),e.jsx("p",{className:"mt-2 text-sm text-[#667085]",children:E.trim()?`No locations foun
1d for "${E}".`:"No locations found for the selected filter."})]})]})}),e.jsx(Cs,{visible:!!p,onClose:()=>D(null),targetType:"location",targetValue:p,targetLabel:p,onSaved:L,onDeleted:L})]})},ys=20,$t=[{label:"Active",value:"Active"},{label:"Inactive",value:"Inactive"},{label:"All",value:""}],Ol=new Set($t.map(t=>t.value)),gt=t=>Ol.has(t)?t:"",ql=["border-[#C7D7FE] bg-[#EEF4FF] text-[#2333CB]","border-[#D6BBFB] bg-[#F9F5FF] text-[#6941C6]","border-[#ABEFC6] bg-[#ECFDF3] text-[#067647]","border-[#FEC84B] bg-[#FFFAEB] text-[#B54708]","border-[#FECACA] bg-[#FEF3F2] text-[#B42318]"];function yt(t){return Array.isArray(t.roles)&&t.roles.length?t.roles:t.empType?[t.empType]:t.role?[t.role]:[]}function Ul(t){return Array.isArray(t)?t.join(", "):t||"-"}function Wl(t){return(t||"").split(" ").filter(Boolean).slice(0,2).map(x=>{var d;return(d=x[0])==null?void 0:d.toUpperCase()}).join("")}const Hl=()=>{const t=Qe(),[x,d]=xs(),c=ge(i=>{var g,I;return(I=(g=i.accessControl)==null?void 0:g.roles)==null?void 0:I.data}),{items:h,total:B,loading:S,error:E}=ge(i=>{var g;return((g=i.accessControl)==null?void 0:g.employees)||{}}),v=jl(x,"ac_employees_page"),p=gt(Ke(x,"ac_employees_status")),D=Ke(x,"ac_employees_role"),_=Ke(x,"ac_employees_q"),[T,W]=n.useState(_),L=n.useRef(null),[C,J]=n.useState(null),[b,P]=n.useState({}),[y,z]=n.useState([]),[oe,Z]=n.useState(!1),[M,V]=n.useState(!1),[se,Q]=n.useState({all:0,active:0,inactive:0}),f=(c==null?void 0:c.roles)||[],F=n.useCallback(i=>{Hs(d,g=>{Bs(g,At),i(g)})},[d]),q=i=>{F(g=>{Te(g,"ac_employees_page",Math.max(1,i),"1")})},ae=i=>{F(g=>{Te(g,"ac_employees_status",gt(i)),g.delete("ac_employees_page")}),z([])},U=i=>{F(g=>{Te(g,"ac_employees_role",i),g.delete("ac_employees_page")}),z([])},ee=i=>{W(i),L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{F(g=>{Te(g,"ac_employees_q",i),g.delete("ac_employees_page")})},400)};n.useEffect(()=>{W(_)},[_]),n.useEffect(()=>()=>{L.current&&clearTimeout(L.current)},[]),n.useEffect(()=>{h!=null&&h.length&&P(i=>{const g={...i};return h.forEach(I=>{I.hasPolicy!==void 0&&(g[I.id]=I.hasPolicy)}),g})},[h]),n.useEffect(()=>{c||t(il())},[t,c]);const X=n.useCallback(()=>{const i={page:v,pageSize:ys};p&&(i.status=p),D&&(i.role=D),_&&(i.search=_),t(cl(i))},[t,v,p,D,_]);n.useEffect(()=>{X()},[X]),n.useEffect(()=>{let i=!1;return(async()=>{try{const I={};D&&(I.role=D),_&&(I.search=_);const K=await t(ol(I)).unwrap();if(i)return;Q({all:(K==null?void 0:K.all)||0,active:(K==null?void 0:K.active)||0,inactive:(K==null?void 0:K.inactive)||0})}catch{if(i)return;Q({all:B||h.length||0,active:0,inactive:0})}})(),()=>{i=!0}},[_,t,h.length,D,B]);const r=h||[],j=r.filter(i=>i.status==="Active"&&!i.isSynced),Y=i=>{z(g=>g.includes(i)?g.filter(I=>I!==i):[...g,i])},ne=()=>{z(j.map(i=>i.id))},re=async()=>{if(y.length){Z(!0);try{const i=y.map(ce=>{var Ce;return(Ce=(r||[]).find(he=>he.id===ce))==null?void 0:Ce.email}).filter(Boolean),g=await t(cs(i.length>0?{emails:i}:{ids:y})).unwrap(),I=Array.isArray(g)?g.filter(ce=>ce.success).length:(g==null?void 0:g.successful)||y.length,K=Array.isArray(g)?g.filter(ce=>!ce.success).length:(g==null?void 0:g.failed)||0;O.success(`Bulk sync: ${I} successful, ${K} failed`),z([]),X()}catch(i){O.error((i==null?void 0:i.message)||"Bulk sync failed")}finally{Z(!1)}}},le=Math.ceil((B||0)/ys),ie=S&&r.length===0,ye=S&&(h||[]).length>0,G="clamp(33rem, calc(100dvh - 12rem), 72rem)",je=y.length>0?`${y.length} employee${y.length!==1?"s":""} selected`:`${j.length} active employee${j.length!==1?"s":""} not synced`,Ee=B>0?(v-1)*ys+1:0,me=B>0?Math.min(v*ys,B):0;return e.jsxs("div",{className:"w-full space-y-4",children:[e.jsx("section",{className:"min-w-0 flex overflow-hidden rounded-[24px] border border-[#E4E7EC] bg-white shadow-sm",style:{height:G},children:e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:"shrink-0 border-b border-[#E9EAEB] px-4 py-4 sm:px-5 sm:py-5",children:e.jsxs("div",{className:"flex flex-col gap-4 2xl:flex-row 2xl:items-center 2xl:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 max-w-full items-center gap-3 overflow-x-auto pb-1 no-scrollbar",children:[e.jsx("div",{className:"inline-flex items-center rounded-full border border-[#D5D7DA] bg-white p-1",children:$t.map(i=>{const g=i.value==="Active"?se.active:i.value==="Inactive"?se.inactive:se.all;return e.jsxs("button",{type:"button",onClick:()=>
1ae(i.value),className:`whitespace-nowrap rounded-full px-3.5 py-2 text-xs font-semibold transition sm:px-4 sm:text-sm ${p===i.value?"border border-[#4F5CD5] bg-[#EEF4FF] text-[#2333CB]":"text-[#475467] hover:bg-[#F8FAFC]"}`,children:[i.label,e.jsxs("span",{className:"ml-2 opacity-80",children:["(",g,")"]})]},i.label)})}),ye&&e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-2 rounded-full border border-[#D5D7DA] bg-[#F8FAFC] px-3 py-1 text-xs font-medium text-[#475467]",children:[e.jsx(H,{size:12,className:"animate-spin"}),"Refreshing"]})]}),e.jsxs("div",{className:"flex min-w-0 w-full flex-col gap-3 xl:flex-row 2xl:w-auto",children:[e.jsxs("label",{className:"flex min-w-0 w-full items-center gap-3 rounded-xl border border-[#D5D7DA] bg-white px-3.5 py-2.5 text-sm text-[#667085] shadow-sm sm:px-4 sm:py-3 xl:flex-1 2xl:min-w-[24rem]",children:[e.jsx(ds,{size:18,className:"shrink-0 text-[#667085]"}),e.jsx("input",{type:"text",placeholder:"Search",value:T,onChange:i=>ee(i.target.value),className:"w-full border-0 bg-transparent p-0 text-sm text-[#344054] outline-none placeholder:text-[#98A2B3]"})]}),e.jsxs("label",{className:"inline-flex w-full items-center gap-2 rounded-xl border border-[#D5D7DA] bg-white px-3.5 py-2.5 text-sm font-medium text-[#475467] shadow-sm sm:px-4 sm:py-3 xl:w-auto",children:[e.jsx(fl,{size:18,className:"shrink-0 text-[#667085]"}),e.jsxs("select",{value:D,onChange:i=>U(i.target.value),className:"min-w-0 flex-1 border-0 bg-transparent p-0 pr-6 text-sm font-medium text-[#475467] outline-none md:min-w-[10rem]",children:[e.jsx("option",{value:"",children:"All Roles"}),f.map(i=>e.jsx("option",{value:i,children:i},i))]})]})]})]})}),E&&e.jsx("p",{className:"shrink-0 border-b border-[#FEE4E2] bg-[#FFFBFA] px-4 py-3 text-sm text-[#B42318] sm:px-5",children:E}),e.jsxs("div",{className:"relative min-h-0 min-w-0 flex-1 overflow-hidden",children:[ye&&e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 z-30 h-1 bg-[#EEF4FF]",children:e.jsx("div",{className:"h-full w-1/3 animate-pulse rounded-full bg-[#2333CB]"})}),e.jsx("div",{className:"h-full w-full overflow-auto leaderboard-scrollbar-custom",children:e.jsxs("table",{className:"min-w-[1120px] w-full text-left xl:min-w-[1280px]",children:[e.jsx("thead",{className:"bg-[#FCFCFD]",children:e.jsxs("tr",{className:"border-b border-[#E9EAEB]",children:[e.jsx("th",{className:"sticky top-0 z-20 w-14 bg-[#FCFCFD] px-4 py-3.5 shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4",children:e.jsx("input",{type:"checkbox",checked:y.length===j.length&&j.length>0,onChange:i=>i.target.checked?ne():z([]),disabled:j.length===0,className:"h-5 w-5 rounded-md border-[#D0D5DD] text-[#2333CB] focus:ring-[#C7D7FE] disabled:opacity-40"})}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4 sm:text-sm",children:"Name/Email"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Role"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Status"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Location"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Policy"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:py-4 sm:text-sm",children:"Synced"}),e.jsx("th",{className:"sticky top-0 z-10 bg-[#FCFCFD] px-4 py-3.5 text-right text-xs font-medium text-[#667085] shadow-[inset_0_-1px_0_0_#E9EAEB] sm:px-5 sm:py-4 sm:text-sm",children:"Action"})]})}),e.jsx("tbody",{children:ie?Array.from({length:8}).map((i,g)=>
1e.jsxs("tr",{className:"border-b border-[#E9EAEB] last:border-0",children:[e.jsx("td",{className:"px-5 py-5",children:e.jsx("div",{className:"h-5 w-5 rounded-md bg-[#EAECF0]"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-[#EAECF0]"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 w-32 rounded bg-[#EAECF0]"}),e.jsx("div",{className:"h-3 w-40 rounded bg-[#F2F4F7]"})]})]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-20 rounded-xl bg-[#F4F3FF]"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-24 rounded-full bg-[#ECFDF3]"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-4 w-28 rounded bg-[#EAECF0]"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-12 rounded-xl bg-[#F2F4F7]"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("div",{className:"h-7 w-24 rounded-full bg-[#EFF8FF]"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("div",{className:"ml-auto h-11 w-32 rounded-xl bg-[#EAECF0]"})})]},`employee-skeleton-${g}`)):r.map(i=>{const g=yt(i),I=g[0]||i.empType||"-",K=b[i.id],ce=i.status==="Active"&&!i.isSynced;return e.jsxs("tr",{className:"border-b border-[#E9EAEB] transition hover:bg-[#F9FAFB] last:border-0",children:[e.jsx("td",{className:"px-5 py-5",children:e.jsx("input",{type:"checkbox",checked:y.includes(i.id),onChange:()=>Y(i.id),disabled:!ce,className:"h-5 w-5 rounded-md border-[#D0D5DD] text-[#2333CB] focus:ring-[#C7D7FE] disabled:opacity-40"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-[#EEF4FF] text-sm font-semibold text-[#2333CB]",children:Wl(i.name)||"E"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-[1.05rem] font-semibold text-[#181D27]",children:i.name||"-"}),e.jsx("p",{className:"truncate text-sm text-[#667085]",children:i.email||"-"})]})]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:`inline-flex items-center rounded-xl border px-3 py-1 text-sm font-medium ${ql[0]}`,children:I}),g.length>1&&e.jsxs("span",{className:"text-xs font-medium text-[#667085]",children:["+",g.length-1," more"]})]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("span",{className:`inline-flex items-center gap-2 rounded-full border px-3 py-1 text-sm font-medium ${i.status==="Active"?"border-[#A6F4C5] bg-[#ECFDF3] text-[#027A48]":"border-[#D0D5DD] bg-[#F2F4F7] text-[#667085]"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${i.status==="Active"?"bg-[#12B76A]":"bg-[#98A2B3]"}`}),i.status||"-"]})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("p",{className:"text-[1.05rem] font-medium text-[#344054]",children:Ul(i.location)})}),e.jsx("td",{className:"px-4 py-5",children:e.jsx("span",{className:`inline-flex items-center rounded-xl border px-3 py-1 text-sm font-medium ${K?"border-[#D9D6FE] bg-[#F4F3FF] text-[#6941C6]":"border-[#E4E7EC] bg-[#F8FAFC] text-[#475467]"}`,children:K?"Yes":"No"})}),e.jsx("td",{className:"px-4 py-5",children:e.jsxs("span",{className:`inline-flex items-center gap-2 rounded-full border px-3 py-1 text-sm font-medium ${i.isSynced?"border-[#B2DDFF] bg-[#EFF8FF] text-[#1570EF]":"border-[#FEC84B] bg-[#FFFAEB] text-[#B54708]"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${i.isSynced?"bg-[#2E90FA]":"bg-[#F79009]"}`}),i.isSynced?"Synced":"Not Synced"]})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:()=>J(i),className:`inline-flex h-11 min-w-[8.75rem] items-center justify-center gap-2 rounded-xl px-4 text-sm font-semibold transition ${K?"border border-[#D0D5DD] bg-white text-[#344054] hover:bg-[#F9FAFB]":"bg-[#2333CB] text-white hover:opacity-95"}`,children:K?e.jsxs(e.Fragment,{children:[e.jsx(vs,{size:16})," Edit Policy"]}):e.jsxs(e.Fragment,{children:[e.jsx(ws,{size:16})," Set Policy"]})})})})]},i.id)})})]})})]}),!ie&&r.length===0&&e.jsx("div",{className:"shrink-0 border-t border-[#
1E9EAEB] px-4 py-10 text-center",children:e.jsx("p",{className:"text-sm font-medium text-[#344054]",children:T.trim()?`No employees found for "${T}".`:"No employees found."})}),le>1&&e.jsxs("div",{className:"flex gap-3 border-t border-[#E9EAEB] px-4 py-4 items-center justify-between flex-nowrap",children:[e.jsxs("p",{className:"text-xs text-[#667085] sm:text-sm",children:[Ee,"-",me," of ",B]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>q(v-1),disabled:v===1,className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border border-[#D5D7DA] text-[#344054] transition hover:bg-[#F9FAFB] disabled:opacity-40",children:e.jsx(Rs,{size:16})}),e.jsxs("span",{className:"px-2 text-sm font-medium text-[#344054]",children:[v," / ",le]}),e.jsx("button",{type:"button",onClick:()=>q(Math.min(le,v+1)),disabled:v>=le,className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border border-[#D5D7DA] text-[#344054] transition hover:bg-[#F9FAFB] disabled:opacity-40",children:e.jsx(Ns,{size:16})})]})]}),e.jsxs("div",{className:"shrink-0 flex flex-col gap-3 border-t border-[#E9EAEB] px-4 py-4 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("label",{className:"inline-flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:y.length===j.length&&j.length>0,onChange:i=>i.target.checked?ne():z([]),disabled:j.length===0,className:"h-5 w-5 rounded-md border-[#D0D5DD] text-[#2333CB] focus:ring-[#C7D7FE] disabled:opacity-40"}),e.jsxs("span",{className:"rounded-xl border border-[#E4E7EC] bg-white px-3 py-2 text-xs font-medium text-[#344054] sm:text-sm",children:[y.length," Selected"]})]}),e.jsx("p",{className:"text-xs text-[#667085] sm:text-sm",children:j.length>0?je:"All active employees are synced"})]}),e.jsxs("button",{type:"button",onClick:()=>V(!0),disabled:y.length===0||oe,className:"inline-flex h-11 w-full items-center justify-center gap-2 rounded-xl bg-[#2333CB] px-5 text-sm font-semibold text-white shadow-sm transition hover:opacity-95 disabled:opacity-50 xl:h-12 xl:w-auto",children:[oe?e.jsx(H,{size:16,className:"animate-spin"}):e.jsx(we,{size:16}),"Sync Employees"]})]})]})}),M&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40",children:e.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-white p-6 shadow-xl",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-[#FFFAEB]",children:e.jsx(we,{size:20,className:"text-[#B54708]"})}),e.jsx("h3",{className:"text-lg font-semibold text-[#181D27]",children:"Sync Employees"})]}),e.jsxs("p",{className:"mb-2 text-sm text-[#535862]",children:["Sync"," ",e.jsxs("span",{className:"font-semibold text-[#181D27]",children:[y.length," employee",y.length!==1?"s":""]})," ","to the Studio Workspace engine?"]}),e.jsx("div",{className:"mb-4 flex max-h-24 flex-wrap gap-1.5 overflow-y-auto no-scrollbar",children:y.map(i=>{const g=(r||[]).find(I=>I.id===i);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-md border border-[#E9EAEB] bg-[#F9FAFB] px-2 py-0.5 text-xs text-[#344054]",children:[(g==null?void 0:g.name)||(g==null?void 0:g.email)||i,(g==null?void 0:g.status)&&e.jsx("span",{className:`rounded px-1.5 py-px text-[9px] font-semibold ${g.status==="Active"?"bg-[#ECFDF3] text-[#067647]":"bg-[#F2F4F7] text-[#667085]"}`,children:g.status})]},i)})}),e.jsx("p",{className:"mb-5 text-xs text-[#B54708]",children:"Already synced users will be skipped."}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>V(!1),className:"rounded-lg border border-[#D0D5DD] px-4 py-2 text-sm font-semibold text-[#344054] hover:bg-[#F9FAFB]",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:()=>{V(!1),re()},disabled:oe,className:"inline-flex items-center gap-1.5 rounded-lg bg-[#B54708] px-4 py-2 text-sm font-semibold text-white hover:bg-[#93370D] disabled:opacity-50",children:[oe?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(we,{size:14}),"Sync Now"]})]})]})}),e.jsx(Cs,{visible:!!C,onClose:()=>J(null),targetType:"userId",targetValue:C==null?void 0:C.id,targetLabel:C?`${C.name||"Employee"} - ${C.empType||yt(C).join(", ")||"-"}`:"",targetStatus:C==null?void 0:C.status,isSynced:!!(C!=null&&C.isSynced),onSaved:()=>{P(i=>({...i,[C==null?void 0:C.id]:!0})),X()},onDeleted:()=>{P(i=>({...i,[C==null?void 0:C.id]:!1})),X()}})]})},Yl=[{value:"fee",label:"Fee Compliance"},{value:"attendance",label:"Attendance Compliance"},{value:"status",label:"Student Status"}],Gl=[{value:"learningContent",label:"Learning Content"},{value:"exams",label:"Exams"},{value:"studio",label:"Workspace"},{value:"codePlayground",label:"Code Playground"},{value:"mockInterviews",label:"Mock Interviews"},{value:"placementSupport",label:"Placement Support"}],os=t=>{if(!t)return null;const x=String(t).replace(/\s*IST\s*$/i,"").trim(),d=new Date(x);return isNaN(d.getTime())?new Date(t):d},zs=t=>{const x=os(t);return!x||isNaN(x.getTime())?0:Math.ceil((x-new Date)/864e5)},jt=t=>{const x=os(t);if(!x||isNaN(x.getTime()))return"Unknown";const d=x-new Date;if(d<=0){const E=Math.abs(d),v=Math.floor(E/864e5),p=Math.floor(E%864e5/36e5),D=Math.floor(E%36e5/6e4);return v>0?`Expired ${v}d ${p}h ago`:p>0?`Expired ${p}h ${D}m ago`:`Expired ${D}m ago`}const c=Math.floor(d/864e5),h=Math.floor(d%864e5/36e5),B=Math.floor(d%36e5/6e4),S=Math.floor(d%6e4/1e3);return c>0?`${c}d ${h}h ${B}m ${S}s left`:h>0?`${h}h ${B}m ${S}s left`:`${B}m ${S}s left`},Kl=()=>{const t=Qe(),[x,d]=n.useState([]),[c,h]=n.useState(!0),[B,S]=n.useState(1),[E,v]=n.useState(1),[p,D]=n.useState(0),[_,T]=n.useState(""),[W,L]=n.useState([]),[C,J]=n.useState(!1),[b,P]=n.useState(null),[y,z]=n.useState(null),[oe,Z]=n.useState(!1),[M,V]=n.useState([]),[se,Q]=n.useState(!0),[f,F]=n.useState([]),[q,ae]=n.useState(""),[U,ee]=n.useState(""),[X,r]=n.useState(""),[j,Y]=n.useState(!1),[ne,re]=n.useState(!1),[le,ie]=n.useState(null),[ye,G]=n.useState({active:0,expiringSoon:0,expired:0}),je=n.useCallback(async(o=B)=>{h(!0);try{const A=await t(dl({page:o,pageSize:20})).unwrap(),k=(A==null?void 0:A.data)||A;d(Array.isArray(k==null?void 0:k.items)?k.items:Array.isArray(k)?k:[]),D((k==null?void 0:k.total)||0),v(Math.ceil(((k==null?void 0:k.total)||0)/((k==null?void 0:k.pageSize)||20))||1),k!=null&&k.summary&&G(k.summary)}catch{d([])}finally{h(!1)}},[t,B]);n.useEffect(()=>{je(B)},[je,B]);const Ee=n.useCallback(async()=>
1{if(_.trim()){J(!0);try{const o=await t(xl({search:_.trim(),pageSize:10})).unwrap();L((o==null?void 0:o.items)||[])}catch{L([])}finally{J(!1)}}},[t,_]),me=async o=>{P(o),L([]),T(""),Z(!0);try{const A=await t(is(o.id)).unwrap(),k=(A==null?void 0:A.complianceBypass)||null;if(z(k),k){V(k.checks||[]),Q(k.modules===null||k.modules===void 0),F(k.modules||[]);const fe=k.deadline||"",de=os(fe);if(de&&!isNaN(de.getTime())){ae(de.toISOString().split("T")[0]);const Ae=de.getHours(),qe=de.getMinutes();ee(Ae===23&&qe===59?"":`${String(Ae).padStart(2,"0")}:${String(qe).padStart(2,"0")}`)}else ae(fe.split(" ")[0]||""),ee("");r(k.reason||"")}else i()}catch{z(null),i()}finally{Z(!1)}},i=()=>{V([]),Q(!0),F([]),ae(""),ee(""),r("")},g=o=>{V(A=>A.includes(o)?A.filter(k=>k!==o):[...A,o])},I=o=>{F(A=>A.includes(o)?A.filter(k=>k!==o):[...A,o])},K=async()=>{if(!b||!M.length||!q||!X.trim()){O.error("Please fill all required fields");return}Y(!0);try{const o=U?`${q}T${U}:00`:q;await t(wt({userId:b.id,checks:M,modules:se?null:f,deadline:o,reason:X.trim()})).unwrap(),O.success("Compliance bypass set successfully");const A=await t(is(b.id)).unwrap();z((A==null?void 0:A.complianceBypass)||null),je()}catch(o){O.error((o==null?void 0:o.message)||"Failed to set bypass")}finally{Y(!1)}},ce=async()=>{if(b){re(!0);try{await t(Ts(b.id)).unwrap(),O.success("Bypass revoked"),z(null),i(),je()}catch(o){O.error((o==null?void 0:o.message)||"Failed to revoke bypass")}finally{re(!1)}}},Ce=y!=null&&y.deadline?zs(y.deadline)<=0:!1,he=y!=null&&y.deadline?zs(y.deadline):0,Pe=new Date(Date.now()+864e5).toISOString().split("T")[0],{active:be,expiringSoon:De,expired:pe}=ye;return e.jsxs("div",{className:"w-full space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsxs("div",{className:"flex items-center h-10 bg-white border border-[#D5D7DA] rounded-lg px-3 gap-2 shadow-[0_5px_10px_0_rgba(2,2,76,0.03)]",children:[e.jsx(ds,{size:17,className:"text-[#98A2B3]"}),e.jsx("input",{type:"text",placeholder:"Search student by name, email, or ID...",value:_,onChange:o=>T(o.target.value),onKeyDown:o=>o.key==="Enter"&&Ee(),className:"w-full outline-none text-sm text-gray-700 placeholder-gray-400"}),C&&e.jsx(H,{size:14,className:"animate-spin text-[#2333CB]"})]}),W.length>0&&e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white border border-[#E9EAEB] rounded-xl shadow-lg z-20 max-h-60 overflow-y-auto",children:W.map(o=>e.jsxs("button",{type:"button",onClick:()=>me(o),className:"w-full text-left px-4 py-3 hover:bg-[#F9FAFB] border-b border-[#F2F4F7] last:border-0 transition",children:[e.jsx("p",{className:"text-sm font-medium text-[#181D27]",children:o.name||"-"}),e.jsxs("p",{className:"text-xs text-[#667085]",children:[o.email," · ",o.studentId||"-"," · ",o.status]})]},o.id))})]}),e.jsx("button",{type:"button",onClick:Ee,disabled:!_.trim()||C,className:"h-10 px-4 rounded-lg bg-[#2333CB] border border-[#4F5CD5] text-white text-sm font-semibold hover:opacity-95 disabled:opacity-50 transition",children:"Search"})]}),!c&&be+De+pe>0&&e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-[#E4E7EC] px-4 py-3 shadow-[0_5px_10px_0_rgba(2,2,76,0.03)]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-[#ECFDF3] flex items-center justify-center",children:e.jsx(Oe,{size:12,className:"text-[#067647]"})}),e.jsx("span",{className:"text-xs text-[#667085]",children:"Active"})]}),e.jsx("p",{className:"text-xl font-bold text-[#181D27]",children:be})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#E4E7EC] px-4 py-3 shadow-[0_5px_10px_0_rgba(2,2,76,0.03)]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-[#FFFAEB] flex items-center justify-center",children:e.jsx(js,{size:12,className:"text-[#B54708]"})}),e.jsx("span",{className:"text-xs text-[#667085]",children:"Expiring ⤠7d"})]}),e.jsx("p",{className:"text-xl font-bold text-[#B54708]",children:De})]}
1),e.jsxs("div",{className:"bg-white rounded-xl border border-[#E4E7EC] px-4 py-3 shadow-[0_5px_10px_0_rgba(2,2,76,0.03)]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-[#FEF3F2] flex items-center justify-center",children:e.jsx(Ve,{size:12,className:"text-[#B42318]"})}),e.jsx("span",{className:"text-xs text-[#667085]",children:"Expired"})]}),e.jsx("p",{className:"text-xl font-bold text-[#B42318]",children:pe})]})]}),b&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-black/20 backdrop-blur-[2px]",onClick:()=>{P(null),z(null),i()}}),e.jsxs("div",{className:"fixed top-0 right-0 z-50 h-full w-full max-w-[480px] bg-[#F9FAFB] shadow-2xl flex flex-col",children:[e.jsxs("div",{className:"bg-white px-6 py-4 border-b border-[#E9EAEB]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-[10px] font-semibold text-[#667085] uppercase tracking-wider",children:y?"Edit Bypass":"New Bypass"}),e.jsx("button",{type:"button",onClick:()=>{P(null),z(null),i()},className:"h-7 w-7 rounded-md border border-[#E9EAEB] flex items-center justify-center hover:bg-[#F9FAFB] transition",children:e.jsx(Bt,{size:13,className:"text-[#667085]"})})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#EEF4FF] text-[#2333CB] flex items-center justify-center font-semibold text-sm shrink-0",children:(b.name||"?").split(" ").filter(Boolean).slice(0,2).map(o=>{var A;return(A=o[0])==null?void 0:A.toUpperCase()}).join("")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-[#181D27] truncate",children:b.name}),e.jsx("span",{className:`inline-flex items-center h-5 px-1.5 rounded text-[10px] font-medium shrink-0 ${b.status==="Active"?"bg-[#ECFDF3] text-[#067647]":"bg-[#F2F4F7] text-[#667085]"}`,children:b.status})]}),e.jsxs("p",{className:"text-xs text-[#667085] truncate",children:[b.email," · ",b.studentId||"-"]})]})]}),y&&!oe&&e.jsxs("div",{className:`mt-3 flex items-center justify-between px-3 py-2 rounded-lg ${Ce?"bg-[#FEF3F2]":he<=7?"bg-[#FFFAEB]":"bg-[#ECFDF3]"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[Ce?e.jsx(Ve,{size:13,className:"text-[#B42318]"}):e.jsx(Oe,{size:13,className:he<=7?"text-[#B54708]":"text-[#067647]"}),e.jsx("span",{className:`text-xs font-semibold ${Ce?"text-[#B42318]":he<=7?"text-[#B54708]":"text-[#067647]"}`,children:jt(y.deadline)})]}),e.jsx("span",{className:"text-[10px] text-[#667085]",children:(()=>{const o=os(y.deadline);return o&&!isNaN(o.getTime())?o.toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"}):y.deadline})()})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-4 no-scrollbar",children:oe?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(H,{size:22,className:"animate-spin text-[#2333CB]"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white rounded-xl border border-[#E4E7EC] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-[#FEF3F2] flex items-center justify-center",children:e.jsx(Os,{size:12,className:"text-[#B42318]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-[#181D27]",children:"Compliance Checks"}),e.jsx("p",{className:"text-[10px] text-[#98A2B3]",children:"Select which checks to bypass"})]})]}),e.jsx("div",{className:"space-y-1.5",children:Yl.map(o=>{const A=M.includes(o.value),fe={fee:"#B42318",attendance:"#B54708",status:"#667085"}[o.value]||"#667085";return e.jsxs("button",{type:"button",onClick:()=>
1g(o.value),className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-lg border text-left transition ${A?"border-l-[3px] bg-[#FAFBFC]":"border-[#E9EAEB] hover:bg-[#FAFBFC]"}`,style:A?{borderLeftColor:fe,borderTopColor:"#E4E7EC",borderRightColor:"#E4E7EC",borderBottomColor:"#E4E7EC"}:{},children:[e.jsx("div",{className:`w-4 h-4 rounded border-[1.5px] flex items-center justify-center transition ${A?"border-[#2333CB] bg-[#2333CB]":"border-[#D0D5DD]"}`,children:A&&e.jsx("svg",{width:"10",height:"8",viewBox:"0 0 10 8",fill:"none",children:e.jsx("path",{d:"M1 4L3.5 6.5L9 1",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("span",{className:`text-sm ${A?"font-medium text-[#181D27]":"text-[#344054]"}`,children:o.label})]},o.value)})})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#E4E7EC] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-[#EEF4FF] flex items-center justify-center",children:e.jsx(Ze,{size:12,className:"text-[#2333CB]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-[#181D27]",children:"Module Scope"}),e.jsx("p",{className:"text-[10px] text-[#98A2B3]",children:"Which modules should the bypass apply to"})]})]}),e.jsx("div",{className:"flex items-center gap-2 mb-3",children:[{val:!0,label:"All Modules"},{val:!1,label:"Specific"}].map(o=>e.jsx("button",{type:"button",onClick:()=>Q(o.val),className:`h-8 px-3 rounded-lg text-xs font-semibold transition ${se===o.val?"bg-[#2333CB] text-white border border-[#4F5CD5]":"text-[#667085] bg-[#F9FAFB] border border-[#E9EAEB] hover:bg-white"}`,children:o.label},String(o.val)))}),!se&&e.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:Gl.map(o=>e.jsx("button",{type:"button",onClick:()=>I(o.value),className:`h-9 px-3 rounded-lg border text-xs font-medium text-left transition ${f.includes(o.value)?"border-[#C7D7FE] bg-[#EEF4FF] text-[#2333CB]":"border-[#E9EAEB] bg-[#FAFBFC] text-[#344054] hover:bg-white"}`,children:o.label},o.value))})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#E4E7EC] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-[#FFFAEB] flex items-center justify-center",children:e.jsx(Fs,{size:12,className:"text-[#B54708]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-[#181D27]",children:"Deadline"}),e.jsx("p",{className:"text-[10px] text-[#98A2B3]",children:"Time defaults to 11:59 PM IST if not set"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Fs,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[#667085] pointer-events-none z-[1]"}),e.jsx("input",{type:"date",min:Pe,value:q,onChange:o=>ae(o.target.value),onClick:o=>{var A,k;return(k=(A=o.target).showPicker)==null?void 0:k.call(A)},className:"w-full h-10 pl-9 pr-3 rounded-lg border border-[#D5D7DA] text-sm text-[#344054] outline-none focus:border-[#2333CB] cursor-pointer [&::-webkit-calendar-picker-indicator]:cursor-pointer [&::-webkit-calendar-picker-indicator]:opacity-100"})]}),e.jsxs("div",{className:"relative w-[120px]",children:[e.jsx(js,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[#667085] pointer-events-none z-[1]"}),e.jsx("input",{type:"time",value:U,onChange:o=>ee(o.target.value),onClick:o=>{var A,k;return(k=(A=o.target).showPicker)==null?void 0:k.call(A)},className:"w-full h-10 pl-9 pr-3 rounded-lg border border-[#D5D7DA] text-sm text-[#344054] outline-none focus:border-[#2333CB] cursor-pointer [&::-webkit-calendar-picker-indicator]:cursor-pointer [&::-webkit-calendar-picker-indicator]:opacity-100"})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-[#E4E7EC] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-[#F2F4F7] flex items-center justify-center",children:e.jsx(Ve,{size:12,className:"text-[#667085]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-[#181D27]",children:"Reason"}),e.jsx("p",{className:"text-[10px] text-[#98A2B3]",children:"Recorded in audit trail"})]})]}),e.jsx("textarea",{value:X,onChange:o=>r(o.target.value),placeholder:"Why is this bypass needed?",rows:3,className:"w-full px-3 py-2.5 rounded-lg border border-[#D5D7DA] text-sm text-[#344054] outline-none focus:border-[#2333CB] resize-none"})]}),(y==null?void 0:y.createdBy)&&e.jsxs("div",{className:"flex items-center gap-2 px-1 text-[10px] text-[#98A2B3]",children:[e.jsx(js,{size:10}),e.jsxs("span",{children:["Set by"," ",e.jsx("span",{className:"text-[#667085] font-medium",children:y.createdBy}),y.createdAt?` on ${y.createdAt}`:""]})]})]})}
1),!oe&&e.jsxs("div",{className:"bg-white border-t border-[#E9EAEB] px-6 py-4 flex items-center justify-between",children:[y?e.jsxs("button",{type:"button",onClick:ce,disabled:ne,className:"h-9 px-4 rounded-lg border border-[#FECACA] text-[#B42318] text-xs font-semibold hover:bg-[#FEF3F2] transition inline-flex items-center gap-1.5 disabled:opacity-50",children:[ne?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Ge,{size:12})," ","Revoke"]}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{P(null),z(null),i()},className:"h-9 px-4 rounded-lg border border-[#D5D7DA] text-[#344054] text-xs font-semibold hover:bg-[#F9FAFB] transition",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:K,disabled:j||!M.length||!q||!X.trim(),className:"h-9 px-5 rounded-lg bg-[#2333CB] border border-[#4F5CD5] text-white text-xs font-semibold inline-flex items-center gap-1.5 hover:opacity-95 disabled:opacity-50 transition",children:[j?e.jsx(H,{size:14,className:"animate-spin"}):e.jsx(ns,{size:14})," ",y?"Update":"Set Bypass"]})]})]})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-[#E4E7EC] shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-[#E9EAEB]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Oe,{size:16,className:"text-[#B54708]"}),e.jsx("h3",{className:"text-[#181D27] font-semibold text-base",children:"Active Bypasses"}),!c&&e.jsx("span",{className:"text-xs text-[#667085] bg-[#F2F4F7] px-2 py-0.5 rounded-full font-medium",children:p})]}),e.jsxs("button",{type:"button",onClick:()=>je(B),disabled:c,className:"h-8 px-3 rounded-lg border border-[#D5D7DA] text-xs font-medium text-[#344054] hover:bg-[#F9FAFB] disabled:opacity-50 inline-flex items-center gap-1.5 transition",children:[c?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(we,{size:12})," ","Refresh"]})]}),c?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(H,{size:22,className:"animate-spin text-[#2333CB]"})}):x.length===0?e.jsxs("div",{className:"py-16 text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-[#FFFAEB] flex items-center justify-center mx-auto mb-3",children:e.jsx(Os,{size:20,className:"text-[#B54708]"})}),e.jsx("p",{className:"text-[#344054] text-sm font-medium",children:"No active bypasses"}),e.jsx("p",{className:"text-[#667085] text-xs mt-1",children:"Search for a student above to set a compliance bypass"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[#E9EAEB] bg-[#F9FAFB]",children:[e.jsx("th",{className:"text-[10px] font-semibold text-[#667085] uppercase tracking-wider py-2.5 px-4",children:"Student"}),e.jsx("th",{className:"text-[10px] font-semibold text-[#667085] uppercase tracking-wider py-2.5 px-3",children:"Checks"}),e.jsx("th",{className:"text-[10px] font-semibold text-[#667085] uppercase tracking-wider py-2.5 px-3",children:"Modules"}),e.jsx("th",{className:"text-[10px] font-semibold text-[#667085] uppercase tracking-wider py-2.5 px-3",children:"Deadline"}),e.jsx("th",{className:"text-[10px] font-semibold text-[#667085] uppercase tracking-wider py-2.5 px-3",children:"Reason"}),e.jsx("th",{className:"text-[10px] font-semibold text-[#667085] uppercase tracking-wider py-2.5 px-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{children:x.map(o=>{const A=o.complianceBypass||o,k=zs(A.deadline),fe=k<=0,de={fee:{bg:"#FEF3F2",text:"#B42318",border:"#FECACA"},attendance:{bg:"#FFFAEB",text:"#B54708",border:"#FEC84B"}},Ae=os(A.deadline),qe=Ae&&!isNaN(Ae.getTime())?Ae.toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"}):A.deadline;let Se="#067647";fe?Se="#B42318":k<=7&&(Se="#B54708");let ue="#ECFDF3";fe?ue="#FEF3F2":k<=7&&(ue="#FFFAEB");let Le=Math.max(5,Math.min(60,100-k));return fe?Le=100:k<=7&&(Le=Math.max(10,100-k/7*100)),e.jsxs("tr",{className:"border-b border-[#F2F4F7] last:border-0 hover:bg-[#FAFBFC] transition group",children:[e.jsx("td",{className:"py-3 px-4",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-[#EEF4FF] text-[#2333CB] flex items-center justify-center font-semibold text-xs shrink-0",children:(o.name||"?").split(" ").filter(
1Boolean).slice(0,2).map(Ne=>{var xe;return(xe=Ne[0])==null?void 0:xe.toUpperCase()}).join("")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-[#181D27]",children:o.name||o.id}),e.jsx("p",{className:"text-[10px] text-[#667085]",children:o.email}),(o.batchNo||o.location)&&e.jsx("p",{className:"text-[10px] text-[#98A2B3]",children:[o.batchNo,o.location].filter(Boolean).join(" · ")})]})]})}),e.jsx("td",{className:"py-3 px-3",children:e.jsx("div",{className:"flex flex-wrap gap-1",children:(A.checks||[]).map(Ne=>{const xe=de[Ne]||{bg:"#F2F4F7",text:"#344054",border:"#E9EAEB"};return e.jsx("span",{className:"inline-flex items-center h-5 px-1.5 rounded text-[10px] font-medium capitalize",style:{background:xe.bg,color:xe.text,border:`1px solid ${xe.border}`},children:Ne},Ne)})})}),e.jsx("td",{className:"py-3 px-3",children:A.modules?e.jsxs("div",{className:"flex flex-wrap gap-1",children:[A.modules.slice(0,2).map(Ne=>e.jsx("span",{className:"inline-flex items-center h-5 px-1.5 rounded text-[10px] font-medium border border-[#C7D7FE] bg-[#EEF4FF] text-[#2333CB]",children:Ne},Ne)),A.modules.length>2&&e.jsxs("span",{className:"text-[10px] text-[#667085]",children:["+",A.modules.length-2]})]}):e.jsx("span",{className:"inline-flex items-center h-5 px-1.5 rounded text-[10px] font-medium border border-[#ABEFC6] bg-[#ECFDF3] text-[#067647]",children:"All"})}),e.jsx("td",{className:"py-3 px-3",children:e.jsxs("div",{className:"w-[130px]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-[11px] text-[#344054] font-medium",children:qe}),e.jsx("span",{className:"text-[10px] font-semibold",style:{color:Se},children:jt(A.deadline)})]}),e.jsx("div",{className:"h-1.5 rounded-full w-full",style:{background:ue},children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${Le}%`,background:Se}})})]})}),e.jsx("td",{className:"py-3 px-3",children:e.jsx("p",{className:"text-xs text-[#667085] truncate max-w-[160px]",title:A.reason,children:A.reason||"-"})}),e.jsx("td",{className:"py-3 px-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>me({id:o.id,name:o.name||o.id,email:o.email||"",studentId:o.studentId||"",status:o.status||"-"}),className:"h-7 px-2.5 rounded-md border border-[#D5D7DA] text-[11px] font-medium text-[#344054] hover:bg-[#F9FAFB] transition",children:"Edit"}),e.jsx("button",{type:"button",onClick:()=>ie(o),className:"h-7 px-2.5 rounded-md border border-[#FECACA] text-[11px] font-medium text-[#B42318] hover:bg-[#FEF3F2] transition",children:"Revoke"})]})})]},o.id)})})]})}),E>1&&e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-t border-[#E9EAEB]",children:[e.jsxs("span",{className:"text-xs text-[#667085]",children:[p," bypass",p!==1?"es":""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>S(o=>Math.max(1,o-1)),disabled:B<=1,className:"h-7 px-2.5 rounded-md border border-[#D5D7DA] text-xs text-[#344054] disabled:opacity-40 hover:bg-[#F9FAFB]",children:"Prev"}),e.jsxs("span",{className:"text-xs text-[#667085]",children:[B,"/",E]}),e.jsx("button",{type:"button",onClick:()=>S(o=>Math.min(E,o+1)),disabled:B>=E,className:"h-7 px-2.5 rounded-md border border-[#D5D7DA] text-xs text-[#344054] disabled:opacity-40 hover:bg-[#F9FAFB]",children:"Next"})]})]})]})]}),le&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[60] bg-black/20 backdrop-blur-[2px]",onClick:()=>ie(null)}),e.jsxs("div",{className:"fixed z-[70] top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-sm bg-white rounded-2xl shadow-2xl border border-[#E4E7EC] p-6",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#FEF3F2] flex items-center justify-center mx-auto mb-3",children:e.jsx(Ge,{size:18,className:"text-[#B42318]"})}),e.jsx("h3",{className:"text-sm font-semibold text-[#181D27] text-center",children:"Revoke Bypass"}),e.jsxs("p",{className:"text-xs text-[#667085] text-center mt-1.5",children:["This will immediately remove the compliance bypass for"," ",e.jsx("span",{className:"font-medium text-[#344054]",children:le.name||le.id}),". The student will be subject to all compliance checks again."]}),e.jsxs("div",{className:"flex items-center gap-2 mt-5",children:[e.jsx("button",{type:"button",onClick:()=>ie(null),className:"flex-1 h-9 rounded-lg border border-[#D5D7DA] text-xs font-semibold text-[#344054] hover:bg-[#F9FAFB] transition",children:"Cancel"}),e.jsxs("button",{type:"button",disabled:ne,onClick:async()=>{re(!0);try{await t(Ts(le.id)).unwrap(),O.success("Bypass revoked"),ie(null),je()}catch(o){O.error((o==null?void 0:o.message)||"Failed to revoke")}finally{re(!1)}},className:"flex-1 h-9 rounded-lg bg-[#B42318] border border-[#B42318] text-white text-xs font-semibold inline-flex items-center justify-center gap-1.5 hover:opacity-95 disabled:opacity-50 transition",children:[ne?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Ge,{size:12})," ","Revoke"]})]})]})]})]})},es="/admin/access-control",Ql={batches:{title:"Batches Access Control",description:"Set batch-level policies"},locations:{title:"Location Access Control",description:"Set location-level policies"},employees:{title:"Employee Access Control",description:"Set employee-level policies"},bypass:{title:"Compliance Bypass",description:"Bypass fee/attendance/status"}},Jl=()=>{const t=Us(),[x]=xs(),d=(c,h={})=>{const B=new URLSearchParams(x);if(Bs(B),c==="batches"&&Te(B,"ac_batches_location",h.batchLocation),!c||c==="overview"){t(qs(es,B));return}
1t(qs(`${es}/${c}`,B))};return e.jsxs("div",{className:"w-full space-y-6 px-4",children:[e.jsx("div",{className:"space-y-1",children:e.jsx("h1",{className:"text-[1.3rem] sm:text-[1.6rem] font-semibold tracking-tight text-[#414651]",children:"Access Control"})}),e.jsx(kt,{onNavigate:d})]})},rs=({section:t,children:x})=>{const d=Us(),c=Nt(),[h]=xs(),B=Ql[t];return t==="batches"&&Ft(`${es}/batches/view/:batchId`,c.pathname)?e.jsx("div",{className:"w-full space-y-4 px-4",children:x}):e.jsxs("div",{className:"w-full space-y-4 px-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-start gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{const E=new URLSearchParams(h);Bs(E),d(qs(es,E))},"aria-label":"Back to Access Control overview",className:"inline-flex items-center h-12 w-11",children:e.jsx(Dt,{size:24,className:"text-[#181D27]"})}),e.jsx("div",{className:"min-w-0 space-y-1",children:e.jsx("h1",{className:"text-[1.3rem] sm:text-[1.8rem] font-semibold tracking-tight text-[#181D27]",children:B==null?void 0:B.title})})]}),x]})},ia=()=>{const t=Qe(),x=ge(d=>{var c,h;return(h=(c=d.accessControl)==null?void 0:c.metadata)==null?void 0:h.data});return n.useEffect(()=>{x||(t(vt()),t(Ws()))},[t,x]),e.jsxs(Rt,{children:[e.jsx(We,{index:!0,element:e.jsx(Jl,{})}),e.jsx(We,{path:"overview",element:e.jsx(nt,{to:es,replace:!0})}),e.jsx(We,{path:"batches/*",element:e.jsx(rs,{section:"batches",children:e.jsx(Tl,{})})}),e.jsx(We,{path:"locations",element:e.jsx(rs,{section:"locations",children:e.jsx(Rl,{})})}),e.jsx(We,{path:"employees",element:e.jsx(rs,{section:"employees",children:e.jsx(Hl,{})})}),e.jsx(We,{path:"bypass",element:e.jsx(rs,{section:"bypass",children:e.jsx(Kl,{})})}),e.jsx(We,{path:"*",element:e.jsx(nt,{to:es,replace:!0})})]})};rs.propTypes={section:Ls.string.isRequired,children:Ls.node.isRequired};export{ia 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.