import{_ as N}from"./DxB0DKYp.js";import{u as V,q as $,c as r,a as t,t as a,e as i,b as g,w as _,g as k,j as S,h as P,x as A,F as I,r as L,i as M,k as T,l as p,m as B,o as c,d as U,n as E}from"./BKiFavna.js";import{u as F}from"./BZ7f31ti.js";import{u as K}from"./DKzHUNYh.js";import{_ as j}from"./DlAUqK2U.js";const q={class:"page-head"},z={class:"page-hdr"},R={class:"filter-bar"},G={value:""},H=["placeholder"],J={class:"table-wrap"},O={key:0,class:"ad-table"},Q={class:"actions"},W=["onClick"],X={key:1,class:"empty"},Y={key:0,class:"pagination"},Z=["disabled"],tt=["disabled"],x=20,st={__name:"index",setup(et){const{lang:n}=V(),{api:h}=F(),y=K(),f=p([]),d=p(1),w=p(0),m=p(!1),o=T({status:"",search:""}),v=B(()=>Math.ceil(w.value/x)),u=async()=>{m.value=!0;try{const l={page:d.value,limit:x};o.status&&(l.status=o.status),o.search&&(l.search=o.search);const s=await h.get("/admin/posts",l);f.value=s.data.posts,w.value=s.meta.total}catch(l){console.error(l)}finally{m.value=!1}},D=async l=>{if(confirm(`Delete "${l.title_bn}"?`))try{await h.del(`/admin/posts/${l.id}`),u(),y.success("Deleted")}catch(s){y.error(s.message)}},C=l=>l?new Date(l).toLocaleDateString():"";return $(u),(l,s)=>{const b=N;return c(),r("div",null,[t("div",q,[t("h1",z,a(i(n)==="bn"?"পোস্টসমূহ":"Posts"),1),g(b,{to:"/admin/posts/new",class:"btn-primary"},{default:_(()=>[s[4]||(s[4]=t("i",{class:"fas fa-plus"},null,-1)),U(" "+a(i(n)==="bn"?"নতুন পোস্ট":"New Post"),1)]),_:1})]),t("div",R,[k(t("select",{"onUpdate:modelValue":s[0]||(s[0]=e=>o.status=e),onChange:u},[t("option",G,a(i(n)==="bn"?"সব স্ট্যাটাস":"All Status"),1),s[5]||(s[5]=t("option",{value:"published"},"Published",-1)),s[6]||(s[6]=t("option",{value:"draft"},"Draft",-1)),s[7]||(s[7]=t("option",{value:"scheduled"},"Scheduled",-1)),s[8]||(s[8]=t("option",{value:"archived"},"Archived",-1))],544),[[S,o.status]]),k(t("input",{"onUpdate:modelValue":s[1]||(s[1]=e=>o.search=e),onKeyup:A(u,["enter"]),placeholder:i(n)==="bn"?"খুঁজুন...":"Search..."},null,40,H),[[P,o.search]]),t("button",{onClick:u,class:"btn-primary"},[...s[9]||(s[9]=[t("i",{class:"fas fa-search"},null,-1)])])]),t("div",J,[f.value.length?(c(),r("table",O,[t("thead",null,[t("tr",null,[s[10]||(s[10]=t("th",null,"ID",-1)),t("th",null,a(i(n)==="bn"?"শিরোনাম":"Title"),1),t("th",null,a(i(n)==="bn"?"ক্যাটাগরি":"Category"),1),s[11]||(s[11]=t("th",null,"Status",-1)),s[12]||(s[12]=t("th",null,"Views",-1)),s[13]||(s[13]=t("th",null,"Date",-1)),t("th",null,a(i(n)==="bn"?"অ্যাকশন":"Actions"),1)])]),t("tbody",null,[(c(!0),r(I,null,L(f.value,e=>(c(),r("tr",{key:e.id},[t("td",null,a(e.id),1),t("td",null,[t("strong",null,a(e.title_bn),1)]),t("td",null,a(e.category_name_bn),1),t("td",null,[t("span",{class:E(`badge badge-${e.status}`)},a(e.status),3)]),t("td",null,a(e.views),1),t("td",null,a(C(e.published_at||e.created_at)),1),t("td",Q,[g(b,{to:`/admin/posts/${e.id}`,class:"btn-icon",title:"Edit"},{default:_(()=>[...s[14]||(s[14]=[t("i",{class:"fas fa-edit"},null,-1)])]),_:1},8,["to"]),g(b,{to:`/news/${encodeURIComponent(e.slug_bn)}`,target:"_blank",class:"btn-icon",title:"View"},{default:_(()=>[...s[15]||(s[15]=[t("i",{class:"fas fa-eye"},null,-1)])]),_:1},8,["to"]),t("button",{onClick:at=>D(e),class:"btn-icon danger",title:"Delete"},[...s[16]||(s[16]=[t("i",{class:"fas fa-trash"},null,-1)])],8,W)])]))),128))])])):(c(),r("p",X,a(m.value?"Loading...":i(n)==="bn"?"কোনো পোস্ট নেই":"No posts found"),1))]),v.value>1?(c(),r("div",Y,[t("button",{onClick:s[2]||(s[2]=e=>{d.value--,u()}),disabled:d.value<=1},"« Prev",8,Z),t("span",null,"Page "+a(d.value)+" / "+a(v.value),1),t("button",{onClick:s[3]||(s[3]=e=>{d.value++,u()}),disabled:d.value>=v.value},"Next »",8,tt)])):M("",!0)])}}},dt=j(st,[["__scopeId","data-v-0cf558e2"]]);export{dt as default};
