// Main JavaScript file for reviews page function init() { // Initialize star rating functionality initStarRating(); } function teardown() { // Clean up when navigating away from the page teardownStarRating(); } // Star rating functionality function initStarRating() { const starButtons = document.querySelectorAll('.star-btn'); const ratingInput = document.getElementById('rating-value'); const ratingText = document.getElementById('rating-text'); const ratingLabels = { 1: 'Poor - Not satisfied', 2: 'Fair - Below expectations', 3: 'Good - Met expectations', 4: 'Very Good - Exceeded expectations', 5: 'Excellent - Outstanding service!' }; let currentRating = 0; starButtons.forEach((star, index) => { // Click event star.addEventListener('click', handleStarClick); // Hover events star.addEventListener('mouseenter', handleStarHover); }); // Reset on mouse leave const starContainer = document.getElementById('star-rating'); if (starContainer) { starContainer.addEventListener('mouseleave', handleStarLeave); } function handleStarClick(e) { e.preventDefault(); const rating = parseInt(this.getAttribute('data-rating')); currentRating = rating; ratingInput.value = rating; ratingText.textContent = ratingLabels[rating]; updateStars(rating); } function handleStarHover() { const rating = parseInt(this.getAttribute('data-rating')); updateStars(rating, true); } function handleStarLeave() { updateStars(currentRating); } function updateStars(rating, isHover = false) { starButtons.forEach((star, index) => { const starRating = parseInt(star.getAttribute('data-rating')); if (starRating <= rating) { star.classList.remove('text-[#D4AF37]/30'); star.classList.add('text-[#D4AF37]'); } else { star.classList.remove('text-[#D4AF37]'); star.classList.add('text-[#D4AF37]/30'); } }); } } function teardownStarRating() { const starButtons = document.querySelectorAll('.star-btn'); const starContainer = document.getElementById('star-rating'); starButtons.forEach((star) => { star.removeEventListener('click', handleStarClick); star.removeEventListener('mouseenter', handleStarHover); }); if (starContainer) { starContainer.removeEventListener('mouseleave', handleStarLeave); } }