1import{c as oe,K as he,O as ue,M as xe,q as me,r as l,s as x,j as e,S as ge,N as je,L as _,B as j,P as B,Q as E,T as M,V as L,Y as I,Z as F,_ as z,$,a0 as q,F as fe}from"./index-CISjGKDG.js";import{I as pe}from"./input-DGwrk3E_.js";import{B as w}from"./badge-CYkC30cE.js";import{T as ve,a as be,b as A,c as o,d as Ne,e as d}from"./table-DqBp5wl9.js";import{S as V,a as H,b as we,c as O,d as h}from"./select-DvsdkMH9.js";import{C as Q,A as R}from"./checkbox-DRbi5eZe.js";import{I as Se}from"./image-BoCP9cXw.js";import{P as De}from"./plus-BiEo2wCc.js";import{S as ye}from"./search-D6dewDhK.js";import{T as Y}from"./trash-2-BemfS7GG.js";import{f as K}from"./format-BEMO4FpZ.js";import"./index-BdQq_4o_.js";import"./index-BqPSmliO.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 _e=oe("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]),qe=()=>{const{user:f,loading:S}=he(),{isAdmin:p,loading:C}=ue(),v=xe(),{toast:i}=me(),[U,Z]=l.useState([]),[G,J]=l.useState({}),[W,D]=l.useState(!0),[T,X]=l.useState(""),[y,ee]=l.useState("all"),[c,b]=l.useState([]),[m,se]=l.useState("created_at"),[te,P]=l.useState("desc");l.useEffect(()=>{!S&&!f&&v("/auth")},[f,S,v]),l.useEffect(()=>{!C&&!p&&f&&(i({title:"Access Denied",description:"You don't have permission to access this page.",variant:"destructive"}),v("/"))},[p,C,f,v,i]),l.useEffect(()=>{p&&N()},[p]);const N=async()=>{D(!0);const{data:s,error:t}=await x.from("blog_posts").select("id, title, slug, status, created_at, published_date, author_id").order("created_at",{ascending:!1});if(t){i({title:"Error fetching posts",description:t.message,variant:"destructive"}),D(!1);return}Z(s||[]);const a=[...new Set((s||[]).map(r=>r.author_id))];if(a.length>0){const{data:r}=await x.from("profiles").select("id, full_name").in("id",a),n={};(r||[]).forEach(g=>{n[g.id]=g}),J(n)}D(!1)},ae=async s=>{const{error:t}=await x.from("blog_posts").delete().eq("id",s);t?i({title:"Error deleting post",description:t.message,variant:"destructive"}):(i({title:"Post deleted"}),N())},le=async()=>{const{error:s}=await x.from("blog_posts").delete().in("id",c);s?i({title:"Error deleting posts",description:s.message,variant:"destructive"}):(i({title:`${c.length} posts deleted`}),b([]),N())},re=async(s,t)=>{const a={status:t};if(t==="published"){const{data:n}=await x.from("blog_posts").select("published_date").eq("id",s).single();n!=null&&n.published_date||(a.published_date=new Date().toISOString().split("T")[0])}const{error:r}=await x.from("blog_posts").update(a).eq("id",s);r?i({title:"Error updating status",description:r.message,variant:"destructive"}):(i({title:"Status updated"}),N())},ie=s=>{switch(s){case"published":return e.jsx(w,{className:"bg-green-500 hover:bg-green-600",children:"Published"});case"draft":return e.jsx(w,{variant:"secondary",children:"Draft"});case"archived":return e.jsx(w,{variant:"destructive",children:"Archived"});default:return e.jsx(w,{variant:"outline",children:s})}},k=s=>{m===s?P(t=>t==="desc"?"asc":"desc"):(se(s),P("desc"))},u=U.filter(s=>{const t=s.title.toLowerCase().includes(T.toLowerCase()),a=y==="all"||s.status===y;return t&&a}).sort((s,t)=>{const a=m==="created_at"?s.created_at:s.published_date,r=m==="created_at"?t.created_at:t.published_date;if(!a&&!r)return 0;if(!a)return 1;if(!r)return-1;const n=new Date(a).getTime(),g=new Date(r).getTime();return te==="desc"?g-n:n-g}),ne=()=>{c.length===u.length?b([]):b(u.map(s=>s.id))},ce=s=>{b(t=>t.includes(s)?t.filter(a=>a!==s):[...t,s])},de=s=>{const t=G[s];return(t==null?void 0:t.full_name)||"Anonymous"};return S||W?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx("div",{className:"animate-pulse text-muted-foreground",children:"Loading..."})}):e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx(ge,{title:"Blog Management",description:"Manage your blog posts"}),e.jsx(je,{}),e.jsx("main",{className:"flex-1 py-12",children:e.jsxs("div",{className:"container mx-auto px-4 lg:px-8",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Blog Management"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(_,{to:"/admin/images",children:e.jsxs(j,{variant:"outline",children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),"Image Library"]})}),e.jsx(_,{to:"/admin/blog/new",children:e.jsxs(j,{variant:"hero",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),"New Post"]})})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 mb-6",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ye,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(pe,{placeholder:"Search posts...",value:T,onChange:s=>X(s.target.value),className:"pl-10"})]}),e.jsxs(V,{value:y,onValueChange:ee,children:[e.jsx(H,{className:"w-full sm:w-[180px]",children:e.jsx(we,{placeholder:"Filter by status"})}),e.jsxs(O,{children:[e.jsx(h,{value:"all",children:"All"}),e.jsx(h,{value:"draft",children:"Drafts"}),e.jsx(h,{value:"published",children:"Published"}),e.jsx(h,{value:"archived",children:"Archived"})]})]})]}),c.length>0&&e.jsxs("div",{className:"mb-4 p-4 bg-muted rounded-lg flex items-center justify-between",children:[e.jsxs("span",{children:[c.length," posts selected"]}),e.jsxs(B,{children:[e.jsx(E,{asChild:!0,children:e.jsxs(j,{variant:"destructive",size:"sm",children:[e.jsx(Y,{className:"mr-2 h-4 w-4"}),"Delete Selected"]})}),e.jsxs(M,{children:[e.jsxs(L,{children:[e.jsxs(I,{children:["Delete ",c.length," posts?"]}),e.jsx(F,{children:"This action cannot be undone. These posts will be permanently deleted."})]}),e.jsxs(z,{children:[e.jsx($,{children:"Cancel"}),e.jsx(q,{onClick:le,children:"Delete"})]})]})]})]}),e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(ve,{children:[e.jsx(be,{children:e.jsxs(A,{children:[e.jsx(o,{className:"w-12",children:e.jsx(Q,{checked:c.length===u.length&&u.length>0,onCheckedChange:ne})}),e.jsx(o,{children:"Title"}),e.jsx(o,{children:"Author"}),e.jsx(o,{children:"Status"}),e.jsx(o,{children:e.jsxs("button",{className:`flex items-center gap-1 hover:text-accent ${m==="created_at"?"text-accent":""}`,onClick:()=>k("created_at"),children:["Created",e.jsx(R,{className:"h-4 w-4"})]})}),e.jsx(o,{children:e.jsxs("button",{className:`flex items-center gap-1 hover:text-accent ${m==="published_date"?"text-accent":""}`,onClick:()=>
6k("published_date"),children:["Published",e.jsx(R,{className:"h-4 w-4"})]})}),e.jsx(o,{className:"text-right",children:"Actions"})]})}),e.jsx(Ne,{children:u.length===0?e.jsx(A,{children:e.jsx(d,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"No posts found"})}):u.map(s=>e.jsxs(A,{children:[e.jsx(d,{children:e.jsx(Q,{checked:c.includes(s.id),onCheckedChange:()=>ce(s.id)})}),e.jsx(d,{className:"font-medium max-w-[200px] truncate",children:s.title}),e.jsx(d,{className:"text-muted-foreground",children:de(s.author_id)}),e.jsx(d,{children:e.jsxs(V,{value:s.status,onValueChange:t=>re(s.id,t),children:[e.jsx(H,{className:"w-[130px] h-8",children:ie(s.status)}),e.jsxs(O,{children:[e.jsx(h,{value:"draft",children:"Draft"}),e.jsx(h,{value:"published",children:"Published"}),e.jsx(h,{value:"archived",children:"Archived"})]})]})}),e.jsx(d,{className:"text-muted-foreground",children:K(new Date(s.created_at),"MMM d, yyyy")}),e.jsx(d,{className:"text-muted-foreground",children:s.published_date?K(new Date(s.published_date),"MMM d, yyyy"):"â"}),e.jsx(d,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(_,{to:`/admin/blog/edit/${s.id}`,children:e.jsx(j,{variant:"ghost",size:"icon",children:e.jsx(_e,{className:"h-4 w-4"})})}),e.jsxs(B,{children:[e.jsx(E,{asChild:!0,children:e.jsx(j,{variant:"ghost",size:"icon",children:e.jsx(Y,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(M,{children:[e.jsxs(L,{children:[e.jsx(I,{children:"Delete post?"}),e.jsx(F,{children:"This action cannot be undone. This post will be permanently deleted."})]}),e.jsxs(z,{children:[e.jsx($,{children:"Cancel"}),e.jsx(q,{onClick:()=>ae(s.id),children:"Delete"})]})]})]})]})})]},s.id))})]})})]})}),e.jsx(fe,{})]})};export{qe 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.