1import{j as e}from"./radix-Cmq07x6K.js";import{r,u as X,N as Y,L as W}from"./react-vendor-3Ku-1ERf.js";import{c as Z,n as ee,B as i,p as I,o as se,X as te,g as x,f as ae,A as re,k as ie,aU as le,F as ne}from"./index-DNJkTYkI.js";import{u as M}from"./useGalleryProjects-VdlpzRJ4.js";import{C as $,a as R}from"./card-BT7M_i6G.js";import{A as G,a as B,b as O,c as _,d as U,e as q,f as H,g as K,h as Q}from"./alert-dialog-bp6ngcUd.js";import{I as T}from"./input-Be1FlM5N.js";import{S as ce,a as oe,b as de,c as he,d as me}from"./select-A5viTzpK.js";import{D as z,s as xe,S as ge,a as ue}from"./gallerySort-B5UqzuH6.js";import{u as we}from"./useGalleryCategories-B3OxAd7F.js";import{P as be}from"./pencil-DreNek2w.js";import{T as V}from"./trash-2-1ZfQ2Y8K.js";import{A as pe}from"./arrow-down-BenvG75o.js";import{S as je}from"./square-pen-D4fx1K45.js";import{C as fe}from"./chevron-left-NpZk3Uhh.js";import"./firebase-CPbFPgyj.js";import"./supabase-M27pd__B.js";import"./chevron-up-CzPssOF-.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 Ne=Z("Tags",[["path",{d:"m15 5 6.3 6.3a2.4 2.4 0 0 1 0 3.4L17 19",key:"1cbfv1"}],["path",{d:"M9.586 5.586A2 2 0 0 0 8.172 5H3a1 1 0 0 0-1 1v5.172a2 2 0 0 0 .586 1.414L8.29 18.29a2.426 2.426 0 0 0 3.42 0l3.58-3.58a2.426 2.426 0 0 0 0-3.42z",key:"135mg7"}],["circle",{cx:"6.5",cy:"9.5",r:".5",fill:"currentColor",key:"5pm5xn"}]]);function ve(){const{categories:N,loading:w,isSeeded:D,seedDefaults:c,addCategory:P,renameCategory:E,removeCategory:S}=we(),{projects:g,saveProject:v}=M(),[o,u]=r.useState(!1),[d,k]=r.useState(""),[b,p]=r.useState(null),[h,y]=r.useState(""),[n,m]=r.useState(!1);r.useEffect(()=>{!w&&!D&&c().catch(()=>{})},[w,D,c]);const C=r.useMemo(()=>{const s=new Map;for(const t of g)for(const a of t.categories??[])s.set(a,(s.get(a)??0)+1);return s},[g]),j=async()=>{m(!0);try{await P(d),k(""),x.success("Category added")}catch(s){x.error(s instanceof Error?s.message:"Failed to add category")}finally{m(!1)}},f=s=>{p(s.id),y(s.name)},A=async s=>{m(!0);try{await E(s.id,h);const t=h.trim().replace(/\s+/g," "),a=g.filter(l=>(l.categories??[]).includes(s.name));await Promise.all(a.map(l=>{const J=Array.from(new Set((l.categories??[]).map(F=>F===s.name?t:F)));return v({...l,categories:J})})),p(null),x.success(a.length?`Renamed and updated ${a.length} project${a.length!==1?"s":""}`:"Category renamed")}catch(t){x.error(t instanceof Error?t.message:"Failed to rename category")}finally{m(!1)}},L=async s=>{m(!0);try{const t=g.filter(a=>(a.categories??[]).includes(s.name));await Promise.all(t.map(a=>v({...a,categories:(a.categories??[]).filter(l=>l!==s.name)}))),await S(s.id),x.success("Category removed")}catch(t){x.error(t instanceof Error?t.message:"Failed to remove category")}finally{m(!1)}};return e.jsxs($,{className:"bg-white/[0.03] border-white/10 mb-6",children:[e.jsxs("button",{type:"button",onClick:()=>u(s=>!s),"aria-expanded":o,className:"flex w-full items-center gap-3 px-5 py-3.5 text-left",children:[e.jsx(Ne,{className:"h-4 w-4 text-illumigreen"}),e.jsx("span",{className:"text-white font-semibold",children:"Categories"}),e.jsx("span",{className:"text-white/40 text-xs",children:w?"...":`${N.length} tags`}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-white/40 text-xs hidden sm:inline",children:"Add, rename, or remove gallery tags"}),e.jsx(ee,{className:`h-4 w-4 text-white/40 transition-transform ${o?"rotate-180":""}`})]}),o&&e.jsxs(R,{className:"pt-0 pb-4 px-4 sm:px-5 space-y-3",children:[e.jsxs("div",{className:"flex gap-2 max-w-sm",children:[e.jsx(T,{value:d,onChange:s=>k(s.target.value),onKeyDown:s=>{s.key==="Enter"&&d.trim()&&!n&&j()},placeholder:"New category name",maxLength:40,className:"bg-white/5 border-white/10 text-white h-9"}),e.jsxs(i,{onClick:j,disabled:n||!d.trim(),className:"bg-illumigreen text-black hover:bg-illumigreen/80 font-semibold shrink-0 h-9",children:[e.jsx(I,{className:"h-4 w-4 mr-1.5"}),"Add"]})]}),w?e.jsx("p",{className:"text-white/40 text-sm",children:"Loading c
6ategories..."}):N.length===0?e.jsx("p",{className:"text-white/40 text-sm",children:"No categories yet."}):e.jsx("ul",{className:"flex flex-wrap gap-2",children:N.map(s=>{const t=C.get(s.name)??0,a=b===s.id;return e.jsx("li",{className:`flex items-center gap-2 sm:gap-1 rounded-full border py-1 ${a?"border-illumigreen/40 bg-white/5 pl-1 pr-1":"border-white/10 bg-white/5 pl-3 pr-1"}`,children:a?e.jsxs(e.Fragment,{children:[e.jsx(T,{value:h,onChange:l=>y(l.target.value),onKeyDown:l=>{l.key==="Enter"&&!n&&A(s),l.key==="Escape"&&p(null)},maxLength:40,autoFocus:!0,className:"bg-transparent border-none text-white h-9 sm:h-6 w-36 px-2 text-sm focus-visible:ring-0"}),e.jsx(i,{size:"icon",variant:"ghost","aria-label":"Save",disabled:n,onClick:()=>A(s),className:"h-9 w-9 sm:h-6 sm:w-6 text-illumigreen hover:bg-illumigreen/10 shrink-0",children:e.jsx(se,{className:"h-3.5 w-3.5"})}),e.jsx(i,{size:"icon",variant:"ghost","aria-label":"Cancel",onClick:()=>p(null),className:"h-9 w-9 sm:h-6 sm:w-6 text-white/60 hover:bg-white/10 shrink-0",children:e.jsx(te,{className:"h-3.5 w-3.5"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-white",children:s.name}),e.jsx("span",{className:"text-[10px] text-white/35 mr-0.5",children:t}),e.jsx(i,{size:"icon",variant:"ghost","aria-label":`Rename ${s.name}`,disabled:n,onClick:()=>f(s),className:"h-9 w-9 sm:h-6 sm:w-6 text-white/50 hover:text-illumigreen hover:bg-white/10 shrink-0",children:e.jsx(be,{className:"h-3 w-3"})}),e.jsxs(G,{children:[e.jsx(B,{asChild:!0,children:e.jsx(i,{size:"icon",variant:"ghost","aria-label":`Delete ${s.name}`,disabled:n,className:"h-9 w-9 sm:h-6 sm:w-6 text-red-400 hover:text-red-300 hover:bg-red-500/10 shrink-0",children:e.jsx(V,{className:"h-3 w-3"})})}),e.jsxs(O,{className:"bg-zinc-900 border-white/10",children:[e.jsxs(_,{children:[e.jsxs(U,{className:"text-white",children:['Delete "',s.name,'"?']}),e.jsx(q,{className:"text-white/50",children:t>0?`${t} project${t!==1?"s":""} use this category. Deleting will remove the tag from ${t!==1?"them":"it"}. This cannot be undone.`:"This category is not used by any project. This cannot be undone."})]}
6),e.jsxs(H,{children:[e.jsx(K,{className:"bg-transparent border-white/10 text-white hover:bg-white/10",children:"Cancel"}),e.jsx(Q,{onClick:()=>L(s),className:"bg-red-600 text-white hover:bg-red-500",children:"Delete"})]})]})]})]})},s.id)})})]})]})}const Oe=()=>{const{user:N,isLoading:w,isAdmin:D}=ae(),{projects:c,loading:P,deleteProject:E}=M(),S=X(),[g,v]=r.useState(null),[o,u]=r.useState(1),[d,k]=r.useState(""),[b,p]=r.useState("date"),[h,y]=r.useState(z.date),n=12,m=s=>{p(s),y(z[s]),u(1)},C=r.useMemo(()=>{const s=d.trim().toLowerCase();return s?c.filter(t=>t.title.toLowerCase().includes(s)):c},[c,d]),j=r.useMemo(()=>xe(C,b,h),[C,b,h]),f=Math.max(1,Math.ceil(j.length/n)),A=r.useMemo(()=>{const s=(o-1)*n;return j.slice(s,s+n)},[j,o]);if(w)return e.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-illumigreen"})});if(!N)return e.jsx(Y,{to:"/login",replace:!0});if(!D())return e.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"text-2xl font-bold text-white mb-2",children:"Access Denied"}),e.jsx("p",{className:"text-white/60",children:"You do not have permission to access this page."})]})});const L=async s=>{v(s);try{await E(s),x.success("Project deleted successfully")}catch{x.error("Failed to delete project")}finally{v(null)}};return e.jsx("div",{className:"min-h-screen bg-black",children:e.jsxs("div",{className:"max-w-6xl mx-auto px-3 sm:px-4 pt-1 sm:pt-6 pb-8",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 sm:gap-4 mb-6 sm:mb-8",children:[e.jsxs("div",{className:"flex flex-1 items-center gap-2 sm:gap-4 min-w-0",children:[e.jsx(W,{to:"/admin",children:e.jsx(i,{variant:"ghost",size:"icon",className:"text-white hover:text-illumigreen",children:e.jsx(re,{className:"h-5 w-5"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold text-white",children:"Gallery Projects"}),e.jsxs("p",{className:"text-white/50 text-sm mt-1",children:[c.length," project",c.length!==1?"s":""]})]})]}),e.jsxs(i,{onClick:()=>S("/manage-gallery/edit"),className:"self-start sm:self-auto bg-illumigreen text-black hover:bg-illumigreen/80 font-semibold",children:[e.jsx(I,{className:"h-4 w-4 mr-2"}),"New Project"]})]}),e.jsx(ve,{}),e.jsxs("div",{className:"mb-6 flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 min-w-[220px]",children:[e.jsx(ie,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-white/40"}),e.jsx(T,{value:d,onChange:s=>{k(s.target.value),u(1)},placeholder:"Search projects by title",className:"pl-9 bg-white/5 border-white/10 text-white"})]}),e.jsxs(ce,{value:b,onValueChange:s=>m(s),children:[e.jsx(oe,{"aria-label":"Sort by",className:"h-10 w-[150px] bg-white/5 border-white/10 text-white/70 focus:ring-illumigreen/40",children:e.jsx(de,{})}),e.jsx(he,{className:"border-white/10 bg-zinc-900 text-white/80",children:ge.map(({field:s,label:t})=>e.jsx(me,{value:s,children:t},s))})]}),e.jsx(i,{variant:"ghost",size:"icon",onClick:()=>{y(h==="desc"?"asc":"desc"),u(1)},"aria-label":`Flip sort order, currently ${ue[b][h]}`,className:"h-10 w-10 border border-white/10 bg-white/5 text-white/60 hover:bg-white/10 hover:text-white",children:h==="desc"?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(le,{className:"h-4 w-4"})})]}),P?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-illumigreen"})}):c.length===0?e.jsxs("div",{className:"text-center py-20",children:[e.jsx("p",{className:"text-white/40 text-lg mb-4",children:"No gallery projects yet."}),e.jsx("p",{className:"text-white/30 text-sm mb-6",children:"Create a new project to get started."})]}):C.length===0?e.jsx("div",{className:"text-center py-20",children:e.jsxs("p",{className:"text-white/40 text-lg",children:['No projects match "',d.trim(),'".']})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:A.map(s=>e.jsx($,{className:"bg-white/[0.03] border-white/10 hover:border-white/20 transition-all duration-200 group",children:e.jsxs(R,{className:"p-0",children:[e.jsx("div",{className:"relative aspect-video overflow-hidden rounded-t-lg",children:s.thumbnailImage?e.jsx("img",{src:s.thumbnailImage,alt:s.title,loading:"lazy",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"}):e.jsx("div",{className:"w-full h-full bg-white/5 flex items-center justify-center",children:e.jsx("span",{className:"text-white/20 text-sm",children:"No thumbnail"})})}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"text-white font-semibold text-lg truncate mb-1",children:s.title}),e.jsxs("p",{className:"text-white/40 text-xs font-mono mb-2",children:["/",s.slug]}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-3",children:s.categories.map(t=>e.jsx("span",{className:"text-[10px] uppercase tracking-wider px-2 py-0.5 rounded-full bg-illumigreen/10 text-illumigreen/70 border border-illumigreen/20",children:t},t))}),s.date&&e.jsx("p",{className:"text-white/30 text-xs mb-3",children:s.date}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(i,{variant:"ghost",size:"sm",onClick:()=>S(`/manage-gallery/edit?slug=${s.slug}`),className:"flex-1 border border-white/10 bg-transparent text-white hover:bg-white/10 hover:text-illumigreen",children:[e.jsx(je,{className:"h-3.5 w-3.5 mr-1.5"}),"Edit"]}),e.jsxs(G,{children:[e.jsx(B,{asChild:!0,children:e.jsx(i,{variant:"ghost",size:"sm","aria-label":"Delete project",className:"border border-red-500/20 bg-transparent text-red-400 hover:bg-red-500/10 hover:text-red-300",children:e.jsx(V,{className:"h-3.5 w-3.5"})})}),e.jsxs(O,{className:"bg-zinc-900 border-white/10",children:[e.jsxs(_,{children:[e.jsxs(U,{className:"text-white",children:['Delete "',s.title,'"?']}),e.jsx(q,{className:"text-white/50",children:"This action cannot be undone. This will permanently delete the project and all associated data."})]}
6),e.jsxs(H,{children:[e.jsx(K,{className:"bg-white/5 border-white/10 text-white hover:bg-white/10",children:"Cancel"}),e.jsx(Q,{onClick:()=>L(s.id),disabled:g===s.id,className:"bg-red-600 hover:bg-red-700 text-white",children:g===s.id?"Deleting...":"Delete"})]})]})]})]})]})]})},s.id))}),f>1&&e.jsxs("div",{className:"flex items-center justify-center gap-4 mt-8 pb-4",children:[e.jsxs(i,{variant:"ghost",size:"sm",onClick:()=>u(s=>Math.max(1,s-1)),disabled:o===1,className:"border border-white/10 bg-transparent text-white/60 hover:bg-white/10 hover:text-white disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(fe,{className:"h-4 w-4 mr-1"}),"Previous"]}),e.jsxs("span",{className:"text-sm text-white/50",children:["Page ",o," of ",f]}),e.jsxs(i,{variant:"ghost",size:"sm",onClick:()=>u(s=>Math.min(f,s+1)),disabled:o===f,className:"border border-white/10 bg-transparent text-white/60 hover:bg-white/10 hover:text-white disabled:opacity-30 disabled:cursor-not-allowed",children:["Next",e.jsx(ne,{className:"h-4 w-4 ml-1"})]})]})]})]})})};export{Oe 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.