document.addEventListener('DOMContentLoaded', function() {
    const starGroups = document.querySelectorAll('.star-rating');
    
    starGroups.forEach(group => {
        const stars = group.querySelectorAll('.star');
        const hiddenInput = group.querySelector('input[type="hidden"]');
        
        stars.forEach(star => {
            star.addEventListener('click', function() {
                const value = parseInt(this.getAttribute('data-value'));
                hiddenInput.value = value;
                
                stars.forEach((s, i) => {
                    if (i < value) {
                        s.classList.add('active');
                        s.style.color = '#ffc107';
                    } else {
                        s.classList.remove('active');
                        s.style.color = '#ddd';
                    }
                });
            });
            
            star.addEventListener('mouseover', function() {
                const value = parseInt(this.getAttribute('data-value'));
                
                stars.forEach((s, i) => {
                    if (i < value) {
                        s.style.color = '#ffc107';
                    } else {
                        s.style.color = '#ddd';
                    }
                });
            });
        });
        
        group.addEventListener('mouseleave', function() {
            const currentValue = parseInt(hiddenInput.value) || 0;
            
            stars.forEach((s, i) => {
                if (i < currentValue) {
                    s.style.color = '#ffc107';
                } else {
                    s.style.color = '#ddd';
                }
            });
        });
    });
    
    document.getElementById('reviewForm').addEventListener('submit', function(e) {
        const serviceRating = document.getElementById('service_rating').value;
        const deliveryRating = document.getElementById('delivery_rating').value;
        
        if (!serviceRating || !deliveryRating) {
            e.preventDefault();
            alert('Please provide ratings for both service quality and delivery.');
        }
    });
});
