import{jsxs as t,jsx as e}from"react/jsx-runtime";import{A as u,a as f,b as v,c as N,d as b,e as C,f as w,g as A}from"./alert-dialog-xorwy8s8.js";import{B as h}from"./badge-CFi7bqqA.js";import{B as l}from"./button-BvFBRYHq.js";import{C as k,b as B,c as I,a as j}from"./card-Zg0WOx-j.js";import{T as z,a as H,b as m,c as n,d as P,e as i}from"./table-BrXe3s2z.js";import{A as E}from"./layout-CssQHtfO.js";import{Head as L,Link as x,router as g}from"@inertiajs/react";import{Plus as M,EyeOff as O,Eye as R,Edit as F,Trash2 as U,ChevronLeft as $,ChevronRight as q}from"lucide-react";import{useState as T}from"react";import"@radix-ui/react-alert-dialog";import"./utils-CMbmcP35.js";import"clsx";import"tailwind-merge";import"@radix-ui/react-slot";import"class-variance-authority";import"./app-sidebar-header-BX2s-HO_.js";import"@radix-ui/react-collapsible";import"./dropdown-menu-BP80qPHw.js";import"@radix-ui/react-dropdown-menu";import"./app-logo-icon-beRg1XGs.js";import"./fonts-CqawFh47.js";import"@radix-ui/react-dialog";import"@radix-ui/react-tooltip";import"@radix-ui/react-avatar";import"../app.js";/* empty css     */import"axios";import"sonner";import"react-dom/client";import"./toaster-DuLpwsc2.js";const G=[{title:"Admin",href:"/admin"},{title:"News Management",href:"/admin/news"}];function Te({news:r}){const[s,o]=T(null),[c,d]=T(null),_=()=>{s&&g.delete(route("admin.news.destroy",s),{onSuccess:()=>{o(null)}})},y=()=>{c&&g.post(route("admin.news.toggle",c),{},{onSuccess:()=>{d(null)}})},D=a=>e(h,{className:{patch:"bg-blue-500",download:"bg-green-500",promo:"bg-purple-500"}[a],children:a.toUpperCase()}),S=()=>r.data.find(a=>a.id===c),p=a=>{g.get(route("admin.news.index"),{page:a},{preserveState:!0,preserveScroll:!0})};return t(E,{breadcrumbs:G,children:[e(L,{title:"News Management"}),t("div",{className:"space-y-6",children:[t(k,{children:[t(B,{className:"flex flex-row items-center justify-between",children:[e(I,{children:"News Management"}),e(x,{href:route("admin.news.create"),children:t(l,{children:[e(M,{className:"h-4 w-4"}),e("span",{className:"ml-2 hidden md:inline",children:"Add News"})]})})]}),t(j,{children:[t(z,{children:[e(H,{children:t(m,{children:[e(n,{children:"Title"}),e(n,{children:"Category"}),e(n,{children:"Image"}),e(n,{children:"Status"}),e(n,{children:"Created At"}),e(n,{children:"Actions"})]})}),t(P,{children:[r.data.map(a=>t(m,{children:[e(i,{className:"font-medium",children:a.title}),e(i,{children:D(a.category)}),e(i,{children:a.image?e("img",{src:`/storage/${a.image}`,alt:a.title,className:"h-16 w-16 rounded object-cover"}):e("span",{className:"text-gray-400",children:"No image"})}),e(i,{children:a.is_active?e(h,{className:"bg-green-500",children:"Active"}):e(h,{className:"bg-gray-500",children:"Inactive"})}),e(i,{children:new Date(a.created_at).toLocaleDateString()}),e(i,{children:t("div",{className:"flex gap-2",children:[e(l,{size:"sm",variant:"outline",onClick:()=>d(a.id),title:a.is_active?"Deactivate":"Activate",children:a.is_active?e(O,{className:"h-4 w-4"}):e(R,{className:"h-4 w-4"})}),e(x,{href:route("admin.news.edit",a.id),children:e(l,{size:"sm",variant:"outline",title:"Edit",children:e(F,{className:"h-4 w-4"})})}),e(l,{size:"sm",variant:"destructive",onClick:()=>o(a.id),title:"Delete",children:e(U,{className:"h-4 w-4"})})]})})]},a.id)),r.data.length===0&&e(m,{children:e(i,{colSpan:6,className:"text-center text-gray-400",children:'No news available. Click "Add News" to create one.'})})]})]}),r.last_page>1&&t("div",{className:"flex items-center justify-between px-2 py-4",children:[t("div",{className:"text-muted-foreground text-sm",children:["Showing ",(r.current_page-1)*r.per_page+1," to ",Math.min(r.current_page*r.per_page,r.total)," ","of ",r.total," results"]}),t("div",{className:"flex items-center space-x-2",children:[t(l,{variant:"outline",size:"sm",onClick:()=>p(r.current_page-1),disabled:r.current_page===1,children:[e($,{className:"h-4 w-4"}),"Previous"]}),t("div",{className:"text-sm",children:["Page ",r.current_page," of ",r.last_page]}),t(l,{variant:"outline",size:"sm",onClick:()=>p(r.current_page+1),disabled:r.current_page===r.last_page,children:["Next",e(q,{className:"h-4 w-4"})]})]})]})]})]}),e(u,{open:s!==null,onOpenChange:()=>o(null),children:t(f,{children:[t(v,{children:[e(N,{children:"Are you sure?"}),e(b,{children:"This action cannot be undone. This will permanently delete this news article."})]}),t(C,{children:[e(w,{children:"Cancel"}),e(A,{onClick:_,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})}),e(u,{open:c!==null,onOpenChange:()=>d(null),children:t(f,{children:[t(v,{children:[e(N,{children:"Change News Status"}),e(b,{children:S()?.is_active?"This will deactivate the news article and hide it from public view.":"This will activate the news article and make it visible to public."})]}),t(C,{children:[e(w,{children:"Cancel"}),e(A,{onClick:y,children:"Confirm"})]})]})})]})]})}export{Te as default};
