// Mobile Menu Toggle
document.addEventListener('DOMContentLoaded', function() {
    const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
    const navMenu = document.querySelector('.nav-menu');

    if (mobileMenuToggle && navMenu) {
        mobileMenuToggle.addEventListener('click', function() {
            navMenu.classList.toggle('active');
            
            // Change icon
            const icon = this.querySelector('i');
            if (navMenu.classList.contains('active')) {
                icon.classList.remove('fa-bars');
                icon.classList.add('fa-times');
            } else {
                icon.classList.remove('fa-times');
                icon.classList.add('fa-bars');
            }
        });
    }

    // Hero Slider functionality
    const heroSlides = document.querySelectorAll('.hero-slide');
    const heroNext = document.getElementById('heroNext');
    const heroPrev = document.getElementById('heroPrev');
    let currentHeroSlide = 0;
    let heroSliderInterval;

    function showHeroSlide(index) {
        // Remove active class from all slides
        heroSlides.forEach(slide => slide.classList.remove('active'));
        
        // Add active class to current slide
        if (heroSlides[index]) {
            heroSlides[index].classList.add('active');
        }
    }

    function nextHeroSlide() {
        currentHeroSlide = (currentHeroSlide + 1) % heroSlides.length;
        showHeroSlide(currentHeroSlide);
    }

    function prevHeroSlide() {
        currentHeroSlide = (currentHeroSlide - 1 + heroSlides.length) % heroSlides.length;
        showHeroSlide(currentHeroSlide);
    }

    // Auto-slide every 5 seconds
    function startHeroSlider() {
        heroSliderInterval = setInterval(nextHeroSlide, 5000);
    }

    function resetHeroSlider() {
        clearInterval(heroSliderInterval);
        startHeroSlider();
    }

    if (heroNext && heroPrev && heroSlides.length > 0) {
        // Next button
        heroNext.addEventListener('click', function() {
            nextHeroSlide();
            resetHeroSlider();
        });

        // Previous button
        heroPrev.addEventListener('click', function() {
            prevHeroSlide();
            resetHeroSlider();
        });

        // Start auto-slider
        startHeroSlider();
    }

    // Smooth scroll for anchor links
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            const href = this.getAttribute('href');
            if (href !== '#' && document.querySelector(href)) {
                e.preventDefault();
                document.querySelector(href).scrollIntoView({
                    behavior: 'smooth'
                });
            }
        });
    });

    // Add scroll effect to navbar
    let lastScroll = 0;
    window.addEventListener('scroll', function() {
        const navbar = document.querySelector('.navbar');
        const currentScroll = window.pageYOffset;

        if (currentScroll > 100) {
            navbar.style.backgroundColor = 'rgba(85, 59, 56, 1)';
        } else {
            navbar.style.backgroundColor = 'rgba(85, 59, 56, 0.95)';
        }

        lastScroll = currentScroll;
    });

    // Scroll to Top Button functionality
    const scrollToTopBtn = document.getElementById('scrollToTop');

    if (scrollToTopBtn) {
        // Show/hide button based on scroll position
        window.addEventListener('scroll', function() {
            if (window.pageYOffset > 300) {
                scrollToTopBtn.classList.add('visible');
            } else {
                scrollToTopBtn.classList.remove('visible');
            }
        });

        // Scroll to top when button is clicked
        scrollToTopBtn.addEventListener('click', function() {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            });
        });
    }

    // Category Buttons Toggle functionality
    const categoryButtons = document.querySelectorAll('.category-btn');
    
    if (categoryButtons.length > 0) {
        categoryButtons.forEach(button => {
            button.addEventListener('click', function() {
                // Remove active class from all buttons
                categoryButtons.forEach(btn => btn.classList.remove('active'));
                // Add active class to clicked button
                this.classList.add('active');
            });
        });
    }
});
