import{r as a,d as C,t as h,j as e,H as T,g as N,cg as _,S as L,cJ as I,ae as M,af as k}from"./vendor-laZsiqLO.js";import{A}from"./AdminLayout-Cg-VwQ1I.js";import{B as d}from"./button-B8f8jW4H.js";import{B}from"./badge-CJ9RzXvO.js";import{I as E}from"./input-CT5MkJwj.js";import{T as H,a as O,b as c,c as r,d as $,e as t}from"./table-D7zRN5YZ.js";import{D as z,a as F,b as Q,c as b}from"./dropdown-menu-CpMN0BZ0.js";import{C as R,a as q,b as J,d as U}from"./card-BKDXjfy_.js";import{C as G}from"./ConfirmModal-DLCUZ7vx.js";import"./utils-RgT4yCq8.js";import"./admin-D0dR58a0.js";import"./bootstrap-CBwglqL9.js";/* empty css            */import"./sheet-Cp4V1hdh.js";import"./avatar-1RNhlzAH.js";import"./useFlashMessages-CQoLOBuv.js";function oe(){const[o,w]=a.useState([]),[l,S]=a.useState({}),[m,p]=a.useState(!0),[n,i]=a.useState(1),[u,y]=a.useState(""),[j,g]=a.useState(null),[P,x]=a.useState(!1);a.useEffect(()=>{const s=setTimeout(()=>{f()},300);return()=>clearTimeout(s)},[n,u]);const f=()=>{p(!0),C.get(`/api/admin/pages?page=${n}&search=${u}`).then(s=>{w(s.data.data),S(s.data)}).catch(()=>h.error("Failed to load pages")).finally(()=>p(!1))},v=s=>{g(s),x(!0)},D=async()=>{if(j)try{await C.delete(`/api/admin/pages/${j}`),h.success("Page deleted successfully"),o.length===1&&n>1?i(n-1):f()}catch{h.error("Failed to delete page")}finally{x(!1),g(null)}};return e.jsxs(A,{children:[e.jsx(T,{title:"Custom Pages"}),e.jsx(G,{open:P,onOpenChange:x,onConfirm:D,title:"Delete Page",description:"Are you sure you want to delete this page? This action cannot be undone.",confirmText:"Delete Page",variant:"destructive"}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:"Custom Pages"}),e.jsx("p",{className:"text-muted-foreground",children:"Create and manage static pages."})]}),e.jsx(d,{asChild:!0,children:e.jsxs(N,{href:route("admin.pages.create"),children:[e.jsx(_,{className:"mr-2 h-4 w-4"})," Create Page"]})})]}),e.jsxs(R,{children:[e.jsxs(q,{className:"flex flex-row items-center justify-between border-b pb-4 mb-4",children:[e.jsx(J,{children:"All Pages"}),e.jsxs("div",{className:"relative w-full max-w-sm",children:[e.jsx(L,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search pages...",className:"pl-9",value:u,onChange:s=>{y(s.target.value),i(1)}})]})]}),e.jsxs(U,{children:[e.jsxs(H,{children:[e.jsx(O,{children:e.jsxs(c,{children:[e.jsx(r,{children:"Title"}),e.jsx(r,{children:"Slug"}),e.jsx(r,{children:"Status"}),e.jsx(r,{children:"Last Updated"}),e.jsx(r,{className:"text-right",children:"Actions"})]})}),e.jsx($,{children:m?e.jsx(c,{children:e.jsx(t,{colSpan:5,className:"h-24 text-center",children:"Loading..."})}):o.length===0?e.jsx(c,{children:e.jsx(t,{colSpan:5,className:"h-24 text-center text-muted-foreground",children:"No pages found."})}):o.map(s=>e.jsxs(c,{children:[e.jsx(t,{className:"font-medium",children:s.title}),e.jsxs(t,{className:"text-muted-foreground",children:["/",s.slug]}),e.jsx(t,{children:e.jsx(B,{variant:s.status==="published"?"default":"secondary",children:s.status})}),e.jsx(t,{children:new Date(s.updated_at).toLocaleDateString()}),e.jsx(t,{className:"text-right",children:e.jsxs(z,{children:[e.jsx(F,{asChild:!0,children:e.jsx(d,{variant:"ghost",className:"h-8 w-8 p-0",children:e.jsx(I,{className:"h-4 w-4"})})}),e.jsxs(Q,{align:"end",children:[e.jsx(b,{asChild:!0,children:e.jsxs(N,{href:route("admin.pages.edit",s.id),children:[e.jsx(M,{className:"mr-2 h-4 w-4"})," Edit"]})}),e.jsxs(b,{onClick:()=>v(s.id),className:"text-red-600 focus:text-red-600",children:[e.jsx(k,{className:"mr-2 h-4 w-4"})," Delete"]})]})]})})]},s.id))})]}),e.jsxs("div",{className:"flex items-center justify-end space-x-2 pt-4",children:[e.jsx(d,{variant:"outline",size:"sm",onClick:()=>i(s=>Math.max(1,s-1)),disabled:!l.prev_page_url||m,children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",l.current_page||1," of ",l.last_page||1]}),e.jsx(d,{variant:"outline",size:"sm",onClick:()=>i(s=>s+1),disabled:!l.next_page_url||m,children:"Next"})]})]})]})]})}export{oe as default};
