// Star Rating Functionality let selectedRating = 0; const ratingMessages = { 1: "Poor - We're sorry to hear that", 2: "Fair - We appreciate your feedback", 3: "Good - Thank you for your review", 4: "Very Good - We're glad you're satisfied", 5: "Excellent - Thank you for the 5-star review!" }; function handleStarClick(event) { event.preventDefault(); const rating = parseInt(event.currentTarget.getAttribute('data-rating')); selectedRating = rating; // Update hidden input const ratingInput = document.getElementById('rating'); if (ratingInput) { ratingInput.value = rating; } // Update star display const starButtons = document.querySelectorAll('.star-btn'); starButtons.forEach((btn, index) => { const star = btn.querySelector('i'); if (index < rating) { btn.className = 'star-btn text-3xl text-[var(--accent2-color)] hover:text-[var(--accent2-color)] transition-colors duration-200'; } else { btn.className = 'star-btn text-3xl text-gray-300 hover:text-[var(--accent2-color)] transition-colors duration-200'; } }); // Update rating text const ratingText = document.getElementById('ratingText'); if (ratingText) { ratingText.textContent = ratingMessages[rating]; ratingText.className = 'text-[var(--primary-color)] ml-4 font-medium'; } } function handleStarHover(event) { const rating = parseInt(event.currentTarget.getAttribute('data-rating')); const starButtons = document.querySelectorAll('.star-btn'); starButtons.forEach((btn, index) => { const star = btn.querySelector('i'); if (index < rating) { btn.querySelector('i').style.color = 'var(--accent2-color)'; } else if (index < selectedRating) { btn.querySelector('i').style.color = 'var(--accent2-color)'; } else { btn.querySelector('i').style.color = ''; } }); } function handleStarLeave() { const starButtons = document.querySelectorAll('.star-btn'); starButtons.forEach((btn, index) => { if (index < selectedRating) { btn.querySelector('i').style.color = 'var(--accent2-color)'; } else { btn.querySelector('i').style.color = ''; } }); } function init() { // Add star rating event listeners const starButtons = document.querySelectorAll('.star-btn'); starButtons.forEach(btn => { btn.addEventListener('click', handleStarClick); btn.addEventListener('mouseenter', handleStarHover); btn.addEventListener('mouseleave', handleStarLeave); }); } function teardown() { // Remove star rating event listeners const starButtons = document.querySelectorAll('.star-btn'); starButtons.forEach(btn => { btn.removeEventListener('click', handleStarClick); btn.removeEventListener('mouseenter', handleStarHover); btn.removeEventListener('mouseleave', handleStarLeave); }); } // Export functions export { init, teardown };