import{u as U,q as x,c as n,a as s,t as d,e as $,d as k,F as g,r as C,i as N,f as B,g as u,h as c,v as D,l as y,k as M,o as l}from"./BKiFavna.js";import{u as O}from"./BZ7f31ti.js";import{u as A}from"./DKzHUNYh.js";import{_ as T}from"./DlAUqK2U.js";const E={class:"page-head"},P={class:"page-hdr"},S={class:"polls-list"},F={class:"poll-meta"},I=["onClick"],Q={key:0,class:"empty"},j={class:"modal"},L={class:"modal-header"},z={class:"form-group"},G={class:"form-group"},H={class:"form-group"},J=["onUpdate:modelValue"],K=["onUpdate:modelValue"],R=["onClick"],W={class:"ck"},X={class:"modal-actions"},Y=["disabled"],Z={__name:"polls",setup(ss){const{lang:q}=U(),{api:v}=O(),_=A(),m=y([]),i=y(!1),p=y(!1),e=M({question_bn:"",question_en:"",options:[{option_bn:"",option_en:""},{option_bn:"",option_en:""}],is_active:!0}),b=async()=>{try{const a=await v.get("/admin/polls");m.value=a.data.polls}catch{}},w=()=>{Object.assign(e,{question_bn:"",question_en:"",options:[{option_bn:"",option_en:""},{option_bn:"",option_en:""}],is_active:!0}),i.value=!0},h=async()=>{p.value=!0;try{await v.post("/admin/polls",{...e,is_active:e.is_active?1:0}),i.value=!1,b(),_.success(e.id?"Updated!":"Created!")}catch(a){_.error(a.message)}finally{p.value=!1}},V=async a=>{confirm("Delete poll?")&&(await v.del(`/admin/polls/${a.id}`),b(),_.success("Deleted"))};return x(b),(a,o)=>(l(),n("div",null,[s("div",E,[s("h1",P,d($(q)==="bn"?"পোল / ভোটিং":"Polls"),1),s("button",{onClick:w,class:"btn-primary"},[...o[7]||(o[7]=[s("i",{class:"fas fa-plus"},null,-1),k(" New Poll",-1)])])]),s("div",S,[(l(!0),n(g,null,C(m.value,t=>(l(),n("div",{key:t.id,class:"poll-card"},[s("h3",null,d(t.question_bn),1),s("div",F,"Total votes: "+d(t.total_votes)+" | Active: "+d(t.is_active?"✓":"×"),1),s("button",{onClick:f=>V(t),class:"btn-icon danger"},[...o[8]||(o[8]=[s("i",{class:"fas fa-trash"},null,-1),k(" Delete",-1)])],8,I)]))),128)),m.value.length?N("",!0):(l(),n("p",Q,"No polls yet"))]),i.value?(l(),n("div",{key:0,class:"modal-backdrop",onClick:o[6]||(o[6]=B(t=>i.value=!1,["self"]))},[s("div",j,[s("div",L,[o[9]||(o[9]=s("h3",{style:{margin:"0"}},"New Poll",-1)),s("button",{class:"modal-close",onClick:o[0]||(o[0]=t=>i.value=!1),title:"Close"},"×")]),s("div",z,[o[10]||(o[10]=s("label",null,"Question (BN) *",-1)),u(s("input",{"onUpdate:modelValue":o[1]||(o[1]=t=>e.question_bn=t),required:""},null,512),[[c,e.question_bn]])]),s("div",G,[o[11]||(o[11]=s("label",null,"Question (EN)",-1)),u(s("input",{"onUpdate:modelValue":o[2]||(o[2]=t=>e.question_en=t)},null,512),[[c,e.question_en]])]),s("div",H,[o[12]||(o[12]=s("label",null,"Options *",-1)),(l(!0),n(g,null,C(e.options,(t,f)=>(l(),n("div",{key:f,class:"opt-row"},[u(s("input",{"onUpdate:modelValue":r=>t.option_bn=r,placeholder:"Option (BN)"},null,8,J),[[c,t.option_bn]]),u(s("input",{"onUpdate:modelValue":r=>t.option_en=r,placeholder:"Option (EN)"},null,8,K),[[c,t.option_en]]),s("button",{onClick:r=>e.options.splice(f,1),class:"btn-del"},"×",8,R)]))),128)),s("button",{onClick:o[3]||(o[3]=t=>e.options.push({option_bn:"",option_en:""})),class:"btn-add"},"+ Add Option")]),s("label",W,[u(s("input",{type:"checkbox","onUpdate:modelValue":o[4]||(o[4]=t=>e.is_active=t)},null,512),[[D,e.is_active]]),o[13]||(o[13]=k(" Active",-1))]),s("div",X,[s("button",{onClick:o[5]||(o[5]=t=>i.value=!1),class:"btn-secondary"},"Cancel"),s("button",{onClick:h,disabled:p.value,class:"btn-primary"},d(p.value?"Saving...":"Save"),9,Y)])])])):N("",!0)]))}},ls=T(Z,[["__scopeId","data-v-789d435d"]]);export{ls as default};
