1import{j as e}from"./vendor-markdown-Daxr8BJC.js";import{r as n}from"./vendor-charts-qvx8-m0G.js";import{G as he,s as Q,b as T,aC as ne,a as D,a9 as ye,X as re,i as le,C as Re,t as Te,u as Pe,d as Ee,m as Ie,n as Ge,o as Z,l as ie,bA as ce,p as Be,P as Le}from"./index-DVHzHwfb.js";import{u as De,U as de,B as qe,a as Ve}from"./BulkRejectDialog-d_QiwAP_.js";import{u as ze}from"./useSchools-ClBuqHi6.js";import{T as Oe,a as Me,b as oe,c as y,d as Fe,e as R}from"./table-BWVTKvol.js";import{S as J,a as W,b as Y,c as ee,d as L}from"./select-DNjl5UiE.js";import{C as ue}from"./checkbox-BOaVtFzw.js";import{P as He}from"./pagination-CqZ04MDb.js";import{t as ae}from"./use-toast-i2zyaXe4.js";import{L as V}from"./loader-circle-5In9C9RK.js";import{C as Ue}from"./cloud-B_xlVAJE.js";import{C as Xe}from"./circle-check-DpVZg0Xw.js";import{f as $e}from"./format-BtJhFMXd.js";import"./vendor-pdf-SjvVsPhg.js";import"./dialog-CoKHzKdp.js";import"./alert-dialog-CoLhr2wu.js";import"./index-BdQq_4o_.js";import"./chevron-left-Y_vLsvat.js";import"./en-US-B1FN9Dyc.js";const se=new Set(["success","failed","skipped"]);function Ke({dagId:l,onSuccess:i,onFailure:p,pollIntervalMs:o=5e3,maxPollMs:C=30*60*1e3}){const{user:u}=he(),[c,f]=n.useState(!1),[v,S]=n.useState(null),[M,P]=n.useState(null),N=n.useRef(i),w=n.useRef(p);n.useEffect(()=>{N.current=i,w.current=p},[i,p]);const _=n.useRef(null),k=n.useRef(null),E=n.useRef(0),d=n.useCallback(()=>{k.current&&(clearInterval(k.current),k.current=null)},[]);n.useEffect(()=>()=>d(),[d]);const m=n.useCallback(async()=>{var z,I;const x=_.current;if(!x)return;if(Date.now()-E.current>C){d(),P("Timed out waiting for DAG run to finish.");return}const{data:a,error:h}=await Q.from("dag_runs").select("id,dag_id,run_id,state,triggered_at,started_at,finished_at,error_message").eq("run_id",x).maybeSingle();if(h){console.warn("dag_runs poll failed:",h);return}if(!a)return;const j=a;S(j),se.has(j.state)&&(d(),j.state==="success"?(z=N.current)==null||z.call(N,j):(I=w.current)==null||I.call(w,j))},[C,d]),F=n.useCallback(()=>{d(),_.current=null,S(null),P(null)},[d]);n.useEffect(()=>{if(!(u!=null&&u.id)||_.current)return;let x=!1;return(async()=>{const{data:a,error:h}=await Q.from("dag_runs").select("id,dag_id,run_id,state,triggered_at,started_at,finished_at,error_message").eq("dag_id",l).eq("triggered_by",u.id).in("state",["queued","running"]).order("triggered_at",{ascending:!1}).limit(1).maybeSingle();if(x||h||!a)return;const j=a;_.current=j.run_id,E.current=Date.now(),S(j),d(),k.current=setInterval(m,o)})(),()=>{x=!0}},[u==null?void 0:u.id,l,o,m,d]);const g=n.useCallback(async x=>{if(!(c||v&&!se.has(v.state))){f(!0),P(null),S(null);try{const{data:a,error:h}=await Q.functions.invoke("trigger-dag",{body:{dagId:l,...x?{conf:x}:{}}});if(h)throw new Error(h.message||"trigger-dag failed");if(!(a!=null&&a.runId))throw new Error("trigger-dag returned no runId");_.current=a.runId,E.current=Date.now(),S({id:"",dag_id:l,run_id:a.runId,state:a.state||"queued",triggered_at:new Date().toISOString(),started_at:null,finished_at:null,error_message:null}),await m(),d(),k.current=setInterval(m,o)}catch(a){const h=a instanceof Error?a.message:String(a);P(h),ae({title:"Could not start DAG",description:h,variant:"destructive"})}finally{f(!1)}}},[l,c,o,m,v,d]),b=!!v&&!se.has(v.state);return{trigger:g,reset:F,run:v,error:M,isTriggering:c,isRunning:b}}const Qe="failed_login_sync_manual",Ze={queued:"Queuedâ¦",running:"Runningâ¦",success:"Succeeded",failed:"Failed",skipped:"Skipped"},Je={queued:{className:"bg-slate-100 text-slate-700 border-slate-200",Icon:V},running:{className:"bg-blue-50 text-blue-700 border-blue-200",Icon:V},success:{className:"bg-green-50 text-green-700 border-green-200",Icon:Xe},failed:{className:"bg-red-50 text-red-700 border-red-200",Icon:ne},skipped:{className:"bg-amber-50 text-amber-700 border-amber-200",Icon:ne}},We=({onSuccess:l})=>{const{trigger:i,run:p,isTriggering:o,isRunning:C}=Ke({dagId:Qe,onSuccess:f=>{ae({title:"Sync complete",description:"Pending profile approvals refreshed."}),l==null||l(),console.log("[failed_login_sync_manual] success",f)},onFailure:f=>{ae({title:`Sync ${f.state}`,description:f.error_message||"The sync DAG ended without succeeding. Check Airflow logs.",variant:"destructive"}),console.warn("[failed_login_sync_manual] terminal",f)}}),u=()=>i(),c=o||C;return e.jsxs("div",{className:"flex items-center gap-2",children:[p&&e.jsx(Ye,{state:p.state}),e.jsxs(T,{onClick:u,disabled:c,variant:"default",children:[c?e.jsx(V,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(Ue,{className:"w-4 h-4 mr-2"}),c?"Syncingâ¦":"Sync Machine Logins"]})]})},Ye=({state:l})=>{const{className:i,Icon:p}=Je[l],o=l==="queued"||l==="running";return e.jsxs(D,{variant:"outline",className:i,children:[e.jsx(p,{className:`w-3 h-3 mr-1 ${o?"animate-spin":""}`}
1),Ze[l]]})},q=50,me=[{value:"K",label:"Kindergarten"},{value:"1",label:"1st Grade"},{value:"2",label:"2nd Grade"},{value:"3",label:"3rd Grade"},{value:"4",label:"4th Grade"},{value:"5",label:"5th Grade"},{value:"6",label:"6th Grade"},{value:"7",label:"7th Grade"},{value:"8",label:"8th Grade"},{value:"9",label:"9th Grade"},{value:"10",label:"10th Grade"},{value:"11",label:"11th Grade"},{value:"12",label:"12th Grade"}],vs=()=>{const{userProfile:l}=he(),[i,p]=n.useState("pending"),[o,C]=n.useState(1),{approvals:u,total:c,isLoading:f,isFetching:v,refetch:S,approveProfile:M,rejectProfile:P,isApproving:N,isRejecting:w,bulkApprove:_,bulkReject:k,isBulkApproving:E,isBulkRejecting:d}=De(i,o-1,q,"machine"),{schools:m,isLoading:F}=ze((l==null?void 0:l.district_id)||void 0),[g,b]=n.useState(new Set),[x,a]=n.useState(!1),h=u,j=Math.max(1,Math.ceil(c/q)),[z,I]=n.useState(!1),[ge,H]=n.useState(!1),[xe,fe]=n.useState({}),je=s=>{p(s),b(new Set),a(!1),C(1)},G=h.map(s=>s.id),U=G.length>0&&G.every(s=>g.has(s)),pe=G.some(s=>g.has(s)),be=()=>{if(U){const s=new Set(g);G.forEach(t=>s.delete(t)),b(s),a(!1)}else{const s=new Set(g);G.forEach(t=>s.add(t)),b(s)}},ve=s=>{const t=new Set(g);t.has(s)?(t.delete(s),a(!1)):t.add(s),b(t)},Se=()=>{a(!0),b(new Set(u.map(s=>s.id)))},X=x?c:g.size,te=x?u.map(s=>s.id):Array.from(g),$=s=>xe[s]||{school_id:null,role:"student",grade:null},K=(s,t,B)=>{fe(O=>({...O,[s]:{...$(s),[t]:B}}))},Ne=s=>{const t=$(s.id);M({id:s.id,school_id:t.school_id,role:t.role,grade:t.grade})},we=s=>{P({id:s.id})},Ce=(s,t,B)=>{_({ids:te,school_id:s,role:t,grade:B},{onSuccess:()=>{b(new Set),a(!1),I(!1)}})},_e=()=>{k({ids:te},{onSuccess:()=>{b(new Set),a(!1),H(!1)}})},ke=s=>{switch(s){case"pending":return e.jsxs(D,{variant:"outline",className:"bg-yellow-50 text-yellow-700 border-yellow-200",children:[e.jsx(ie,{className:"w-3 h-3 mr-1"})," Pending"]});case"approved":return e.jsxs(D,{variant:"outline",className:"bg-green-50 text-green-700 border-green-200",children:[e.jsx(ce,{className:"w-3 h-3 mr-1"})," Approved"]});case"rejected":return e.jsxs(D,{variant:"outline",className:"bg-red-50 text-red-700 border-red-200",children:[e.jsx(de,{className:"w-3 h-3 mr-1"})," Rejected"]})}},A=i==="pending"||i==="rejected",Ae=s=>{var B,O;const t=$(s.id);return e.jsxs(oe,{children:[A&&e.jsx(R,{className:"w-10",children:e.jsx(ue,{checked:g.has(s.id),onCheckedChange:()=>ve(s.id)})}),e.jsx(R,{className:"font-medium",children:s.email}),e.jsx(R,{children:A?e.jsxs(J,{value:t.school_id||"none",onValueChange:r=>K(s.id,"school_id",r==="none"?null:r),children:[e.jsx(W,{className:"w-[180px]",children:e.jsx(Y,{placeholder:"Select school"})}),e.jsxs(ee,{children:[e.jsx(L,{value:"none",children:"No school"}),m==null?void 0:m.map(r=>e.jsx(L,{value:r.id,children:r.name},r.id))]})]}):e.jsx("span",{className:"text-muted-foreground",children:((B=m==null?void 0:m.find(r=>r.id===s.school_id))==null?void 0:B.name)||"-"})}),e.jsx(R,{children:A?e.jsxs(J,{value:t.role,onValueChange:r=>K(s.id,"role",r),children:[e.jsx(W,{className:"w-[120px]",children:e.jsx(Y,{})}),e.jsxs(ee,{children:[e.jsx(L,{value:"student",children:"Student"}),e.jsx(L,{value:"teacher",children:"Teacher"})]})]}):e.jsx(D,{variant:"secondary",className:"capitalize",children:s.role||"-"})}),e.jsx(R,{children:A?e.jsxs(J,{value:t.grade||"none",onValueChange:r=>K(s.id,"grade",r==="none"?null:r),children:[e.jsx(W,{className:"w-[130px]",children:e.jsx(Y,{placeholder:"No grade"})}),e.jsxs(ee,{children:[e.jsx(L,{value:"none",children:"No grade"}),me.map(r=>e.jsx(L,{value:r.value,children:r.label},r.value))]})]}):e.jsx("span",{className:"text-muted-foreground",children:t.grade?((O=me.find(r=>r.value===t.grade))==null?void 0:O.label)||t.grade:"-"})}),e.jsx(R,{children:ke(s.status)}),e.jsxs(R,{children:[A&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(T,{size:"sm",onClick:()=>Ne(s),disabled:N||w,children:[N?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(le,{className:"w-4 h-4 mr-1"}),"Approve"]}),e.jsxs(T,{size:"sm",variant:"destructive",onClick:()=>we(s),disabled:N||w||i==="rejected",children:[w?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(re,{className:"w-4 h-4 mr-1"}),"Reject"]})]}),i==="approved"&&s.approved_at&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Approved on ",$e(new Date(s.approved_at),"MMM d, yyyy")]})]})]},s.id)};return e.jsxs("div",{className:"container mx-auto py-6 space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Machine Profile Approvals"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Review machine-login profile requests that are not yet linked to a district"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(We,{onSuccess:()=>{b(new Set),a(!1),S()}}),e.jsxs(T,{variant:"outline",onClick:()=>S(),disabled:v,children:[e.jsx(ye,{className:`w-4 h-4 mr-2 ${v?"animate-spin":""}`}),"Refresh"]})]})]}),g.size>0&&A&&e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-muted rounded-lg border",children:[e.jsxs("span",{className:"text-sm font-medium",children:[X," selected"]}),!x&&g.size===G.length&&c>q&&e.jsxs(T,{variant:"link",size:"sm",className:"text-xs",onClick:Se,children:["Select all ",c," records across all pages"]}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[i!=="rejected"&&e.jsxs(T,{size:"sm",variant:"destructive",onClick:()=>H(!0),disabled:d,children:[e.jsx(re,{className:"w-4 h-4 mr-1"})," Reject Selected"]}),e.jsxs(T,{size:"sm",onClick:()=>I(!0),disabled:E,children:[e.jsx(le,{className:"w-4 h-4 mr-1"})," Approve Selected"]})]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Pe,{children:"Pending Profile Requests"}),!f&&c>0&&e.jsxs(D,{variant:"secondary",className:"text-sm",children:[c.toLocaleStr
1ing()," ",i," request",c!==1?"s":""]})]})}),e.jsx(Ee,{children:e.jsxs(Ie,{value:i,onValueChange:je,children:[e.jsxs(Ge,{className:"mb-4",children:[e.jsxs(Z,{value:"pending",className:"gap-2",children:[e.jsx(ie,{className:"w-4 h-4"})," Pending"]}),e.jsxs(Z,{value:"rejected",className:"gap-2",children:[e.jsx(de,{className:"w-4 h-4"})," Rejected"]}),e.jsxs(Z,{value:"approved",className:"gap-2",children:[e.jsx(ce,{className:"w-4 h-4"})," Approved"]})]}),e.jsx(Be,{value:i,children:f||F?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Le,{size:40,label:""})}):c===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:e.jsxs("p",{children:["No ",i," approvals found"]})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Oe,{children:[e.jsx(Me,{children:e.jsxs(oe,{children:[A&&e.jsx(y,{className:"w-10",children:e.jsx(ue,{checked:U,onCheckedChange:be,"aria-label":"Select all on this page",...pe&&!U?{"data-state":"indeterminate"}:{}})}),e.jsx(y,{children:"Email"}),e.jsx(y,{children:"School"}),e.jsx(y,{children:"Role"}),e.jsx(y,{children:"Grade"}),e.jsx(y,{children:"Status"}),e.jsx(y,{children:"Actions"})]})}),e.jsx(Fe,{children:h.map(Ae)})]})}),j>1&&e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",(o-1)*q+1,"â",Math.min(o*q,c)," of ",c.toLocaleString()]}),e.jsx(He,{currentPage:o,totalPages:j,onPageChange:C})]})]})})]})})]}),e.jsx(qe,{open:z,onOpenChange:I,selectedCount:X,schools:m||[],onConfirm:Ce,isPending:E}),e.jsx(Ve,{open:ge,onOpenChange:H,selectedCount:X,onConfirm:_e,isPending:d})]})};export{vs 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.