document.addEventListener("DOMContentLoaded",function(){var t=window.ticketRatingConfig;if(!t||t.hasRating)return;var s=document.querySelector(".rating-stars"),a=document.getElementById("submitRating"),l=document.getElementById("ratingComment"),o=document.getElementById("ratingHoverLabel"),r=0;if(!s||!a)return;var d={1:t.translations.poor,2:t.translations.fair,3:t.translations.good,4:t.translations.veryGood,5:t.translations.excellent};function g(n){return n.closest?n.closest("[data-rating]"):null}function y(){return s.querySelectorAll("[data-rating]")}function c(n){y().forEach(function(e){var i=parseInt(e.getAttribute("data-rating"),10);i<=n?(e.classList.remove("text-muted"),e.classList.add("text-warning")):(e.classList.remove("text-warning"),e.classList.add("text-muted"))})}s.addEventListener("mouseover",function(n){var e=g(n.target);if(e){var i=parseInt(e.getAttribute("data-rating"),10);c(i),o&&(o.textContent=d[i]||"")}}),s.addEventListener("mouseout",function(n){s.contains(n.relatedTarget)||(c(r),o&&(o.textContent=r>0?d[r]:""))}),s.addEventListener("click",function(n){var e=g(n.target);e&&(r=parseInt(e.getAttribute("data-rating"),10),c(r),a.disabled=!1,o&&(o.textContent=d[r]||""))}),a.addEventListener("click",async function(){if(!(r<1||r>5)){a.disabled=!0,a.innerHTML='<i class="fas fa-spinner fa-spin me-1"></i>'+t.translations.submit;var n=document.querySelector('meta[name="csrf-token"]');if(!n){a.disabled=!1,a.innerHTML='<i class="fas fa-paper-plane me-1"></i>'+t.translations.submit;return}try{var e=await fetch(t.routes.rate,{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-TOKEN":n.content,Accept:"application/json"},body:JSON.stringify({rating:r,comment:l?l.value.trim():null})}),i=await e.json();if(e.ok&&i.success){var v=document.getElementById("ratingFormContainer"),p=document.getElementById("ratingSuccessContainer");if(v&&v.classList.add("d-none"),p){var L=document.getElementById("ratingSuccessStars");if(L){for(var u="",f=1;f<=5;f++){var E=f<=r?"text-warning":"text-muted";u+='<i class="fas fa-star '+E+'" style="font-size: 1.5rem;"></i>'}u+='<span class="ms-2 fw-semibold">('+r+"/5)</span>",L.innerHTML=u}var b=l?l.value.trim():"",m=document.getElementById("ratingSuccessComment");m&&b&&(m.textContent='"'+b+'"',m.classList.remove("d-none")),p.classList.remove("d-none")}}else{var S=i.message||t.translations.error;alert(S),a.disabled=!1,a.innerHTML='<i class="fas fa-paper-plane me-1"></i>'+t.translations.submit}}catch{alert(t.translations.error||"An error occurred"),a.disabled=!1,a.innerHTML='<i class="fas fa-paper-plane me-1"></i>'+t.translations.submit}}})});
