import{_ as I}from"./B4vThZpn.js";import{_ as T}from"./CSlxKmMR.js";import{u as A,q as D,c as i,a as e,t as a,e as M,d as V,F as C,r as w,f as E,g as p,h as b,b as g,v as G,i as S,l as f,k as j,o as d}from"./BKiFavna.js";import{u as q}from"./BZ7f31ti.js";import{u as F}from"./DKzHUNYh.js";import{_ as O}from"./DlAUqK2U.js";const L={class:"page-head"},R={class:"page-hdr"},z={class:"table-wrap"},H={class:"ad-table"},J={class:"actions"},K=["onClick"],P=["onClick"],Q={class:"modal"},W={class:"modal-header"},X={style:{margin:"0"}},Y={class:"form-group"},Z={class:"form-group"},ee={class:"form-group"},te={class:"form-group"},le={class:"form-group"},se={style:{flex:"1"}},ne=["onUpdate:modelValue"],oe=["onClick"],ae={class:"ck"},ie={class:"modal-actions"},de=["disabled"],re={__name:"galleries",setup(ue){const{lang:N}=A(),{api:r}=q(),_=F(),y=f([]),o=f(!1),u=f(!1),s=j({id:null,title_bn:"",title_en:"",cover_image:"",description_bn:"",images:[],is_active:!0}),v=async()=>{try{const n=await r.get("/galleries");y.value=n.data.galleries}catch{}},x=()=>{Object.assign(s,{id:null,title_bn:"",title_en:"",cover_image:"",description_bn:"",images:[],is_active:!0}),o.value=!0},U=async n=>{try{const t=await r.get(`/galleries/${n.slug}`);Object.assign(s,t.data.gallery),s.is_active=!!n.is_active}catch{}o.value=!0},$=async()=>{u.value=!0;const n={...s,is_active:s.is_active?1:0};try{s.id?await r.put(`/admin/galleries/${s.id}`,n):await r.post("/admin/galleries",n),o.value=!1,v(),_.success(s.id?"Updated!":"Created!")}catch(t){_.error(t.message)}finally{u.value=!1}},h=async n=>{confirm("Delete?")&&(await r.del(`/admin/galleries/${n.id}`),v(),_.success("Deleted"))};return D(v),(n,t)=>{const k=I,B=T;return d(),i("div",null,[e("div",L,[e("h1",R,a(M(N)==="bn"?"গ্যালারি":"Galleries"),1),e("button",{onClick:x,class:"btn-primary"},[...t[9]||(t[9]=[e("i",{class:"fas fa-plus"},null,-1),V(" New",-1)])])]),e("div",z,[e("table",H,[t[12]||(t[12]=e("thead",null,[e("tr",null,[e("th",null,"Title (BN)"),e("th",null,"Images"),e("th",null,"Views"),e("th",null,"Active"),e("th",null,"Actions")])],-1)),e("tbody",null,[(d(!0),i(C,null,w(y.value,l=>(d(),i("tr",{key:l.id},[e("td",null,[e("strong",null,a(l.title_bn),1)]),e("td",null,a(l.image_count||0),1),e("td",null,a(l.views),1),e("td",null,a(l.is_active?"✓":"×"),1),e("td",J,[e("button",{onClick:c=>U(l),class:"btn-icon"},[...t[10]||(t[10]=[e("i",{class:"fas fa-edit"},null,-1)])],8,K),e("button",{onClick:c=>h(l),class:"btn-icon danger"},[...t[11]||(t[11]=[e("i",{class:"fas fa-trash"},null,-1)])],8,P)])]))),128))])])]),o.value?(d(),i("div",{key:0,class:"modal-backdrop",onClick:t[8]||(t[8]=E(l=>o.value=!1,["self"]))},[e("div",Q,[e("div",W,[e("h3",X,a(s.id?"Edit":"New")+" Gallery",1),e("button",{class:"modal-close",onClick:t[0]||(t[0]=l=>o.value=!1),title:"Close"},"×")]),e("div",Y,[t[13]||(t[13]=e("label",null,"Title (BN) *",-1)),p(e("input",{"onUpdate:modelValue":t[1]||(t[1]=l=>s.title_bn=l),required:""},null,512),[[b,s.title_bn]])]),e("div",Z,[t[14]||(t[14]=e("label",null,"Title (EN)",-1)),p(e("input",{"onUpdate:modelValue":t[2]||(t[2]=l=>s.title_en=l)},null,512),[[b,s.title_en]])]),e("div",ee,[t[15]||(t[15]=e("label",null,"Cover Image",-1)),g(k,{modelValue:s.cover_image,"onUpdate:modelValue":t[3]||(t[3]=l=>s.cover_image=l),endpoint:"/admin/upload/gallery"},null,8,["modelValue"])]),e("div",te,[t[16]||(t[16]=e("label",null,"Description (BN)",-1)),g(B,{modelValue:s.description_bn,"onUpdate:modelValue":t[4]||(t[4]=l=>s.description_bn=l)},null,8,["modelValue"])]),e("div",le,[t[17]||(t[17]=e("label",null,"Gallery Images",-1)),(d(!0),i(C,null,w(s.images,(l,c)=>(d(),i("div",{key:c,class:"img-row"},[e("div",se,[g(k,{modelValue:l.image_url,"onUpdate:modelValue":m=>l.image_url=m,endpoint:"/admin/upload/gallery"},null,8,["modelValue","onUpdate:modelValue"]),p(e("input",{"onUpdate:modelValue":m=>l.caption_bn=m,placeholder:"Caption (BN)",style:{"margin-top":"4px"}},null,8,ne),[[b,l.caption_bn]])]),e("button",{type:"button",onClick:m=>s.images.splice(c,1),class:"btn-del"},"×",8,oe)]))),128)),e("button",{type:"button",onClick:t[5]||(t[5]=l=>s.images.push({image_url:"",caption_bn:"",caption_en:""})),class:"btn-add"},"+ Add Image")]),e("label",ae,[p(e("input",{type:"checkbox","onUpdate:modelValue":t[6]||(t[6]=l=>s.is_active=l)},null,512),[[G,s.is_active]]),t[18]||(t[18]=V(" Active",-1))]),e("div",ie,[e("button",{onClick:t[7]||(t[7]=l=>o.value=!1),class:"btn-secondary"},"Cancel"),e("button",{onClick:$,disabled:u.value,class:"btn-primary"},a(u.value?"Saving...":"Save"),9,de)])])])):S("",!0)])}}},ge=O(re,[["__scopeId","data-v-2c91eb5c"]]);export{ge as default};
