(()=>{"use strict";var e={6479:function(e,t,n){var r=n(5893),s=n(7294),o=n(745);let i=()=>(0,r.jsx)("footer",{children:(0,r.jsxs)("p",{children:[(0,r.jsx)("span",{style:{fontSize:"150%",position:"relative",top:"3px"},children:"★"}),(0,r.jsx)("a",{href:"https://github.com/hartwork/jawanndenn/",children:"jawanndenn"})," is"," ",(0,r.jsx)("a",{href:"https://www.gnu.org/philosophy/free-sw.en.html",children:"software libre"})," ","developed by ",(0,r.jsx)("a",{href:"https://blog.hartwork.org/",children:"Sebastian Pipping"}),", licensed under the"," ",(0,r.jsx)("a",{href:"https://www.gnu.org/licenses/agpl.en.html",children:"GNU Affero GPL license"}),". Please"," ",(0,r.jsx)("a",{href:"https://github.com/hartwork/jawanndenn/issues",children:"report bugs"})," ","and let me know if you ",(0,r.jsx)("a",{href:"mailto:sebastian@pipping.org",children:"like"})," ","it.",(0,r.jsx)("iframe",{id:"github-star-button",src:"./static/3rdparty/github-buttons-4.0.1/docs/github-btn.html?user=hartwork&repo=jawanndenn&type=star&count=true",frameBorder:"0",scrolling:"0",width:"170px",height:"20px"})]})}),a=[["**","<strong>","</strong>"],["*","<em>","</em>"],["__","<strong>","</strong>"],["_","<em>","</em>"],["`","<tt>","</tt>"]],l={};a.forEach(e=>{let t=e[0],n=e[2];l[t]=n});let d=e=>{e=e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");let t=[],n=[];for(;e.length;){let r=!1;a.forEach(s=>{let o=s[0],i=s[1],a=s[2];if(e.startsWith(o))return n.length&&n[n.length-1]==o?(t.push(a),n.pop()):(t.push(i),n.push(o)),e=e.slice(o.length),r=!0,!1}),r||(t.push(e[0]),e=e.slice(1))}return n.reverse(),n.forEach(e=>{t.push(l[e])}),t.join("")};var c=n(5237);let u=e=>{let{name:t,tribool:n,setTribool:s}=e,o=!0===n,i=null===n;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{name:t,type:"hidden",value:i?"indeterminate":o?"on":""}),(0,r.jsx)(c.Z,{color:i?"maybe":o?"primary":"error",checked:o,indeterminate:i,onChange:function(e){i?s(!1):o?s(null):s(!0)}})]})};var h=n(807),p=n(2153),m=n(9717),f=n(2865);let g=e=>{let{pollId:t,config:n,votes:o,titleIsHtml:i=!1,pretend:a=!1}=e,[l,c]=(0,s.useState)([]),[g,j]=(0,s.useState)(""),x=l;if(l.length>n.options.length)x=l.slice(0,n.options.length);else if(l.length<n.options.length){let e=n.options.slice(l.length).map(e=>void 0);x=l.concat(e)}console.assert(x.length===n.options.length);let v=n.options.map((e,t)=>o.reduce((e,n)=>{let[r,s]=n;return e+ +!!s[t]},+!!x[t])),b=n.options.map((e,t)=>o.reduce((e,n)=>{let[r,s]=n;return e+ +(!1!==s[t])},+!![!0,null].includes(x[t]))),w=n.options.map((e,t)=>b[t]>v[t]?`${v[t]}\u{2013}${b[t]}`:v[t]),y=e=>t=>{let n=x.slice();n[e]=t,c(n)};return(0,r.jsx)(p.Z,{className:"poll",children:(0,r.jsxs)(m.Z,{children:[(0,r.jsx)("h2",{dangerouslySetInnerHTML:{__html:i?n.title:d(n.title)},className:"question"}),(0,r.jsxs)("form",{method:"POST",action:`vote/${t}`,children:[(0,r.jsx)("input",{type:"hidden",name:"csrfmiddlewaretoken",value:window.DJANGO_CSRF_TOKEN}),(0,r.jsxs)("table",{children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{}),n.options.map((e,t)=>(0,r.jsx)("td",{className:"vote",children:e},t)),(0,r.jsx)("td",{})]})}),(0,r.jsxs)("tbody",{children:[o.map((e,t)=>{let[n,s]=e;return(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{dangerouslySetInnerHTML:{__html:n},className:"person"}),s.map((e,t)=>(0,r.jsx)("td",{className:`vote ${e?"votedYes":null===e?"votedMaybe":"votedNo"}`,children:e?"✔":null===e?(0,r.jsx)("b",{children:"?"}):"✘"},t)),(0,r.jsx)("td",{})]},t)}),(0,r.jsxs)("tr",{className:"userVote",children:[(0,r.jsx)("td",{children:(0,r.jsx)(f.Z,{name:"voterName",placeholder:"Your name",variant:"standard",autoFocus:!a,value:g,onChange:e=>j(e.target.value),error:!a&&!g.trim(),className:"voterName"})}),x.map((e,t)=>(0,r.jsx)("td",{className:`vote ${e?"votedYes":null===e?"votedMaybe":!1===e?"votedNo":"yetToVote"}`,children:(0,r.jsx)(u,{name:`option${t}`,tribool:e,setTribool:y(t)})},t)),(0,r.jsxs)("td",{children:[" ",(0,r.jsx)(h.Z,{variant:"contained",disabled:a||!g.trim(),type:"submit",className:"submitVote",children:"SAVE"})]})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{}),w.map((e,t)=>(0,r.jsx)("td",{className:`vote ${e?"sumNonZero":""}`,children:e},t)),(0,r.jsx)("td",{})]})]})]})]})]})})},j=["Dmitri","Jule","Vered","Matthieu"],x={},v=(e,t)=>{let n=`${e}@${t}`,r=x[n];return void 0===r&&(r=Math.random()>.5,x[n]=r),r},b=e=>{let{config:t}=e,n=j.map((e,n)=>[e,t.options.map((e,t)=>v(n,t))]);return(0,r.jsx)(g,{config:t,votes:n,pretend:!0})},w=(e,t)=>{let n=Math.min(e.length,t.length),r=0;for(;r<n&&e[r]==t[r];r++);return e.substring(0,r)},y=e=>e.substring(0,e.length-e.trimStart().length);var O=n(632),N=n(6370);let _=(e=>{let t=e.split("\n"),n=t.reduce((e,t)=>w(y(t)+e,e),y(t[0]));return t.map(e=>e.substring(n.length)).join("\n")})(`\
  title: Which fruit do _**you**_ like?

  options:
    - Apple
    - Banana
    - Orange
    - Papaya

  lifetime: month
`);class S extends Error{constructor(e){super(e),this.name="InvalidConfigError",Object.setPrototypeOf(this,S.prototype)}}let Z=e=>{let t=(0,N.Qc)(e);if(void 0!==t.equal_width&&"boolean"!=typeof t.equal_width)throw new S("Attribute 'equal_width' is invalid, must be boolean.");if(!["month","week",void 0].includes(t.lifetime))throw new S("Attribute 'lifetime' is invalid, must be 'month' or 'week'.");if(void 0===t.options)throw new S("Attribute 'options' is missing.");if(!Array.isArray(t.options))throw new S("Attribute 'options' is not a list.");if(!t.options.every(e=>"string"==typeof e))throw new S("Attribute 'options' is not a list of strings.");if(void 0===t.title)throw new S("Attribute 'title' is missing.");if("string"!=typeof t.title)throw new S("Attribute 'title' is not a string.");return t},k=Z(_),A=[_,!0,k],E=e=>{let{configState:t}=e,[[n,s,o],i]=t;return(0,r.jsx)("div",{className:"setup",children:(0,r.jsx)("form",{action:"create",method:"POST",children:(0,r.jsxs)(p.Z,{children:[(0,r.jsx)("input",{type:"hidden",name:"csrfmiddlewaretoken",value:window.DJANGO_CSRF_TOKEN}),(0,r.jsx)(m.Z,{children:(0,r.jsx)(f.Z,{name:"config",label:"Setup (YAML or JSON)",multiline:!0,value:n,variant:"standard",onChange:e=>{let t=e.target.value,n=!1,r=null;try{r=Z(t),n=!0}catch(e){console.log("[DEBUG]","Config YAML/JSON failed to validate with error:",e.message),r=o}i([t,n,r])},className:`monospace-text ${s?"valid":"invalid"}`,autoFocus:!0,error:!s})}),(0,r.jsxs)(O.Z,{className:"setupButtons",sx:{justifyContent:"flex-end"},children:[(0,r.jsx)(h.Z,{variant:"text",onClick:e=>{i(A)},color:"inherit",children:"RESET"}),(0,r.jsx)(h.Z,{type:"submit",variant:"contained",disabled:!s,children:"CREATE"})]})]})})})};var P=n(8530),C=n(9814),T=n(7683),M=n(3797),$=n(4873);let I=e=>new Promise(t=>setTimeout(t,e)),R=async(e,t)=>{let n=`data/${e}`;try{let e=await fetch(n);if(!e.ok)throw Error(`HTTP request to '${n}' failed with status ${e.status}.`);let r=await e.json();t(r)}catch(e){console.error("ERROR:",e.message)}},F=async(e,t)=>{for(;;)document.hidden||await R(e,t),await I(1e3)},V=window.location.pathname.includes("/poll/")?/[0-9a-fA-F]{64}/.exec(window.location.pathname)[0]:null;V&&(document.title="jawanndenn: Vote!");let q=(0,P.Z)({palette:{primary:{main:T.Z["400"]}}}),B=(0,P.Z)(q,{palette:{maybe:q.palette.augmentColor({color:{main:M.Z["700"]},name:"maybe"})}}),G=e=>{let{pollId:t}=e,[n,o]=(0,s.useState)(null);return n?(0,r.jsx)($.Z,{container:!0,spacing:2,sx:{justifyContent:"safe center",alignItems:"flow-start"},children:(0,r.jsx)($.Z,{size:{xs:12,sm:12,md:"auto",lg:"auto",xl:"auto"},children:(0,r.jsx)("div",{className:"live",children:(0,r.jsx)(g,{pollId:t,config:n.config,votes:n.votes,titleIsHtml:!0})})})}):(F(t,o),(0,r.jsx)(r.Fragment,{}))},J=()=>{let e=(0,s.useState)(A),t=e[0][2];return(0,r.jsxs)($.Z,{container:!0,spacing:2,sx:{justifyContent:"safe center"},children:[(0,r.jsx)($.Z,{size:{xs:12,sm:12,md:4,lg:3,xl:3},children:(0,r.jsx)(E,{configState:e})}),(0,r.jsx)($.Z,{size:{xs:12,sm:12,md:"auto",lg:"auto",xl:"auto"},children:(0,r.jsx)(b,{config:t})})]})},L=document.getElementById("root");L&&o.createRoot(L).render((0,r.jsx)(s.StrictMode,{children:(0,r.jsx)(()=>(0,r.jsxs)(C.Z,{theme:B,children:[(0,r.jsx)("div",{className:"stage",children:V?(0,r.jsx)(G,{pollId:V}):(0,r.jsx)(J,{})}),(0,r.jsx)(i,{})]}),{})}))}},t={};function n(r){var s=t[r];if(void 0!==s)return s.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.m=e,n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},(()=>{var e,t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__;n.t=function(r,s){if(1&s&&(r=this(r)),8&s||"object"==typeof r&&r&&(4&s&&r.__esModule||16&s&&"function"==typeof r.then))return r;var o=Object.create(null);n.r(o);var i={};e=e||[null,t({}),t([]),t(t)];for(var a=2&s&&r;"object"==typeof a&&!~e.indexOf(a);a=t(a))Object.getOwnPropertyNames(a).forEach(e=>{i[e]=()=>r[e]});return i.default=()=>r,n.d(o,i),o}})(),n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e=[];n.O=(t,r,s,o)=>{if(r){o=o||0;for(var i=e.length;i>0&&e[i-1][2]>o;i--)e[i]=e[i-1];e[i]=[r,s,o];return}for(var a=1/0,i=0;i<e.length;i++){for(var[r,s,o]=e[i],l=!0,d=0;d<r.length;d++)(!1&o||a>=o)&&Object.keys(n.O).every(e=>n.O[e](r[d]))?r.splice(d--,1):(l=!1,o<a&&(a=o));if(l){e.splice(i--,1);var c=s();void 0!==c&&(t=c)}}return t}})(),n.rv=()=>"1.3.12",(()=>{var e={980:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var s,o,[i,a,l]=r,d=0;if(i.some(t=>0!==e[t])){for(s in a)n.o(a,s)&&(n.m[s]=a[s]);if(l)var c=l(n)}for(t&&t(r);d<i.length;d++)o=i[d],n.o(e,o)&&e[o]&&e[o][0](),e[o]=0;return n.O(c)},r=self.webpackChunkfrontend=self.webpackChunkfrontend||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})(),n.ruid="bundler=rspack@1.3.12";var r=n.O(void 0,["361","742"],function(){return n(6479)});r=n.O(r)})();