import{_ as x}from"./B4vThZpn.js";import{u as N,q as A,c as p,a as t,t as n,e as D,d as b,F as M,r as $,f as I,g as a,h as d,j as T,b as S,v as L,i as h,l as _,k as j,o as m}from"./BKiFavna.js";import{u as B}from"./BZ7f31ti.js";import{u as E}from"./DKzHUNYh.js";import{_ as q}from"./DlAUqK2U.js";const F={class:"page-head"},O={class:"page-hdr"},P={class:"table-wrap"},H={class:"ad-table"},R={class:"tag"},z={class:"actions"},G=["onClick"],J=["onClick"],K={class:"modal"},Q={class:"modal-header"},W={style:{margin:"0"}},X={class:"form-group"},Y={class:"form-group"},Z={class:"form-group"},tt={class:"form-group"},st={class:"form-group"},lt={class:"form-row"},et={class:"form-group"},ot={class:"form-group"},nt={class:"ck"},it={class:"modal-actions"},at=["disabled"],dt={__name:"ads",setup(ut){const{lang:g}=N(),{api:u}=B(),v=E(),f=_([]),i=_(!1),r=_(!1),e=j({id:null,title:"",position:"sidebar",image:"",link_url:"",html_code:"",start_date:"",end_date:"",is_active:!0}),c=async()=>{try{const o=await u.get("/admin/ads");f.value=o.data.ads}catch{}},k=()=>{Object.assign(e,{id:null,title:"",position:"sidebar",image:"",link_url:"",html_code:"",start_date:"",end_date:"",is_active:!0}),i.value=!0},y=o=>{Object.assign(e,o),e.is_active=!!o.is_active,i.value=!0},w=async()=>{r.value=!0;const o={...e,is_active:e.is_active?1:0};try{e.id?await u.put(`/admin/ads/${e.id}`,o):await u.post("/admin/ads",o),i.value=!1,c(),v.success(e.id?"Updated!":"Created!")}catch(s){v.error(s.message)}finally{r.value=!1}},C=async o=>{confirm("Delete?")&&(await u.del(`/admin/ads/${o.id}`),c(),v.success("Deleted"))};return A(c),(o,s)=>{const V=x;return m(),p("div",null,[t("div",F,[t("h1",O,n(D(g)==="bn"?"বিজ্ঞাপন":"Advertisements"),1),t("button",{onClick:k,class:"btn-primary"},[...s[11]||(s[11]=[t("i",{class:"fas fa-plus"},null,-1),b(" New Ad",-1)])])]),t("div",P,[t("table",H,[s[14]||(s[14]=t("thead",null,[t("tr",null,[t("th",null,"ID"),t("th",null,"Title"),t("th",null,"Position"),t("th",null,"Impressions"),t("th",null,"Clicks"),t("th",null,"Active"),t("th",null,"Actions")])],-1)),t("tbody",null,[(m(!0),p(M,null,$(f.value,l=>(m(),p("tr",{key:l.id},[t("td",null,n(l.id),1),t("td",null,[t("strong",null,n(l.title),1)]),t("td",null,[t("span",R,n(l.position),1)]),t("td",null,n(l.impressions||0),1),t("td",null,n(l.clicks||0),1),t("td",null,n(l.is_active?"✓":"×"),1),t("td",z,[t("button",{onClick:U=>y(l),class:"btn-icon"},[...s[12]||(s[12]=[t("i",{class:"fas fa-edit"},null,-1)])],8,G),t("button",{onClick:U=>C(l),class:"btn-icon danger"},[...s[13]||(s[13]=[t("i",{class:"fas fa-trash"},null,-1)])],8,J)])]))),128))])])]),i.value?(m(),p("div",{key:0,class:"modal-backdrop",onClick:s[10]||(s[10]=I(l=>i.value=!1,["self"]))},[t("div",K,[t("div",Q,[t("h3",W,n(e.id?"Edit":"New")+" Ad",1),t("button",{class:"modal-close",onClick:s[0]||(s[0]=l=>i.value=!1),title:"Close"},"×")]),t("div",X,[s[15]||(s[15]=t("label",null,"Title *",-1)),a(t("input",{"onUpdate:modelValue":s[1]||(s[1]=l=>e.title=l),required:""},null,512),[[d,e.title]])]),t("div",Y,[s[17]||(s[17]=t("label",null,"Position *",-1)),a(t("select",{"onUpdate:modelValue":s[2]||(s[2]=l=>e.position=l)},[...s[16]||(s[16]=[t("option",null,"header",-1),t("option",null,"sidebar",-1),t("option",null,"footer",-1),t("option",null,"below_post",-1),t("option",null,"above_post",-1),t("option",null,"between_posts",-1),t("option",null,"popup",-1),t("option",null,"donation_banner",-1)])],512),[[T,e.position]])]),t("div",Z,[s[18]||(s[18]=t("label",null,"Image",-1)),S(V,{modelValue:e.image,"onUpdate:modelValue":s[3]||(s[3]=l=>e.image=l),endpoint:"/admin/upload/ad"},null,8,["modelValue"])]),t("div",tt,[s[19]||(s[19]=t("label",null,"Link URL",-1)),a(t("input",{"onUpdate:modelValue":s[4]||(s[4]=l=>e.link_url=l)},null,512),[[d,e.link_url]])]),t("div",st,[s[20]||(s[20]=t("label",null,"HTML Code (optional)",-1)),a(t("textarea",{"onUpdate:modelValue":s[5]||(s[5]=l=>e.html_code=l),rows:"4"},null,512),[[d,e.html_code]])]),t("div",lt,[t("div",et,[s[21]||(s[21]=t("label",null,"Start Date",-1)),a(t("input",{type:"date","onUpdate:modelValue":s[6]||(s[6]=l=>e.start_date=l)},null,512),[[d,e.start_date]])]),t("div",ot,[s[22]||(s[22]=t("label",null,"End Date",-1)),a(t("input",{type:"date","onUpdate:modelValue":s[7]||(s[7]=l=>e.end_date=l)},null,512),[[d,e.end_date]])])]),t("label",nt,[a(t("input",{type:"checkbox","onUpdate:modelValue":s[8]||(s[8]=l=>e.is_active=l)},null,512),[[L,e.is_active]]),s[23]||(s[23]=b(" Active",-1))]),t("div",it,[t("button",{onClick:s[9]||(s[9]=l=>i.value=!1),class:"btn-secondary"},"Cancel"),t("button",{onClick:w,disabled:r.value,class:"btn-primary"},n(r.value?"Saving...":"Save"),9,at)])])])):h("",!0)])}}},_t=q(dt,[["__scopeId","data-v-883727e5"]]);export{_t as default};
