1import{l as T,n as E,r as x,j as e,L as N}from"./index-C-ndh74e.js";import{A as P}from"./AdminLayout-Sh9T0FYh.js";import{C as B,a as L}from"./card-DYmeyKjy.js";import{B as m}from"./button-B0NR-1vM.js";import{B as q}from"./badge-BquJ34Gp.js";import{I}from"./input-CNxwvPfZ.js";import{T as D,a as Q,b as v,c as i,d as $,e as d}from"./table-CYzpQsFL.js";import{u as y,S as z}from"./switch-CMm2Z8s9.js";import{u as K}from"./useQuery-BpaWh3Ln.js";import{R as M,P as R,a as H}from"./refresh-cw-D_CtnDlu.js";import{I as O}from"./image-BdNKzHx9.js";import{E as U}from"./eye-ZGiXLyMI.js";import{T as G}from"./trash-2-CQ2IilcW.js";import"./file-text-C9_b9M4E.js";async function J(){const n=await fetch("/api/admin/press-news",{credentials:"include"});if(!n.ok)throw new Error("Failed to load press news");const a=await n.json();return a&&typeof a=="object"&&"data"in a?a.data:a}function de(){const n=T(),[,a]=E(),[l,C]=x.useState(!1),[j,k]=x.useState("");x.useEffect(()=>{let s=!1;return(async()=>{try{const t=await fetch("/api/admin/me",{credentials:"include"});if(!t.ok){a("/admin/login");return}const r=await t.json();if(!s){if(!r||!r.authenticated){a("/admin/login");return}C(!0)}}catch{s||a("/admin/login")}})(),()=>{s=!0}},[a]);const{data:c,isLoading:o,error:h,refetch:S}=K({queryKey:["admin","press-news"],queryFn:J,enabled:l}),b=y({mutationFn:async({id:s,status:t})=>{const r=await fetch(`/api/admin/press-news/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({status:t})});if(!r.ok){const g=await r.text();throw new Error(g||"Failed to update status")}return r.json()},onSuccess:()=>{n.invalidateQueries({queryKey:["admin","press-news"]}),n.invalidateQueries({queryKey:["press-news"]})}}),p=y({mutationFn:async s=>{const t=await fetch(`/api/admin/press-news/${s}`,{method:"DELETE",credentials:"include"});if(!t.ok){const r=await t.text();throw new Error(r||"Failed to delete press news")}return t.json()},onSuccess:()=>{n.invalidateQueries({queryKey:["admin","press-news"]}),n.invalidateQueries({queryKey:["press-news"]})}}),u=j.trim().toLowerCase(),w=!!c&&c.length>0,f=x.useMemo(()=>c?u?c.filter(s=>[s.id.toString(),s.name,s.url,s.badge].filter(Boolean).join(" ").toLowerCase().includes(u)):c:[],[u,c]),A=x.useCallback((s,t)=>{b.mutate({id:s.id,status:t})},[b]),F=x.useCallback(s=>{window.confirm(`Delete "${s.name}"? This cannot be undone.`)&&p.mutate(s.id)},[p]);return e.jsx(P,{children:e.jsxs("section",{className:"pt-20 pb-10 px-4 sm:px-6 md:px-8 lg:px-12",children:[e.jsxs("div",{className:"w-full flex items-start justify-between mb-6 gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx(q,{className:"mb-3 bg-[#e0ecff] text-[#1d4ed8] border-[#bfdbfe] px-4 py-1 text-xs uppercase",children:"Admin · Press Room"}),e.jsx("h1",{className:"text-2xl md:text-3xl font-black text-[#0f172a] tracking-tight mb-1",children:"Press News Coverage"}),e.jsx("p",{className:"text-xs md:text-sm text-[#4b5563] max-w-xl",children:"Manage publisher logos, links, and badges for IG Defence in the News."})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(I,{type:"text",placeholder:"Search coverage...",value:j,onChange:s=>k(s.target.value),className:"w-48 md:w-64 bg-[#020617] border-[#1F2937] text-[#F9FAFB] text-xs"}),e.jsx(m,{type:"button",variant:"outline",size:"icon",className:"border-[#cbd5f5] bg-transparent text-[#1f2937] hover:bg-[#eff6ff]",onClick:()=>S(),disabled:o,children:e.jsx(M,{className:"w-4 h-4"})}),e.jsx(N,{href:"/admin/press-news/new",children:e.jsxs(m,{type:"button",className:"bg-[#1d4ed8] hover:bg-[#1e40af] text-white flex items-center gap-2",children:[e.jsx(R,{className:"w-4 h-4"}),"New Coverage"]})})]})]}),e.jsx(B,{className:"w-full bg-transparent border border-[#e5e7eb] rounded-xl",children:e.jsxs(L,{className:"p-4 md:p-6",children:[!l&&e.jsx("p",{className:"text-sm text-[#6b7280]",children:"Checking admin session..."}),l&&o&&e.jsx("p",{className:"text-sm text-[#6b7280]",children:"Loading coverage..."}),l&&h&&!o&&e.jsx("p",{className:"text-sm text-red-400",children:"Failed to load press news coverage."}),l&&!o&&!h&&!w&&e.jsx("p",{className:"text-sm text-[#6b7280]",children:"No coverage items found yet."}),l&&!o&&!h&&w&&u&&f.length===0&&e.jsx("p",{className:"text-sm text-[#6b7280]",children:"No coverage matches your search."}),l&&!o&&!h&&f.length>0&&e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(D,{className:"min-w-full text-[#0f172a]",children:[e.jsx(Q,{children:e.jsxs(v,{children:[e.jsx(i,{className:"w-12 text-center text-xs text-[#6b7280]",children:"ID"}),e.jsx(i,{className:"text-xs text-[#6b7280]",children:"Coverage"}),e.jsx(i,{className:"hidden lg:table-cell text-xs text-[#6b7280]",children:"Badge"}),e.jsx(i,{className:"hidden md:table-cell text-xs text-[#6b7280]",children:"Sort"}),e.jsx(i,{className:"text-xs text-[#6b7280]",children:"Status"}),e.jsx(i,{className:"hidden md:table-cell text-xs text-[#6b7280]",children:"Updated"}),e.jsx(i,{className:"w-32 text-xs text-[#6b7280] text-right",children:"Actions"})]})}),e.jsx($,{children:f.map(s=>{const t=s.status===1,r=s.updatedAt?new Date(s.updatedAt).toLocaleStr
1ing():"";return e.jsxs(v,{className:"border-[#d1d5db] hover:bg-black/5",children:[e.jsx(d,{className:"align-middle text-center text-xs text-[#6b7280]",children:s.id}),e.jsx(d,{className:"align-middle",children:e.jsxs("div",{className:"flex items-center gap-3",children:[s.image?e.jsx("img",{src:s.image,alt:s.name,className:"h-10 w-14 rounded-lg border border-[#e5e7eb] object-cover"}):e.jsx("span",{className:"h-10 w-14 rounded-lg border border-[#e5e7eb] bg-[#f8fafc] flex items-center justify-center",children:e.jsx(O,{className:"h-4 w-4 text-[#64748b]"})}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm text-[#111827] line-clamp-1",children:s.name}),e.jsx("span",{className:"text-[11px] text-[#6B7280] line-clamp-1",children:s.url})]})]})}),e.jsx(d,{className:"hidden lg:table-cell align-middle text-xs text-[#6b7280]",children:s.badge||"-"}),e.jsx(d,{className:"hidden md:table-cell align-middle text-xs text-[#6b7280]",children:s.sortOrder??0}),e.jsx(d,{className:"align-middle",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{checked:t,onCheckedChange:g=>A(s,g),disabled:b.isPending}),e.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium border ${t?"bg-emerald-50 text-emerald-700 border-emerald-200":"bg-red-50 text-red-700 border-red-200"}`,children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${t?"bg-emerald-500":"bg-red-500"}`}),t?"Active":"Inactive"]})]})}),e.jsx(d,{className:"hidden md:table-cell align-middle text-xs text-[#6b7280]",children:r}),e.jsx(d,{className:"align-middle text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(m,{asChild:!0,type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 text-[#6b7280] hover:text-[#111827] hover:bg-[#e5e7eb]",children:e.jsx("a",{href:s.url,target:"_blank",rel:"noreferrer",children:e.jsx(U,{className:"w-3 h-3"})})}),e.jsx(N,{href:`/admin/press-news/${s.id}`,children:e.jsx(m,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 text-[#9CA3AF] hover:text-[#F9FAFB] hover:bg-[#111827]",children:e.jsx(H,{className:"w-3 h-3"})})}),e.jsx(m,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 text-[#ef4444] hover:text-white hover:bg-[#ef4444]",onClick:()=>F(s),disabled:p.isPending,children:e.jsx(G,{className:"w-3 h-3"})})]})})]},s.id)})})]})})]})})]})})}export{de 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.