1import{r as n,j as e}from"./vendor-ahVw9cdH.js";import{Z as T,aG as _,Y as L,a5 as E,aW as M,bd as z,a6 as B,R as d,bZ as F,V as u,a7 as N,bN as G,bP as H,bQ as I,bR as O,bS as P,bK as Y,bT as Z,bU as $,O as p,ev as w,bY as C}from"./index-DXi0I5ak.js";import{C as l}from"./circle-x-gCUm4_Za.js";import"./radix--pSzM2y8.js";import"./supabase-DYrB2Yg5.js";import"./charts-CSweoJhv.js";import"./query-CeIq2NOR.js";import"./forms-Cc1FL3tT.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const U=T("FileDown",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]]);function te(){const{toast:m}=_(),[h,q]=n.useState(null),[x,D]=n.useState([]),[A,j]=n.useState(!0),[t,o]=n.useState(null),[a,r]=n.useState(null),[v,g]=n.useState(""),[c,f]=n.useState(!1),b=async()=>{j(!0);const{data:{user:s}}=await p.auth.getUser();q((s==null?void 0:s.id)??null);const{data:i}=await p.from("gdpr_requests").select("*").order("created_at",{ascending:!1}).limit(200);D(i??[]),j(!1)};n.useEffect(()=>{b()},[]);const R=async()=>{if(!(!t||!a)){f(!0);try{const{data:s,error:i}=await p.functions.invoke("admin-gdpr-approve",{body:{requestId:t.id,decision:a,note:v}});if(i)throw i;if(s!=null&&s.error)throw new Error(s.error);m({title:`Request ${a==="approve"?"approved":"rejected"}`}),o(null),r(null),g(""),await b()}catch(s){m({variant:"destructive",title:"Action failed",description:s.message})}finally{f(!1)}}},S=s=>{const y={pending:{v:"secondary",icon:C},approved:{v:"default",icon:w},executing:{v:"default",icon:d},completed:{v:"outline",icon:w},rejected:{v:"destructive",icon:l},failed:{v:"destructive",icon:l},cancelled:{v:"outline",icon:l},expired:{v:"outline",icon:l}}[s]??{v:"outline",icon:C},k=y.icon;return e.jsxs(N,{variant:y.v,className:"gap-1",children:[e.jsx(k,{className:"h-3 w-3"}),s]})};return e.jsxs("div",{className:"container max-w-6xl py-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"h-6 w-6"}),e.jsx("h1",{className:"text-2xl font-semibold",children:"GDPR Requests"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Two-admin approval required. You cannot approve a request you created. All actions are audit-logged."}),e.jsxs(E,{children:[e.jsx(M,{children:e.jsx(z,{className:"text-base",children:"Pending & history"})}),e.jsx(B,{children:A?e.jsx(d,{className:"h-5 w-5 animate-spin"}):x.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No requests yet."}):e.jsx("div",{className:"space-y-2",children:x.map(s=>e.jsxs("div",{className:"rounded-md border p-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1 min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.action==="export"?e.jsx(U,{className:"h-4 w-4"}):e.jsx(F,{className:"h-4 w-4 text-destructive"}),e.jsx("span",{className:"font-medium uppercase text-xs",children:s.action}),S(s.status)]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-0.5",children:[e.jsxs("div",{children:["Target: ",e.jsx("span",{className:"font-mono",children:s.target_user_id})]}),e.jsxs("div",{children:["Requested by: ",e.jsxs("span",{className:"font-mono",children:[s.requested_by.slice(0,8),"â¦"]})," · ",new Date(s.created_at).toLocaleString()]}),s.reason&&e.jsxs("div",{children:["Reason: ",s.reason,s.reason_detail?` â ${s.reason_detail}`:""]}),s.scheduled_for&&e.jsxs("div",{children:["Scheduled: ",new Date(s.scheduled_for).toLocaleString()]})]})]}),s.status==="pending"&&s.requested_by!==h&&e.jsxs("div",{className:"flex gap-1",children:[e.jsx(u,{size:"sm",onClick:()=>{o(s),r("approve")},children:"Approve"}),e.jsx(u,{size:"sm",variant:"outline",onClick:()=>{o(s),r("reject")},children:"Reject"})]}),s.status==="pending"&&s.requested_by===h&&e.jsx(N,{variant:"outline",className:"text-[10px]",children:"Awaiting other admin"})]},s.id))})})]}),e.jsx(G,{open:!!t,onOpenChange:s=>
6!s&&o(null),children:e.jsxs(H,{children:[e.jsxs(I,{children:[e.jsxs(O,{children:[a==="approve"?"Approve":"Reject"," ",t==null?void 0:t.action," request"]}),e.jsx(P,{children:a==="approve"&&(t==null?void 0:t.action)==="erasure"?"This will schedule the user's account for permanent deletion in 30 days. They will be signed out and emailed immediately.":a==="approve"&&(t==null?void 0:t.action)==="export"?"This will generate an export and email a 24h download link to the user (not to you).":"The request will be rejected and audit-logged."})]}),e.jsx(Y,{placeholder:"Optional note for the audit log",value:v,onChange:s=>g(s.target.value)}),e.jsxs(Z,{children:[e.jsx($,{disabled:c,children:"Cancel"}),e.jsx(u,{variant:a==="approve"?"default":"destructive",disabled:c,onClick:R,children:c?e.jsx(d,{className:"h-4 w-4 animate-spin"}):`Confirm ${a}`})]})]})})]})}export{te 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.