import{j as me,i as G,G as J,e as n,F as T,z as j,w as o,q,a as t,C as s,d as v,E as a,c as F,v as ne,t as fe,N as he,h as B,g as Y,P as te,J as ae,Q as ye,b as R,x as h,H as be}from"./index-BKC7zwXz.js";import{j as ge,g as _e,i as xe,A as U,c as ke,r as we,a as Ie}from"./polls-CS1wMJkc.js";import{u as se}from"./useSeoHead-Cx3_UPXn.js";import{f as D,a as $e}from"./format-BUz_I1oZ.js";import{a as Ce,r as Oe}from"./SparklesIcon-BkWt6LjM.js";import{r as Ve}from"./PlusIcon-DsXYJ-wI.js";import{r as Ae}from"./TrashIcon-DMiGzPL7.js";import{r as Ee}from"./ClipboardDocumentIcon-CjR26YYp.js";const ie="whenly:participantTokens";function Se(){try{return JSON.parse(localStorage.getItem(ie)??"{}")}catch{return{}}}function le(d){localStorage.setItem(ie,JSON.stringify(d))}const Ne=me("participantTokens",{state:()=>({map:Se()}),getters:{tokenFor:d=>m=>d.map[m]??null},actions:{remember(d,m){this.map[d]=m,le(this.map)},forget(d){delete this.map[d],le(this.map)}}}),ze={class:"space-y-2"},Me={class:"font-medium text-base leading-tight"},Pe={key:0,class:"flex gap-1.5 mt-1 flex-wrap"},Be={class:"inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-[var(--color-sage-400)]/20 text-[var(--color-sage-600)] dark:bg-[var(--color-sage-600)]/30 dark:text-[var(--color-sage-400)] font-medium"},Ye={key:0,class:"inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-[var(--color-citrus-400)]/20 text-[var(--color-citrus-500)] dark:bg-[var(--color-citrus-400)]/20 dark:text-[var(--color-citrus-400)] font-medium"},Te={class:"inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-[var(--color-clay-300)]/20 text-[var(--color-clay-700)] dark:bg-[var(--color-clay-300)]/20 dark:text-[var(--color-clay-300)] font-medium"},qe={class:"flex gap-1.5 shrink-0 justify-end sm:gap-2"},Fe=["disabled","aria-label","onClick"],He=["disabled","aria-label","onClick"],Le=["disabled","aria-label","onClick"],je=G({__name:"VoteGrid",props:{poll:{},myVotes:{},editable:{type:Boolean},showCounts:{type:Boolean}},emits:["change"],setup(d,{emit:m}){const l=d,w=m,{t:O,locale:S}=J(),e=F(()=>{const p=new Map;for(const f of l.poll.options)p.set(f.id,{yes:0,maybe:0,no:0});for(const f of l.poll.participants)for(const c of f.votes){const g=p.get(c.optionId);g&&(c.value==="YES"?g.yes++:c.value==="MAYBE"?g.maybe++:g.no++)}return p});function y(p){return l.myVotes.get(p)}function I(p,f){l.editable&&w("change",p,f)}function N(p){return D(p,l.poll.type,l.poll.timezone,S.value)}return(p,f)=>(o(),n("ul",ze,[(o(!0),n(T,null,j(d.poll.options,c=>{var g,k,$;return o(),n("li",{key:c.id,class:q(["surface-soft px-3 py-2.5 sm:px-4 sm:py-3 grid gap-2 sm:grid-cols-[1fr_auto] items-center",{"ring-2 ring-[var(--color-clay-500)] border-[var(--color-clay-500)]":d.poll.finalizedOptionId===c.id}])},[t("div",null,[t("p",Me,s(N(c)),1),d.showCounts?(o(),n("div",Pe,[t("span",Be," ✓ "+s(((g=e.value.get(c.id))==null?void 0:g.yes)??0),1),d.poll.settings.allowMaybe?(o(),n("span",Ye," ~ "+s(((k=e.value.get(c.id))==null?void 0:k.maybe)??0),1)):v("",!0),t("span",Te," ✗ "+s((($=e.value.get(c.id))==null?void 0:$.no)??0),1)])):v("",!0)]),t("div",qe,[t("button",{type:"button",class:q(["vote-pill !h-9 !min-w-[2.75rem] sm:!h-10 sm:!min-w-[3.25rem]",y(c.id)==="YES"?"vote-yes":"vote-empty"]),disabled:!d.editable,"aria-label":a(O)("poll.votes.yes"),onClick:V=>I(c.id,"YES")}," ✓ ",10,Fe),d.poll.settings.allowMaybe?(o(),n("button",{key:0,type:"button",class:q(["vote-pill !h-9 !min-w-[2.75rem] sm:!h-10 sm:!min-w-[3.25rem]",y(c.id)==="MAYBE"?"vote-maybe":"vote-empty"]),disabled:!d.editable,"aria-label":a(O)("poll.votes.maybe"),onClick:V=>I(c.id,"MAYBE")}," ~ ",10,He)):v("",!0),t("button",{type:"button",class:q(["vote-pill !h-9 !min-w-[2.75rem] sm:!h-10 sm:!min-w-[3.25rem]",y(c.id)==="NO"?"vote-no":"vote-empty"]),disabled:!d.editable,"aria-label":a(O)("poll.votes.no"),onClick:V=>I(c.id,"NO")}," ✗ ",10,Le)])],2)}),128))]))}}),De={key:0,class:"mt-6 pt-4 border-t border-[var(--color-sand-300)] dark:border-[var(--color-ink-700)]"},Re={class:"text-[10px] uppercase tracking-widest text-[var(--color-ink-50)] mb-2 select-none"},oe="6666533624",Ue=G({__name:"AdSenseAd",setup(d){const{t:m}=J(),l=!oe.includes("Y");return ne(()=>{if(l)try{(window.adsbygoogle=window.adsbygoogle||[]).push({})}catch{}}),(w,O)=>l?(o(),n("div",De,[t("p",Re,s(a(m)("common.ad")),1),t("ins",{class:"adsbygoogle block",style:{"min-height":"50px"},"data-ad-client":"ca-pub-9651598288655789","data-ad-slot":oe,"data-ad-format":"auto","data-full-width-responsive":"true"})])):v("",!0)}}),Ge={class:"container-narrow py-6 sm:py-10"},Je={key:0,class:"text-center py-12"},Ke={key:1,class:"text-center py-12 text-[var(--color-clay-700)]"},Qe={class:"mb-4 sm:mb-6"},We={class:"flex flex-wrap items-center gap-2 mb-1.5"},Xe={key:0,class:"chip chip-accent"},Ze={key:1,class:"chip"},et={class:"chip"},tt={class:"font-serif text-2xl sm:text-5xl leading-tight"},at={key:0,class:"mt-2 text-[var(--color-ink-100)] dark:text-[var(--color-sand-300)] whitespace-pre-line"},st={key:0,class:"surface bg-[var(--color-sage-400)] dark:!bg-[var(--color-sage-600)] p-5 mb-6"},lt={class:"chip chip-sage uppercase mb-2 inline-flex"},ot={class:"font-serif text-2xl"},nt={class:"mt-3 flex flex-wrap gap-2"},it=["href"],rt={key:1,class:"surface p-5 mb-6 border-[var(--color-clay-500)]",style:{"border-color":"var(--color-clay-500)"}},ct={class:"chip chip-accent inline-flex items-center gap-1.5 mb-2"},ut={class:"font-serif text-2xl"},dt={class:"text-sm mt-1 text-[var(--color-ink-100)] dark:text-[var(--color-sand-300)]"},pt={key:2,class:"mb-6 surface p-5 sm:p-6"},vt={class:"font-serif text-xl mb-3"},mt={class:"flex gap-2 items-start"},ft=["placeholder"],ht=["disabled"],yt={key:0,class:"text-sm mt-2 text-[var(--color-sage-600)]"},bt={key:1,class:"text-sm mt-2 text-[var(--color-clay-700)]"},gt={class:"text-xs mt-2 text-[var(--color-ink-50)]"},_t={key:3,class:"mb-6"},xt={class:"font-serif text-xl sm:text-2xl mb-2 sm:mb-3"},kt={key:0,class:"mb-3"},wt={class:"field-label",for:"my-name"},It=["placeholder","required"],$t={class:"mt-3 flex flex-wrap gap-2 items-center"},Ct=["disabled"],Ot={key:1,class:"text-sm text-[var(--color-clay-700)] font-medium"},Vt={key:5,class:"mb-6"},At={class:"flex items-baseline gap-3 mb-2 sm:mb-3"},Et={class:"font-serif text-xl sm:text-2xl"},St={key:0,class:"text-sm text-[var(--color-ink-100)] dark:text-[var(--color-sand-300)]"},Nt={key:0,class:"text-[var(--color-ink-100)] dark:text-[var(--color-sand-300)]"},zt={key:1,class:"overflow-x-auto -mx-1"},Mt={class:"w-full border-collapse text-sm"},Pt={class:"p-2 font-medium sticky left-0 bg-[var(--color-sand-100)] dark:bg-[var(--color-ink-900)]"},Bt={key:6,class:"surface-soft p-4 mb-8 text-center"},Yt={class:"mb-6"},Tt={class:"font-serif text-xl sm:text-2xl mb-2 sm:mb-3"},qt={class:"flex flex-col sm:flex-row gap-3 items-start"},Ft=["src","alt"],Ht={class:"text-xs text-[var(--color-ink-50)] text-center"},Qt=G({__name:"PollView",props:{publicId:{}},setup(d){const m=d,{t:l,locale:w}=J(),O=be(),S=Ne(),e=h(null),y=h(null),I=h(!0),N=h(null),p=h(""),f=h(new Map),c=h(!1),g=h(!1),k=h(null),$=h(!1);let V=null;const x=F(()=>S.tokenFor(m.publicId)),K=F(()=>e.value&&e.value.finalizedOptionId?e.value.options.find(i=>i.id===e.value.finalizedOptionId)??null:null),Q=F(()=>{var i,u;return(i=y.value)!=null&&i.bestOptionId?((u=e.value)==null?void 0:u.options.find(r=>r.id===y.value.bestOptionId))??null:null});async function z(i=!1){try{if(e.value=await _e(m.publicId,x.value),i||!y.value)try{y.value=await xe(m.publicId)}catch{}re(),I.value=!1}catch(u){if(I.value=!1,u instanceof U&&u.status===404){O.replace({name:"not-found"});return}N.value=l("common.error")}}function re(){if(!e.value||c.value)return;const i=e.value.viewerParticipantId?e.value.participants.find(r=>r.id===e.value.viewerParticipantId):null;if(!i){f.value=new Map,p.value="";return}const u=new Map;for(const r of i.votes)u.set(r.optionId,r.value);f.value=u,p.value||(p.value=i.name)}async function ce(){if(e.value&&f.value.size!==0){g.value=!0,k.value=null;try{const i=await ke(m.publicId,{name:p.value,votes:Array.from(f.value.entries()).map(([u,r])=>({optionId:u,value:r}))},x.value);S.remember(m.publicId,i.participantToken),c.value=!1,await z(!0)}catch(i){i instanceof U?k.value=i.message:k.value=l("common.error")}finally{g.value=!1}}}async function ue(){if(x.value&&confirm(l("poll.confirmRemove")))try{await we(m.publicId,x.value),S.forget(m.publicId),f.value=new Map,p.value="",await z(!0)}catch{}}function de(i,u){var r;(r=e.value)!=null&&r.closedAt||(c.value=!0,f.value.set(i,u))}const A=h(""),H=h(!1),M=h(null),L=h(!1);async function W(){if(!(!A.value.trim()||!e.value)){H.value=!0,M.value=null,L.value=!1;try{await Ie(m.publicId,A.value.trim()),A.value="",L.value=!0,await z(!0),setTimeout(()=>{L.value=!1},2e3)}catch(i){i instanceof U?M.value=i.message:M.value=l("common.error")}finally{H.value=!1}}}async function pe(){await navigator.clipboard.writeText(window.location.origin+"/p/"+m.publicId),$.value=!0,setTimeout(()=>$.value=!1,1500)}const ve=F(()=>e.value?$e(e.value.retentionUntil,w.value):"");return ne(async()=>{await z(!0),V=window.setInterval(()=>z(!1),1e4)}),fe(()=>{V&&clearInterval(V)}),he(()=>{if(!e.value){se({title:"Poll - whenly"});return}const i=e.value,u=`${i.title} - whenly`,r=i.description?`${i.description} - Vote on whenly`:`Group scheduling poll: ${i.title}. Vote on whenly - no account needed.`,_=`https://whenly.de/p/${i.publicId}`,C={"@context":"https://schema.org","@type":"Event",name:i.title,url:_,organizer:{"@type":"Organization",name:"whenly",url:"https://whenly.de"}};i.description&&(C.description=i.description),i.location&&(C.location={"@type":"Place",name:i.location});const P=i.options.filter(E=>E.startAt).map(E=>E.startAt).sort();P.length>0&&(C.startDate=P[0]),se({title:u,description:r,canonical:_,jsonLd:C})}),(i,u)=>(o(),n("section",Ge,[I.value?(o(),n("p",Je,s(a(l)("common.loading")),1)):N.value?(o(),n("p",Ke,s(N.value),1)):e.value?(o(),n(T,{key:2},[t("header",Qe,[t("div",We,[e.value.closedAt?(o(),n("span",Xe,s(a(l)("poll.closed")),1)):v("",!0),e.value.location?(o(),n("span",Ze,s(e.value.location),1)):v("",!0),t("span",et,s(e.value.participantCount)+" "+s(a(l)("poll.results.participants")),1)]),t("h1",tt,s(e.value.title),1),e.value.description?(o(),n("p",at,s(e.value.description),1)):v("",!0)]),K.value?(o(),n("div",st,[t("p",lt,s(a(l)("poll.finalized")),1),t("p",ot,s(a(D)(K.value,e.value.type,e.value.timezone,a(w))),1),t("div",nt,[t("a",{href:`/api/polls/${e.value.publicId}/ics`,class:"btn btn-outline",target:"_blank",rel:"noreferrer"},[B(a(Ce),{class:"w-5 h-5"}),u[2]||(u[2]=Y(" .ics ",-1))],8,it)])])):y.value&&Q.value&&y.value.participantCount>0?(o(),n("div",rt,[t("p",ct,[B(a(Oe),{class:"w-4 h-4"}),Y(" "+s(a(l)("poll.smartSuggest.heading")),1)]),t("p",ut,s(a(D)(Q.value,e.value.type,e.value.timezone,a(w))),1),t("p",dt,s(y.value.yesCount)+" yes · "+s(y.value.maybeCount)+" maybe · "+s(y.value.noCount)+" no ",1)])):v("",!0),e.value.type==="OPEN"&&!e.value.closedAt?(o(),n("section",pt,[t("h2",vt,s(a(l)("poll.open.suggestHeading")),1),t("div",mt,[te(t("input",{"onUpdate:modelValue":u[0]||(u[0]=r=>A.value=r),class:"input flex-1",placeholder:a(l)("poll.open.suggestPlaceholder"),maxlength:"200",onKeyup:ye(W,["enter"])},null,40,ft),[[ae,A.value]]),t("button",{class:"btn btn-outline shrink-0",disabled:H.value||!A.value.trim(),onClick:W},[B(a(Ve),{class:"w-5 h-5"}),Y(" "+s(H.value?a(l)("common.loading"):a(l)("poll.open.suggestButton")),1)],8,ht)]),L.value?(o(),n("p",yt,s(a(l)("poll.open.suggestSuccess")),1)):v("",!0),M.value?(o(),n("p",bt,s(M.value),1)):v("",!0),t("p",gt,s(a(l)("poll.open.suggestHint")),1)])):v("",!0),e.value.closedAt?v("",!0):(o(),n("section",_t,[t("h2",xt,s(a(l)("poll.voteHeading")),1),e.value.settings.requireParticipantName||c.value||!x.value?(o(),n("div",kt,[t("label",wt,s(a(l)("poll.yourName")),1),te(t("input",{id:"my-name","onUpdate:modelValue":u[1]||(u[1]=r=>p.value=r),class:"input max-w-md",placeholder:a(l)("poll.namePlaceholder"),required:e.value.settings.requireParticipantName,maxlength:"120"},null,8,It),[[ae,p.value]])])):v("",!0),B(je,{poll:e.value,"my-votes":f.value,editable:!e.value.closedAt,"show-counts":!!x.value&&!c.value,onChange:de},null,8,["poll","my-votes","editable","show-counts"]),t("div",$t,[t("button",{class:"btn btn-accent",disabled:g.value||f.value.size===0,onClick:ce},s(g.value?a(l)("common.loading"):x.value?a(l)("poll.updateVote"):a(l)("poll.saveVote")),9,Ct),x.value?(o(),n("button",{key:0,class:"btn btn-ghost text-sm",onClick:ue},[B(a(Ae),{class:"w-4 h-4"}),Y(" "+s(a(l)("poll.removeVote")),1)])):v("",!0),k.value?(o(),n("p",Ot,s(k.value),1)):v("",!0)])])),x.value&&!c.value&&!e.value.closedAt&&e.value.participantCount>=2?(o(),R(Ue,{key:4})):v("",!0),!e.value.resultsHidden&&(x.value&&!c.value||e.value.closedAt)?(o(),n("section",Vt,[t("div",At,[t("h2",Et,s(a(l)("poll.results.heading")),1),e.value.participants.length>0?(o(),n("span",St,s(e.value.participantCount)+" "+s(a(l)("poll.results.participants")),1)):v("",!0)]),e.value.participants.length===0?(o(),n("div",Nt,s(a(l)("poll.results.noVotesYet")),1)):(o(),n("div",zt,[t("table",Mt,[t("thead",null,[t("tr",null,[u[3]||(u[3]=t("th",{class:"text-left p-2 sticky left-0 bg-[var(--color-sand-100)] dark:bg-[var(--color-ink-900)]"}," ",-1)),(o(!0),n(T,null,j(e.value.options,r=>(o(),n("th",{key:r.id,class:"p-2 text-left font-medium font-serif"},s(a(D)(r,e.value.type,e.value.timezone,a(w))),1))),128))])]),t("tbody",null,[(o(!0),n(T,null,j(e.value.participants,r=>(o(),n("tr",{key:r.id,class:"border-t border-[var(--color-sand-300)]"},[t("td",Pt,s(r.name),1),(o(!0),n(T,null,j(e.value.options,_=>{var C,P,E,X,Z,ee;return o(),n("td",{key:_.id,class:"p-2"},[t("span",{class:q(["vote-pill !h-7 !min-w-[2.25rem] !text-xs px-2",{"vote-yes":((C=r.votes.find(b=>b.optionId===_.id))==null?void 0:C.value)==="YES","vote-maybe":((P=r.votes.find(b=>b.optionId===_.id))==null?void 0:P.value)==="MAYBE","vote-no":((E=r.votes.find(b=>b.optionId===_.id))==null?void 0:E.value)==="NO","vote-empty":!r.votes.find(b=>b.optionId===_.id)}])},s(((X=r.votes.find(b=>b.optionId===_.id))==null?void 0:X.value)==="YES"?"✓":((Z=r.votes.find(b=>b.optionId===_.id))==null?void 0:Z.value)==="MAYBE"?"~":((ee=r.votes.find(b=>b.optionId===_.id))==null?void 0:ee.value)==="NO"?"✗":"·"),3)])}),128))]))),128))])])]))])):(o(),n("div",Bt,s(a(l)("poll.results.hidden")),1)),t("section",Yt,[t("h2",Tt,s(a(l)("poll.share.heading")),1),t("div",qt,[t("button",{class:"btn btn-outline",onClick:pe},[$.value?(o(),R(a(ge),{key:0,class:"w-5 h-5"})):(o(),R(a(Ee),{key:1,class:"w-5 h-5"})),Y(" "+s($.value?a(l)("poll.share.copied"):a(l)("poll.share.copy")),1)]),t("img",{src:`/api/polls/${e.value.publicId}/qr`,alt:e.value.title,class:"w-28 h-28 border-2 border-[var(--color-ink-900)] bg-white p-1.5"},null,8,Ft)])]),t("p",Ht,s(a(l)("create.settings.retention.title"))+" "+s(ve.value),1)],64)):v("",!0)]))}});export{Qt as default};