1import{j as e}from"./markdown-BniUNT3b.js";import{r as t}from"./stripe-DNH-pMf_.js";import{A as C}from"./app-header-HmgkKqwJ.js";import{$ as A,t as n,a2 as S,P as I,o as D,I as F,B as r,y as K,w as R,D as T,k as E,l as P,m as _,n as B,q as L}from"./index-DuSE7Tbu.js";import{f as z,a as G,i as H,c as q,b as M,d as O}from"./free-access-Dw4hS7r9.js";import{K as U}from"./key-round-Cuxv64xH.js";import{S as V}from"./shield-alert-DInH9L-N.js";import{C as $}from"./copy-C6imms4s.js";import"./recharts-BxZy5o_C.js";import"./supabase-H0uDwzZe.js";const J={ready:"default",used:"secondary",revoked:"destructive"},ie=()=>{const{isAdmin:d,loading:v}=A(),[m,x]=t.useState(""),[u,p]=t.useState(!1),[c,y]=t.useState(null),[h,g]=t.useState([]),[f,j]=t.useState([]),[i,l]=t.useState(null),o=t.useMemo(()=>async()=>{try{const[a,s]=await Promise.all([z(),G()]);g(a),j(s)}catch{n({title:"Couldn't load free-access records.",variant:"destructive"})}},[]);if(t.useEffect(()=>{d&&o()},[d,o]),v)return e.jsx("div",{className:"flex min-h-screen items-center justify-center text-sm text-muted-foreground",children:"Loadingâ¦"});if(!d)return e.jsx(S,{to:"/app",replace:!0});const N=async a=>{a.preventDefault(),p(!0);try{const s=await q(m);y({email:s.email,rawKey:s.rawKey}),x(""),await o()}catch(s){n({title:s instanceof Error?s.message:"Could not create an access key.",variant:"destructive"})}finally{p(!1)}},k=async()=>{c&&(await navigator.clipboard.writeText(c.rawKey),n({title:"Access key copied."}))},b=async a=>{try{await M(a),await o(),n({title:"Invitation revoked."})}catch{n({title:"Could not revoke that invitation.",variant:"destructive"})}},w=async()=>{if(i)try{await O(i.user_id),await o(),n({title:"Free access revoked. The member's data is untouched."})}catch{n({title:"Could not revoke that account.",variant:"destructive"})}finally{l(null)}};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(I,{title:"Free access · Crosslyst admin",description:"Issue and revoke invitation-only permanent access.",path:"/app/admin/free-access",noindex:!0}),e.jsx(C,{active:"account"}),e.jsxs("main",{className:"container mx-auto max-w-4xl px-3 py-6 sm:px-4 sm:py-10",children:[e.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold sm:text-3xl",children:[e.jsx(U,{className:"h-6 w-6 text-primary","aria-hidden":"true"})," Free access"]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Approve a confirmed member for permanent, card-free Pro access. Each key works once and only for the email you enter."}),e.jsxs("section",{className:"mt-6 rounded-lg border bg-card p-5","aria-label":"Generate an access key",children:[e.jsxs("form",{onSubmit:N,className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"min-w-[240px] flex-1",children:[e.jsx(D,{htmlFor:"approve-email",children:"Approved email address"}),e.jsx(F,{id:"approve-email",type:"email",value:m,onChange:a=>x(a.target.value),placeholder:"[email protected]",className:"mt-1 min-h-[44px]",required:!0})]}),e.jsxs(r,{type:"submit",disabled:u,className:"min-h-[44px] gap-2",children:[u&&e.jsx(K,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}),"Generate key"]})]}),c&&e.jsxs("div",{className:"mt-4 rounded-md border border-primary/30 bg-primary/5 p-4",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(V,{className:"h-4 w-4 text-primary","aria-hidden":"true"}),"Copy this key now â it cannot be displayed again."]}),e.jsx("p",{className:"mt-2 break-all font-mono text-sm",children:c.rawKey}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Bound to ",c.email,". Send it to them and point them at /free-access."]}),e.jsxs(r,{onClick:k,variant:"outline",size:"sm",className:"mt-3 min-h-[40px] gap-2",children:[e.jsx($,{className:"h-4 w-4","aria-hidden":"true"})," Copy key"]})]})]}),e.jsxs("section",{className:"mt-8","aria-label":"Invitation history",children:[e.jsx("h2",{className:"mb-2 text-lg font-semibold",children:"Invitations"}),e.jsxs("div",{className:"divide-y rounded-lg border bg-card",children:[h.length===0&&e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"No invitations yet."}),h.map(a=>{const s=H(a);return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 p-4",children:[e.jsx("span",{className:"flex-1 text-sm",children:a.email}),e.jsx(R,{variant:J[s],children:s}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(a.created_at).toLocaleDateString()}),s==="ready"&&e.jsx(r,{onClick:()=>void b(a.id),variant:"outline",size:"sm",className:"min-h-[40px]",children:"Revoke"})]},a.id)})]})]}),e.jsxs("section",{className:"mt-8","aria-label":"Permanent free accounts",children:[e.jsx("h2",{className:"mb-2 text-lg font-semibold",children:"Permanent free accounts"}),e.jsxs("div",{className:"divide-y rounded-lg border bg-card",children:[f.length===0&&e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"No permanent free accounts yet."}),f.map(a=>e.jsxs("div",{className:"flex flex-wrap items-center gap-3 p-4",children:[e.jsx("span",{className:"flex-1 text-sm",children:a.email??"(no email on profile)"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["since"," ",a.granted_at?new Date(a.granted_at).toLocaleDateString():"unknown"]}),e.jsx(r,{onClick:()=>l(a),variant:"outline",size:"sm",className:"min-h-[40px]",children:"Revoke access"})]}
1,a.user_id))]})]})]}),e.jsx(T,{open:!!i,onOpenChange:a=>!a&&l(null),children:e.jsxs(E,{children:[e.jsxs(P,{children:[e.jsx(_,{children:"Revoke permanent free access?"}),e.jsxs(B,{children:[(i==null?void 0:i.email)??"This member"," will drop to read-only immediately. Their products, listings, images, and schedule are kept â nothing is deleted, and you can issue a new key later."]})]}),e.jsxs(L,{children:[e.jsx(r,{variant:"outline",className:"min-h-[44px]",onClick:()=>l(null),children:"Cancel"}),e.jsx(r,{variant:"destructive",className:"min-h-[44px]",onClick:()=>void w(),children:"Revoke access"})]})]})})]})};export{ie as AdminFreeAccess};
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.