// Star Rating Variables let starButtons = null; let ratingValue = null; let ratingText = null; // Rating text mappings const ratingTexts = { 1: 'Poor', 2: 'Fair', 3: 'Good', 4: 'Very Good', 5: 'Excellent' }; // Star rating click handler function handleStarClick(event) { event.preventDefault(); const rating = parseInt(event.currentTarget.dataset.rating); // Update hidden input ratingValue.value = rating; // Update star colors starButtons.forEach((star, index) => { if (index < rating) { star.classList.remove('text-gray-300'); star.classList.add('text-[var(--accent-color)]'); } else { star.classList.remove('text-[var(--accent-color)]'); star.classList.add('text-gray-300'); } }); // Update rating text ratingText.textContent = ratingTexts[rating]; } // Form submission handler function handleFormSubmit(event) { event.preventDefault(); // Show thank you message const form = event.target.closest('.max-w-4xl'); const thankYouMessage = document.getElementById('thankYouMessage'); if (form && thankYouMessage) { form.style.display = 'none'; thankYouMessage.classList.remove('hidden'); thankYouMessage.scrollIntoView({ behavior: 'smooth' }); } } // Initialize star rating functionality function initStarRating() { starButtons = document.querySelectorAll('.star-btn'); ratingValue = document.getElementById('ratingValue'); ratingText = document.getElementById('ratingText'); // Add click event listeners to star buttons starButtons.forEach(button => { button.addEventListener('click', handleStarClick); }); } // Initialize form submission handling function initFormHandling() { const form = document.querySelector('[data-landingsite-contact-form]'); if (form) { form.addEventListener('submit', handleFormSubmit); } } // Export init function export function init() { initStarRating(); initFormHandling(); } // Export teardown function export function teardown() { // Remove event listeners if (starButtons) { starButtons.forEach(button => { button.removeEventListener('click', handleStarClick); }); } const form = document.querySelector('[data-landingsite-contact-form]'); if (form) { form.removeEventListener('submit', handleFormSubmit); } // Reset variables starButtons = null; ratingValue = null; ratingText = null; }