document.addEventListener('DOMContentLoaded', () => {
    const demoForm = document.getElementById('schoolDemoForm');

    if (demoForm) {
        demoForm.addEventListener('submit', (e) => {
            e.preventDefault();

            // Get form values
            const countryCode = document.getElementById('countryCode').value;
            const category = document.getElementById('category').value;
            const subCategory = document.getElementById('subCategory').value;
            const fullName = document.getElementById('fullName').value;
            const email = document.getElementById('emailAddress').value;
            const phone = document.getElementById('phoneNumber').value;

            // Construct message
            const message = `*New Demo Request*\n` +
                `------------------\n` +
                `*Category:* ${category}\n` +
                `*Sub Category:* ${subCategory}\n` +
                `*Name:* ${fullName}\n` +
                `*Email:* ${email}\n` +
                `*Phone:* ${countryCode} ${phone}`;

            // WhatsApp number
            const whatsappNumber = "918744864239";

            // Encode message
            const encodedMessage = encodeURIComponent(message);

            // Redirect to WhatsApp
            const whatsappUrl = `https://wa.me/${whatsappNumber}?text=${encodedMessage}`;
            window.open(whatsappUrl, '_blank');
        });
    }

    // Dynamic Sub-category logic (Optional but good for UX)
    const categorySelect = document.getElementById('category');
    const subCategorySelect = document.getElementById('subCategory');

    if (categorySelect && subCategorySelect) {
        const subCategories = {
            'School': ['Preschool', 'K-12', 'High School', 'Boarding School'],
            'College': ['Engineering', 'Medical', 'Arts & Science', 'Management'],
            'Coaching': ['JEE/NEET', 'UPSC', 'Languages', 'Skills']
        };

        categorySelect.addEventListener('change', () => {
            const selectedCategory = categorySelect.value;
            const options = subCategories[selectedCategory] || [];

            // Clear current options
            subCategorySelect.innerHTML = '<option value="" selected disabled>Select Sub Category</option>';

            // Add new options
            options.forEach(opt => {
                const option = document.createElement('option');
                option.value = opt;
                option.textContent = opt;
                subCategorySelect.appendChild(option);
            });
        });
    }
});
