document.addEventListener('DOMContentLoaded', () => {
    // --- Smooth Scrolling ---
    const contactSection = document.getElementById('contact-section');
    if (!contactSection) return;

    const ctaButtons = document.querySelectorAll('.cta-button');
    
    ctaButtons.forEach(button => {
        button.addEventListener('click', (e) => {
            e.preventDefault();
            contactSection.scrollIntoView({ behavior: 'smooth' });
        });
    });

    // --- Contact Form Logic ---
    const form = document.getElementById('contact-form');
    const thankYouMessage = document.getElementById('thank-you-message');

    if (form && thankYouMessage) {
        form.addEventListener('submit', (e) => {
            e.preventDefault();
            
            // Fix: Cast elements to their specific HTML types to access the 'value' property.
            const nameInput = form.querySelector('input[name="name"]') as HTMLInputElement;
            const phoneInput = form.querySelector('input[name="phone"]') as HTMLInputElement;
            const equipmentSelect = form.querySelector('select[name="equipment"]') as HTMLSelectElement;
            
            // Basic validation
            if (nameInput.value && phoneInput.value && equipmentSelect.value) {
                form.style.display = 'none';
                thankYouMessage.style.display = 'block';
                // In a real-world scenario, you would send the data to a server here.
                // For this example, we'll just log it to the console.
                console.log('Form submitted with data:', {
                    name: nameInput.value,
                    phone: phoneInput.value,
                    equipment: equipmentSelect.value,
                    // Fix: Cast textarea to HTMLTextAreaElement to access its value property.
                    problem: (form.querySelector('textarea[name="problem"]') as HTMLTextAreaElement).value
                });
            } else {
                alert('Пожалуйста, заполните все обязательные поля (*).');
            }
        });
    }

    // --- Dynamic Copyright Year ---
    const yearSpan = document.getElementById('copyright-year');
    if (yearSpan) {
        // Fix: Convert the number returned by getFullYear() to a string.
        yearSpan.textContent = new Date().getFullYear().toString();
    }
});