import{_ as C,a as V,b as H,c as F}from"./BfPjfeWt.js";import{_ as L}from"./CgXve9qO.js";import{_ as A}from"./DxB0DKYp.js";import{u as E}from"./BZ7f31ti.js";import{u as I,q as M,c as i,b as _,a as t,t as o,e as s,w,F as x,r as N,i as R,l as d,o as c,d as h,B as S}from"./BKiFavna.js";import{u as z}from"./BOqT4ZDK.js";import{_ as D}from"./DlAUqK2U.js";import"./DKzHUNYh.js";const Y={"data-theme":"light"},j={id:"main-content",role:"main"},G={class:"container"},J={class:"page-header"},K={class:"page-title"},O={class:"breadcrumb"},Q={key:0,class:"loading-box"},U={key:1,class:"empty-box"},W={key:2,class:"poll-wrap"},X={class:"poll-card"},Z={class:"poll-badge"},ss={class:"poll-question"},ts={class:"poll-total"},es={key:0,class:"poll-options"},os=["onClick","disabled"],ns={key:0,class:"vote-error"},as={key:1,class:"poll-results"},ls={class:"result-label"},is={class:"result-pct"},cs={class:"result-bar-wrap"},_s={class:"result-count"},rs={class:"voted-msg"},ds={__name:"polls",setup(us){const{lang:n}=I(),{api:f}=E(),e=d(null),y=d(!0),p=d(!1),v=d(!1),u=d(""),g=r=>!e.value||!e.value.total_votes?0:Math.round(r/e.value.total_votes*100),$=async()=>{try{const r=await f.get("/polls/active");e.value=r.data.poll}catch{e.value=null}finally{y.value=!1}},P=async r=>{if(e.value){p.value=!0,u.value="";try{const a=await f.post(`/polls/${e.value.id}/vote`,{option_id:r});e.value.options=a.data.options,e.value.total_votes=a.data.options.reduce((m,b)=>m+b.votes,0),v.value=!0}catch(a){u.value=a.message||(n.value==="bn"?"ভোট দিতে সমস্যা হয়েছে।":"Could not submit vote."),(a.message?.includes("ইতিমধ্যে")||a.message?.includes("already"))&&(v.value=!0)}finally{p.value=!1}}};return M($),z(()=>({title:n.value==="bn"?"পাঠক জরিপ — নিউজভার্স":"Reader's Polls — NewsVerse"})),(r,a)=>{const m=C,b=V,T=H,B=L,k=A,q=F;return c(),i("div",Y,[_(m),_(b),_(T),_(B),t("main",j,[t("div",G,[t("div",J,[t("h1",K,"📊 "+o(s(n)==="bn"?"পাঠক জরিপ":"Reader's Polls"),1),t("div",O,[_(k,{to:"/"},{default:w(()=>[h(o(s(n)==="bn"?"হোম":"Home"),1)]),_:1}),a[0]||(a[0]=t("span",null," › ",-1)),t("span",null,o(s(n)==="bn"?"পোল":"Polls"),1)])]),s(y)?(c(),i("div",Q,[a[1]||(a[1]=t("div",{class:"loader"},null,-1)),t("p",null,o(s(n)==="bn"?"লোড হচ্ছে...":"Loading..."),1)])):s(e)?(c(),i("div",W,[t("div",X,[t("div",Z,o(s(n)==="bn"?"🗳️ সক্রিয় পোল":"🗳️ Active Poll"),1),t("h2",ss,o(s(n)==="bn"?s(e).question_bn:s(e).question_en||s(e).question_bn),1),t("p",ts,o(s(n)==="bn"?`মোট ভোট: ${s(e).total_votes}`:`Total votes: ${s(e).total_votes}`),1),s(v)?(c(),i("div",as,[(c(!0),i(x,null,N(s(e).options,l=>(c(),i("div",{key:l.id,class:"result-row"},[t("div",ls,[h(o(s(n)==="bn"?l.option_bn:l.option_en||l.option_bn)+" ",1),t("span",is,o(g(l.votes))+"%",1)]),t("div",cs,[t("div",{class:"result-bar",style:S({width:g(l.votes)+"%"})},null,4)]),t("span",_s,o(l.votes)+" "+o(s(n)==="bn"?"ভোট":"votes"),1)]))),128)),t("p",rs,"✅ "+o(s(n)==="bn"?"আপনার ভোট গৃহীত হয়েছে।":"Your vote has been recorded."),1)])):(c(),i("div",es,[(c(!0),i(x,null,N(s(e).options,l=>(c(),i("button",{key:l.id,onClick:ps=>P(l.id),disabled:s(p),class:"poll-option-btn"},o(s(n)==="bn"?l.option_bn:l.option_en||l.option_bn),9,os))),128)),s(u)?(c(),i("p",ns,o(s(u)),1)):R("",!0)]))])])):(c(),i("div",U,[a[2]||(a[2]=t("div",{class:"empty-icon"},"📭",-1)),t("h2",null,o(s(n)==="bn"?"এখন কোনো সক্রিয় পোল নেই":"No active poll at the moment"),1),t("p",null,o(s(n)==="bn"?"পরে আবার দেখুন।":"Please check back later."),1),_(k,{to:"/",class:"btn-home"},{default:w(()=>[h(o(s(n)==="bn"?"হোমে ফিরুন":"Back to Home"),1)]),_:1})]))])]),_(q)])}}},ws=D(ds,[["__scopeId","data-v-149b2fc6"]]);export{ws as default};
