import './bootstrap';
import 'bootstrap';

// Professional JavaScript for LECL website with advanced animations
document.addEventListener('DOMContentLoaded', function() {
    // Enhanced smooth scrolling for anchor links
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const target = document.querySelector(this.getAttribute('href'));
            if (target) {
                const headerOffset = 80;
                const elementPosition = target.getBoundingClientRect().top;
                const offsetPosition = elementPosition + window.pageYOffset - headerOffset;

                window.scrollTo({
                    top: offsetPosition,
                    behavior: 'smooth'
                });
            }
        });
    });

    // Advanced scroll-triggered animations
    const observerOptions = {
        threshold: 0.1,
        rootMargin: '0px 0px -100px 0px'
    };

    const animationObserver = new IntersectionObserver((entries) => {
        entries.forEach((entry, index) => {
            if (entry.isIntersecting) {
                // Add staggered animation delays
                setTimeout(() => {
                    entry.target.classList.add('animate');
                }, index * 100);
            }
        });
    }, observerOptions);

    // Observe elements for scroll animations
    document.querySelectorAll('.card-custom, .animate-on-scroll').forEach(element => {
        animationObserver.observe(element);
    });

    // Navbar scroll effect
    let lastScrollTop = 0;
    const navbar = document.querySelector('.navbar');
    
    window.addEventListener('scroll', () => {
        const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
        
        // Add scrolled class for styling
        if (scrollTop > 50) {
            navbar.classList.add('scrolled');
        } else {
            navbar.classList.remove('scrolled');
        }
        
        lastScrollTop = scrollTop;
    });

    // Parallax effect for hero section
    const heroSection = document.querySelector('.hero-section');
    if (heroSection) {
        window.addEventListener('scroll', () => {
            const scrolled = window.pageYOffset;
            const rate = scrolled * -0.5;
            heroSection.style.transform = `translateY(${rate}px)`;
        });
    }

    // Interactive button effects
    document.querySelectorAll('.btn-lecl').forEach(button => {
        button.addEventListener('mouseenter', function() {
            this.style.transform = 'translateY(-3px) scale(1.02)';
        });
        
        button.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(0) scale(1)';
        });
        
        button.addEventListener('mousedown', function() {
            this.style.transform = 'translateY(-1px) scale(0.98)';
        });
        
        button.addEventListener('mouseup', function() {
            this.style.transform = 'translateY(-3px) scale(1.02)';
        });
    });

    // Testimonial card hover effects
    document.querySelectorAll('.testimonial-card').forEach(card => {
        card.addEventListener('mouseenter', function() {
            this.style.transform = 'perspective(1000px) rotateX(2deg) translateY(-5px)';
        });
        
        card.addEventListener('mouseleave', function() {
            this.style.transform = 'perspective(1000px) rotateX(0deg) translateY(0)';
        });
    });

    // Partner logo animation on scroll
    const partnerLogos = document.querySelectorAll('.partner-logo');
    const partnerObserver = new IntersectionObserver((entries) => {
        entries.forEach((entry, index) => {
            if (entry.isIntersecting) {
                setTimeout(() => {
                    entry.target.style.opacity = '1';
                    entry.target.style.transform = 'scale(1)';
                }, index * 150);
            }
        });
    }, { threshold: 0.5 });

    partnerLogos.forEach(logo => {
        logo.style.opacity = '0';
        logo.style.transform = 'scale(0.8)';
        logo.style.transition = 'all 0.6s ease';
        partnerObserver.observe(logo);
    });

    // Add floating animation to specific elements
    const floatingElements = document.querySelectorAll('.animate-float');
    floatingElements.forEach(element => {
        element.style.animation = 'float 3s ease-in-out infinite';
    });

    // Text typing effect for hero title - DISABLED to prevent text scrambling
    // const heroTitle = document.querySelector('.hero-title');
    // if (heroTitle) {
    //     const originalText = heroTitle.textContent;
    //     heroTitle.textContent = '';
    //     heroTitle.style.opacity = '1';
        
    //     let i = 0;
    //     const typeWriter = () => {
    //         if (i < originalText.length) {
    //             heroTitle.textContent += originalText.charAt(i);
    //             i++;
    //             setTimeout(typeWriter, 50);
    //         }
    //     };
        
    //     setTimeout(typeWriter, 800);
    // }

    // Loading animation completion
    setTimeout(() => {
        document.body.classList.add('loaded');
    }, 100);
});