import{u as x,q as L,c as u,a as e,t as o,e as B,d as k,F as y,r as C,f as I,g as i,h as r,j as S,v as T,i as A,l as p,k as D,o as m,n as E}from"./BKiFavna.js";import{u as O}from"./BZ7f31ti.js";import{u as j}from"./DKzHUNYh.js";import{_ as q}from"./DlAUqK2U.js";const F={class:"page-head"},h={class:"page-hdr"},R={class:"tabs"},z=["onClick"],G={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-row"},Z={class:"form-group"},ee={class:"form-group"},le={class:"form-group"},te={class:"form-row"},se={class:"form-group"},ne={class:"form-group"},oe={class:"form-group"},ae={class:"ck"},ie={class:"modal-actions"},de=["disabled"],ue={__name:"menus",setup(re){const{lang:w}=x(),{api:v}=O(),_=j(),N=[{id:1,name:"Main"},{id:2,name:"Footer"},{id:3,name:"Topbar"}],d=p(1),f=p([]),a=p(!1),c=p(!1),s=D({id:null,menu_id:1,parent_id:null,label_bn:"",label_en:"",url:"",icon:"",target:"_self",sort_order:0,is_active:!0}),b=async()=>{try{const n=await v.get(`/admin/menus/${d.value}/items`);f.value=n.data.items}catch{}},M=()=>{Object.assign(s,{id:null,menu_id:d.value,parent_id:null,label_bn:"",label_en:"",url:"",icon:"",target:"_self",sort_order:0,is_active:!0}),a.value=!0},U=n=>{Object.assign(s,n),s.is_active=!!n.is_active,a.value=!0},V=async()=>{c.value=!0;const n={...s,menu_id:d.value,is_active:s.is_active?1:0};try{s.id?await v.put(`/admin/menu-items/${s.id}`,n):await v.post("/admin/menu-items",n),a.value=!1,b(),_.success(s.id?"Updated!":"Created!")}catch(l){_.error(l.message)}finally{c.value=!1}},$=async n=>{confirm("Delete?")&&(await v.del(`/admin/menu-items/${n.id}`),b(),_.success("Deleted"))};return L(b),(n,l)=>(m(),u("div",null,[e("div",F,[e("h1",h,o(B(w)==="bn"?"মেনু":"Menus"),1),e("button",{onClick:M,class:"btn-primary"},[...l[10]||(l[10]=[e("i",{class:"fas fa-plus"},null,-1),k(" New Item",-1)])])]),e("div",R,[(m(),u(y,null,C(N,t=>e("button",{key:t.id,class:E(["tab",{active:d.value===t.id}]),onClick:g=>{d.value=t.id,b()}},o(t.name),11,z)),64))]),e("div",G,[e("table",H,[l[13]||(l[13]=e("thead",null,[e("tr",null,[e("th",null,"Order"),e("th",null,"Label (BN)"),e("th",null,"Label (EN)"),e("th",null,"URL"),e("th",null,"Active"),e("th",null,"Actions")])],-1)),e("tbody",null,[(m(!0),u(y,null,C(f.value,t=>(m(),u("tr",{key:t.id},[e("td",null,o(t.sort_order),1),e("td",null,[e("strong",null,o(t.label_bn),1)]),e("td",null,o(t.label_en),1),e("td",null,[e("code",null,o(t.url),1)]),e("td",null,o(t.is_active?"✓":"×"),1),e("td",J,[e("button",{onClick:g=>U(t),class:"btn-icon"},[...l[11]||(l[11]=[e("i",{class:"fas fa-edit"},null,-1)])],8,K),e("button",{onClick:g=>$(t),class:"btn-icon danger"},[...l[12]||(l[12]=[e("i",{class:"fas fa-trash"},null,-1)])],8,P)])]))),128))])])]),a.value?(m(),u("div",{key:0,class:"modal-backdrop",onClick:l[9]||(l[9]=I(t=>a.value=!1,["self"]))},[e("div",Q,[e("div",W,[e("h3",X,o(s.id?"Edit":"New")+" Menu Item",1),e("button",{class:"modal-close",onClick:l[0]||(l[0]=t=>a.value=!1),title:"Close"},"×")]),e("div",Y,[e("div",Z,[l[14]||(l[14]=e("label",null,"Label (BN) *",-1)),i(e("input",{"onUpdate:modelValue":l[1]||(l[1]=t=>s.label_bn=t),required:""},null,512),[[r,s.label_bn]])]),e("div",ee,[l[15]||(l[15]=e("label",null,"Label (EN)",-1)),i(e("input",{"onUpdate:modelValue":l[2]||(l[2]=t=>s.label_en=t)},null,512),[[r,s.label_en]])])]),e("div",le,[l[16]||(l[16]=e("label",null,"URL *",-1)),i(e("input",{"onUpdate:modelValue":l[3]||(l[3]=t=>s.url=t),required:""},null,512),[[r,s.url]])]),e("div",te,[e("div",se,[l[17]||(l[17]=e("label",null,"Icon",-1)),i(e("input",{"onUpdate:modelValue":l[4]||(l[4]=t=>s.icon=t)},null,512),[[r,s.icon]])]),e("div",ne,[l[18]||(l[18]=e("label",null,"Sort Order",-1)),i(e("input",{type:"number","onUpdate:modelValue":l[5]||(l[5]=t=>s.sort_order=t)},null,512),[[r,s.sort_order,void 0,{number:!0}]])])]),e("div",oe,[l[20]||(l[20]=e("label",null,"Target",-1)),i(e("select",{"onUpdate:modelValue":l[6]||(l[6]=t=>s.target=t)},[...l[19]||(l[19]=[e("option",null,"_self",-1),e("option",null,"_blank",-1)])],512),[[S,s.target]])]),e("label",ae,[i(e("input",{type:"checkbox","onUpdate:modelValue":l[7]||(l[7]=t=>s.is_active=t)},null,512),[[T,s.is_active]]),l[21]||(l[21]=k(" Active",-1))]),e("div",ie,[e("button",{onClick:l[8]||(l[8]=t=>a.value=!1),class:"btn-secondary"},"Cancel"),e("button",{onClick:V,disabled:c.value,class:"btn-primary"},o(c.value?"Saving...":"Save"),9,de)])])])):A("",!0)]))}},pe=q(ue,[["__scopeId","data-v-2fe103c2"]]);export{pe as default};
