1import{r as e,j as s}from"./vendor-react-C9yDzYQD.js";import{MainLayout as r}from"./MainLayout-SlmExmjp.js";import{PageHeader as a}from"./PageHeader-Dt7JKE_V.js";import{B as t}from"./button-CcIRk75H.js";import{I as n}from"./input-CJADGzyX.js";import{B as d}from"./badge-Dri1da3C.js";import{a as l,u as i}from"./useAuth-Dz3EPsxs.js";import{supabase as o}from"./supabase-client-_h80EYw_.js";import{A as m,h as c,a as x,b as u,c as p,d as h,e as j,f,g}from"./alert-dialog-BZjXuitG.js";import{b,L as w}from"./vendor-router-X7RJKav4.js";import{A as N}from"./arrow-left-B8V7NEG8.js";import{S as v}from"./search-D7ByVMw5.js";import{L as y}from"./loader-circle-CWK_zhHB.js";import{L as _}from"./layers-3-b49D35A-.js";import{L as S}from"./lock-Dh-2FzOx.js";import{G as L}from"./globe-DJqDK8z8.js";import{E as k}from"./eye-off-Dee1325O.js";import{F as A}from"./flame-CC1HVkaC.js";import{U as B}from"./user-DrHqDh0A.js";import{S as C}from"./shield-CcxAGV9V.js";import{f as T}from"./vendor-date-D4HAbvGT.js";import{E as F}from"./eye-Dkh28JiF.js";import{C as z}from"./dropdown-menu-BEBSGtMc.js";import{T as D}from"./trash-2-B7zVZuh_.js";function E(){const{isAdmin:E,isLoading:M}=l(),{toast:U}=i(),[$,H]=e.useState(""),[O,P]=e.useState([]),[q,G]=e.useState(0),[I,K]=e.useState(!0),[J,Q]=e.useState(!1),[R,V]=e.useState(!1),[W,X]=e.useState(null),Y=e.useMemo(()=>$.trim(),[$]),Z=async(e,s)=>{s?V(!0):Q(!0);try{const{data:r,error:a}=await o.rpc("admin_get_boards_recent",{p_search_query:Y||null,p_limit:40,p_offset:e});if(a)throw a;const t=r||[];P(e=>s?[...e,...t]:t),G(e),K(40===t.length)}catch(r){U({title:"Failed to load boards",description:r.message,variant:"error"})}finally{Q(!1),V(!1)}};return e.useEffect(()=>{if(!E)return;const e=window.setTimeout(()=>{Z(0,!1)},200);return()=>window.clearTimeout(e)},[E,Y]),M?null:E?s.jsx(r,{children:s.jsxs("div",{className:"max-w-7xl mx-auto p-6 space-y-6",children:[s.jsx(a,{title:"Admin Boards",description:"All site boards ordered by latest updated, including private ones.",rightAction:s.jsx(w,{to:"/admin",children:s.jsxs(t,{variant:"outline",size:"sm",className:"rounded-xl gap-2",children:[s.jsx(N,{className:"w-4 h-4"}),"Admin"]})})}),s.jsx("div",{className:"rounded-[2rem] border border-border/50 bg-card/60 backdrop-blur-xl p-5 shadow-soft",children:s.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Moderation board index"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"Search by board name or owner, then open any board on an admin-only viewer."})]}),s.jsxs("div",{className:"relative w-full md:max-w-sm",children:[s.jsx(v,{className:"w-4 h-4 text-muted-foreground absolute left-3 top-1/2 -translate-y-1/2"}),s.jsx(n,{value:$,onChange:e=>H(e.target.value),placeholder:"Search boards or owners",className:"pl-9 rounded-xl"})]})]})}),s.jsx("div",{className:"space-y-4",children:J?s.jsxs("div",{className:"rounded-[2rem] border border-border/50 bg-card/60 p-10 flex items-center justify-center gap-3 text-muted-foreground",children:[s.jsx(y,{className:"w-5 h-5 animate-spin"}),"Loading boardsâ¦"]}):0===O.length?s.jsxs("div",{className:"rounded-[2rem] border border-dashed border-border/60 bg-card/40 p-10 text-center",children:[s.jsx("p",{className:"text-lg font-semibold text-foreground",children:"No boards found"}),s.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Try a different search term."})]}):O.map(e=>{const r=e.owner_username?`@${e.owner_username}`:e.owner_full_name||"Unknown owner";return s.jsx("div",{className:"rounded-[2rem] border border-border/50 bg-card/60 backdrop-blur-xl p-5 shadow-soft",children:s.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[s.jsxs("div",{className:"min-w-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"inline-flex items-center gap-2 rounded-xl bg-primary/8 px-3 py-1.5 text-sm font-semibold text-primary",children:[s.jsx(_,{className:"w-4 h-4"}),s.jsx("span",{className:"truncate max-w-[16rem]",children:e.name})]}),e.is_private?s.jsxs(d,{variant:"secondary",className:"gap-1",children:[s.jsx(S,{className:"w-3 h-3"}),"Private"]}):s.jsxs(d,{variant:"secondary",className:"gap-1",children:[s.jsx(L,{className:"w-3 h-3"}),"Public"]}),e.is_hidden?s.jsxs(d,{variant:"outline",className:"gap-1",children:[s.jsx(k,{className:"w-3 h-3"}),"Hidden"]}):null,e.is_mature?s.jsxs(d,{variant:"outline",className:"gap-1",children:[s.jsx(A,{className:"w-3 h-3"}),"Mature"]}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 text-sm text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(B,{className:"w-4 h-4"}),e.owner_full_name||r,e.owner_username?s.jsx("span",{className:"text-primary",children:r}):null]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(C,{className:"w-4 h-4"}),e.memory_count||0," ",1===e.memory_count?"echo":"echoes"]}),s.jsxs("span",{children:["Updated ",T(new Date(e.updated_at),{addSuffix:!0})]})]}
1),e.description?s.jsx("p",{className:"text-sm text-foreground/85 leading-relaxed max-w-3xl",children:e.description}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.owner_username?s.jsx(w,{to:`/u/${e.owner_username}`,target:"_blank",children:s.jsxs(t,{variant:"outline",size:"sm",className:"rounded-xl gap-2",children:[s.jsx(B,{className:"w-4 h-4"}),"Owner"]})}):null,s.jsx(w,{to:`/admin/boards/${e.id}`,children:s.jsxs(t,{size:"sm",className:"rounded-xl gap-2",children:[s.jsx(F,{className:"w-4 h-4"}),"Open Board",s.jsx(z,{className:"w-4 h-4"})]})}),s.jsxs(m,{children:[s.jsx(c,{asChild:!0,children:s.jsxs(t,{variant:"outline",size:"sm",className:"rounded-xl gap-2 border-destructive/30 text-destructive hover:bg-destructive/10",disabled:W===e.id,children:[W===e.id?s.jsx(y,{className:"w-4 h-4 animate-spin"}):s.jsx(D,{className:"w-4 h-4"}),"Delete Board"]})}),s.jsxs(x,{className:"rounded-[2rem]",children:[s.jsxs(u,{children:[s.jsx(p,{children:"Delete board?"}),s.jsxs(h,{children:['This permanently deletes "',e.name,'" from Echo. The board will be removed for everyone, including the owner.']})]}),s.jsxs(j,{children:[s.jsx(f,{className:"rounded-xl",children:"Cancel"}),s.jsx(g,{className:"rounded-xl bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{(async e=>{X(e.id);try{const{error:s}=await o.rpc("admin_delete_board",{p_board_id:e.id});if(s)throw s;P(s=>s.filter(s=>s.id!==e.id)),K(e=>e),U({title:"Board deleted",description:`"${e.name}" has been permanently deleted.`})}catch(s){U({title:"Failed to delete board",description:s.message,variant:"error"})}finally{X(null)}})(e)},children:"Delete permanently"})]})]})]})]})]})},e.id)})}),O.length>0&&I?s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(t,{variant:"outline",className:"rounded-xl",disabled:R,onClick:()=>{Z(q+40,!0)},children:R?s.jsxs(s.Fragment,{children:[s.jsx(y,{className:"w-4 h-4 mr-2 animate-spin"}),"Loadingâ¦"]}):"Load more boards"})}):null]})}):s.jsx(b,{to:"/",replace:!0})}export{E 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.