// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
import{get as v,PopStateHandlers as L,post as H,setLastLocation as M}from"../utils/utils.js";function P(){const i=document.getElementById("next"),s=document.getElementById("upvote"),a=document.getElementById("downvote"),d=document.getElementById("report"),g=[document.getElementById("top").getAttribute("quote-id")],h=[i.getAttribute("quote-id")],o=window.location.search,r=(()=>{const e=new URLSearchParams(o).get("keys");return e!=null&&e.length?e.length===4?e.toUpperCase():(alert("Invalid keys given, using default."),"WASD"):"WASD"})();document.getElementById("wasd").innerText="".concat(r[0]," (Witzig), ").concat(r[2]," (Nicht Witzig), ")+"".concat(r[1]," (Vorheriges) und ").concat(r[3]," (Nächstes)"),document.onkeydown=e=>{switch(e.code){case"Key".concat(r[0]):s.click();break;case"Key".concat(r[1]):window.history.back();break;case"Key".concat(r[2]):a.click();break;case"Key".concat(r[3]):i.click()}};const T=document.getElementById("share"),E=document.getElementById("download"),f=document.getElementById("author"),u=document.getElementById("quote"),c=document.getElementById("real-author-name"),$=document.getElementById("rating-text"),A=document.getElementById("rating-img-container");i.removeAttribute("href");function p(e){T.href="/zitate/share/".concat(e).concat(o),E.href="/zitate/".concat(e,".gif").concat(o);const[t,n]=e.split("-",2);u.href="/zitate/info/z/".concat(t).concat(o),f.href="/zitate/info/a/".concat(n).concat(o),g[0]=e}function y(e){if(e=e.toString(),$.innerText=e,["---","???","0"].includes(e)){A.innerHTML="";return}const t=Number.parseInt(e),n=document.createElement("div");n.className="rating-img"+(t>0?" witzig":" nicht-witzig"),A.innerHTML=(n.outerHTML+" ").repeat(Math.min(4,Math.abs(t))).trim()}function b(e){function t(n,B,m){n.disabled=!1,e===B||e===m?(n.setAttribute("voted",m),n.value="0"):(n.removeAttribute("voted"),n.value=m)}t(s,1,"1"),t(a,-1,"-1")}function l(e){if(e.status)return console.error(e),e.status in[429,420]&&alert(e.reason),!1;if(e.id){if(p(e.id),h[0]=e.next,u.innerText="»".concat(e.quote,"«"),f.innerText="- ".concat(e.author),c.innerText=e.real_author,c.href="/zitate/info/a/".concat(e.real_author_id).concat(o),d){const t=new URLSearchParams(o);t.set("subject","Das falsche Zitat ".concat(e.id," hat ein Problem")),t.set("message","".concat(u.innerText," ").concat(c.innerText)),d.href="/kontakt?".concat(t.toString())}return y(e.rating),b(e.vote),!0}return!1}L.quotes=e=>{e.state&&l(e.state)},i.onclick=()=>v("/api/zitate/".concat(h[0]),o,e=>{l(e)&&(e.stateType="quotes",e.url="/zitate/".concat(e.id).concat(o),window.history.pushState(e,"Falsche Zitate",e.url),M(e.url))});const I=e=>H("/api/zitate/".concat(g[0]),{vote:e},t=>void l(t));for(const e of[s,a])e.type="button",e.onclick=()=>{s.disabled=!0,a.disabled=!0,I(e.value).then(()=>{s.disabled=!1,a.disabled=!1}).catch(()=>{s.disabled=!1,a.disabled=!1})}}for(const i of document.getElementsByClassName("auto-submit-element"))i.onchange=()=>{i.form.submit()};P();// @license-end
//# sourceMappingURL=quotes.js.map
