1import{p as u,t as p}from"./main-CdoCcVHu.js";function v(t){t.querySelectorAll(".rating-stars[data-rating]").forEach(e=>{const n=parseFloat(e.dataset.rating||"0");if(!(n<=0)){e.innerHTML="";for(let a=1;a<=6;a++){const r=document.createElement("span");if(r.className="rating-star",a<=Math.floor(n))r.classList.add("rating-star--full");else if(a===Math.ceil(n)&&n%1!==0){const s=Math.round(n%1*100);r.classList.add("rating-star--partial"),r.style.setProperty("--fill-percentage",`${s}%`)}else r.classList.add("rating-star--empty");r.innerHTML='<svg class="icon"><use xlink:href="#star"></use></svg>',e.appendChild(r)}}})}function S(t){const e=Math.round(t*2)/2;return e%1===0?String(e):String(e).replace(".","")}function m(t,e){const n=t.querySelector("dd");if(!n)return;const a=n.querySelector(".pcr-user-vote-skeleton");if(a&&a.remove(),e!==null&&e>0){const r=document.createElement("span");r.className="pcr-number",r.setAttribute("data-ui","user-rating-value"),r.textContent=e.toFixed(1).replace(".",","),n.appendChild(r);const s=document.createElement("span");s.className=`rating rating-results rating-${S(e)}`,s.setAttribute("data-ui","user-rating-stars"),s.textContent=e.toFixed(1).replace(".",","),n.appendChild(s)}else{const r=document.createElement("span");r.className="pcr-no-voted",r.textContent=u("matchRating:voting.no_rating"),n.appendChild(r)}}function d(t,e){t.querySelectorAll('[data-ui="user-vote"][data-player-rating-id]').forEach(n=>{const a=n.dataset.playerRatingId||"";m(n,e?.players[a]??null)}),["manager","team","opponent","referee"].forEach(n=>{const a=t.querySelector(`[data-ui="user-vote"][data-rating-type="${n}"]`);a&&m(a,e?.[n]??null)})}async function E(t,e){if(!e){d(t,null);return}try{const n=await fetch(e,{headers:{Accept:"application/json"},credentials:"same-origin"});if(!n.ok){d(t,null);return}const a=await n.json();if(a.status!=="ok"||!a.data.hasVoted||!a.data.votes){d(t,null);return}d(t,a.data.votes)}catch(n){console.error("Failed to load user votes:",n),d(t,null)}}function M(){document.querySelectorAll('[data-ui="match-rating-summary"]:not([data-rating-bound])').forEach(b)}function b(t){t.dataset.ratingBound="true";const e=t.dataset.apiUserVotes||"";v(t),E(t,e),p(t)}var c=null;function q(t){if(t<=0)return u("matchRating:voting.ended_countdown");const e=Math.floor(t/86400),n=Math.floor(t%86400/3600),a=Math.floor(t%3600/60),r=t%60;return e>0?`${e}d ${n}h ${a}m`:n>0?`${n}h ${a}m ${r}s`:a>0?`${a}m ${r}s`:`${r}s`}function V(t,e,n){const a=t.querySelector('[data-ui="countdown"]'),r=t.querySelector('[data-ui="voting-timer"]');if(!a)return()=>{};function s(){if(!a)return;const o=new Date,i=Math.max(0,Math.floor((e.getTime()-o.getTime())/1e3));if(i<=0){r&&(r.innerHTML=`<span class="match-rating__timer-closed">${u("matchRating:voting.ended_timer")}</span>`),c&&(clearInterval(c),c=null),n?.();return}a.textContent=q(i),i<3600&&a.classList.add("is-urgent")}return s(),c=setInterval(s,1e3),()=>{c&&(clearInterval(c),c=null)}}function R(t,e){const n=t.querySelectorAll(".rating-widget__star");let a=0;function r(s,o=!1){n.forEach((i,l)=>{const g=l+1;i.classList.toggle("is-filled",g<=s),i.classList.toggle("is-hovered",o&&g<=s)})}n.forEach((s,o)=>{const i=o+1;s.addEventListener("mouseenter",()=>{s.disabled||r(i,!0)}),s.addEventListener("mouseleave",()=>{r(a,!1)}),s.addEventListener("click",()=>{s.disabled||(a=i,t.dataset.currentValue=String(i),r(i,!1),e(i))})}),t.setValue=s=>{a=s,t.dataset.currentValue=String(s),r(s,!1)}}function h(t){const e={players:{},manager:null,team:null,opponent:null,referee:null};return t.querySelectorAll("li[data-player-rating-id]").forEach(n=>{const a=n.dataset.playerRatingId,r=n.querySelector('[data-ui="rating-widget"]');if(a&&r){const s=parseInt(r.dataset.currentValue||"0",10);s>0&&(e.players[a]=s)}}),t.querySelectorAll('[data-rating-type][data-ui="rating-widget"]').forEach(n=>{const a=n.dataset.ratingType,r=parseInt(n.dataset.currentValue||"0",10);r>0&&a in e&&(e[a]=r)}),e}function w(t){const e=h(t);return Object.keys(e.players).length>0||e.manager!==null||e.team!==null||e.opponent!==null||e.referee!==null}function f(t){const e=t.querySelector('[data-ui="submit-votes"]');e&&(e.disabled=!w(t))}function y(t){const e=t.querySelector('[data-ui="submit-votes"]');e&&(e.textContent=u("matchRating:voting.change_button"))}async function A(t,e){if(e)try{const n=await fetch(e,{headers:{Accept:"application/json"},credentials:"same-origin"});if(!n.ok)return;const a=await n.json();if(a.status!=="ok"||!a.data.hasVoted||!a.data.votes)return;const r=a.data.votes;
1Object.entries(r.players).forEach(([s,o])=>{t.querySelector(`li[data-player-rating-id="${s}"]`)?.querySelector('[data-ui="rating-widget"]')?.setValue?.(o)}),["manager","team","opponent","referee"].forEach(s=>{const o=r[s];o&&t.querySelector(`[data-rating-type="${s}"][data-ui="rating-widget"]`)?.setValue?.(o)}),f(t),y(t)}catch(n){console.error("Failed to load user votes:",n)}}async function C(t,e,n){const a=t.querySelector('[data-ui="submit-votes"]'),r=t.querySelector('[data-ui="success-message"]'),s=t.querySelector('[data-ui="error-message"]'),o=t.dataset.csrfToken||"";a&&(a.disabled=!0,a.textContent=u("matchRating:voting.sending")),r?.classList.add("hidden"),s?.classList.add("hidden");const i=h(t);try{const l=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},credentials:"same-origin",body:JSON.stringify({matchRatingId:parseInt(e,10),players:i.players,manager:i.manager,team:i.team,opponent:i.opponent,referee:i.referee,_csrf_token:o})})).json();if(l.status==="ok")r&&r.classList.remove("hidden"),y(t);else throw new Error(l.error||u("matchRating:voting.unknown_error"))}catch(l){const g=l instanceof Error?l.message:u("matchRating:voting.error");s&&(s.textContent=g,s.classList.remove("hidden"))}finally{a&&(a.disabled=!1,a.textContent=u("matchRating:voting.change_button")),f(t)}}function L(t){t.querySelectorAll(".rating-widget__star").forEach(a=>a.disabled=!0);const e=t.querySelector('[data-ui="submit-votes"]');e&&(e.style.display="none");const n=t.querySelector(".match-rating__help");n&&(n.textContent=u("matchRating:voting.ended_short"))}function $(){document.querySelectorAll('[data-ui="match-rating-voting"]:not([data-rating-bound])').forEach(_)}function _(t){t.dataset.ratingBound="true";const e=t.dataset.matchRatingId||"",n=t.dataset.votingEndsAt||"",a=t.dataset.apiVote||"",r=t.dataset.apiUserVotes||"",s=new Date(n),o=s>new Date;V(t,s,()=>{L(t)}),t.querySelectorAll('[data-ui="rating-widget"]').forEach(l=>{R(l,()=>{f(t)})}),r&&A(t,r);const i=t.querySelector('[data-ui="submit-votes"]');i&&o&&i.addEventListener("click",()=>{C(t,e,a)}),p(t)}export{M as initMatchRatingSummary,$ as initMatchRatingVoting};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.