const { useState, useEffect, useRef } = React;

// Smoke Effect Component
const SmokeEffect = () => {
    const [particles, setParticles] = useState([]);
    
    useEffect(() => {
        // Create initial particles
        const initialParticles = Array.from({ length: 15 }, (_, i) => ({
            id: i,
            x: Math.random() * window.innerWidth,
            y: window.innerHeight + 50,
            size: Math.random() * 30 + 20,
            opacity: Math.random() * 0.3 + 0.1,
            speed: Math.random() * 2 + 1,
            drift: (Math.random() - 0.5) * 2
        }));
        setParticles(initialParticles);

        // Animation loop
        const animateParticles = () => {
            setParticles(prevParticles => 
                prevParticles.map(particle => {
                    let newY = particle.y - particle.speed;
                    let newX = particle.x + particle.drift;
                    let newOpacity = particle.opacity;

                    // Reset particle when it goes off screen
                    if (newY < -100) {
                        newY = window.innerHeight + 50;
                        newX = Math.random() * window.innerWidth;
                        newOpacity = Math.random() * 0.3 + 0.1;
                    }

                    // Fade out as it rises
                    if (newY < window.innerHeight * 0.7) {
                        newOpacity = newOpacity * 0.995;
                    }

                    return {
                        ...particle,
                        x: newX,
                        y: newY,
                        opacity: Math.max(0, newOpacity)
                    };
                })
            );
        };

        const interval = setInterval(animateParticles, 50);
        return () => clearInterval(interval);
    }, []);

    return (
        <div style={{
            position: 'fixed',
            top: 0,
            left: 0,
            width: '100%',
            height: '100%',
            pointerEvents: 'none',
            zIndex: 1,
            overflow: 'hidden'
        }}>
            {particles.map(particle => (
                <div
                    key={particle.id}
                    style={{
                        position: 'absolute',
                        left: `${particle.x}px`,
                        top: `${particle.y}px`,
                        width: `${particle.size}px`,
                        height: `${particle.size}px`,
                        background: `radial-gradient(circle, rgba(200,200,200,${particle.opacity}) 0%, rgba(150,150,150,${particle.opacity * 0.5}) 50%, transparent 100%)`,
                        borderRadius: '50%',
                        filter: 'blur(8px)',
                        transform: 'scale(1)',
                        transition: 'opacity 0.1s ease-out'
                    }}
                />
            ))}
        </div>
    );
};

// Mock Framer Motion
const motion = new Proxy({}, {
    get: (target, prop) => {
        return ({ children, initial, animate, transition, whileHover, whileInView, viewport, ...props }) => {
            return React.createElement(prop, props, children);
        };
    }
});

const useInView = (ref, options) => true;

// Shared Navigation Component
const Navigation = () => {
    const [scrolled, setScrolled] = useState(false);
    const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
    const [isMobile, setIsMobile] = useState(false);

    useEffect(() => {
        const handleScroll = () => setScrolled(window.scrollY > 50);
        const handleResize = () => {
            setIsMobile(window.innerWidth <= 768);
            if (window.innerWidth > 768) setMobileMenuOpen(false);
        };

        handleResize();
        window.addEventListener('scroll', handleScroll);
        window.addEventListener('resize', handleResize);
        return () => {
            window.removeEventListener('scroll', handleScroll);
            window.removeEventListener('resize', handleResize);
        };
    }, []);

    const navLinkStyle = {
        color: 'var(--charcoal)',
        textDecoration: 'none',
        fontSize: '1rem',
        fontWeight: '500',
        transition: 'color 0.2s',
        cursor: 'pointer'
    };

    const buttonStyle = {
        display: 'inline-block',
        padding: '0.875rem 2rem',
        borderRadius: '8px',
        textDecoration: 'none',
        fontWeight: '600',
        fontSize: '1rem',
        transition: 'all 0.3s ease',
        cursor: 'pointer',
        border: 'none',
        letterSpacing: '0.02em'
    };

    return (
        <nav style={{
            position: 'fixed',
            top: 0,
            left: 0,
            right: 0,
            zIndex: 1000,
            padding: isMobile ? '1rem 1.5rem' : '1.5rem 4rem',
            background: scrolled ? 'rgba(245, 241, 232, 0.95)' : 'rgba(26, 26, 26, 0.8)',
            backdropFilter: 'blur(10px)',
            borderBottom: scrolled ? '1px solid rgba(212, 82, 42, 0.1)' : '1px solid rgba(245, 241, 232, 0.1)',
            transition: 'all 0.3s ease'
        }}>
            <div style={{
                maxWidth: '1600px',
                margin: '0 auto',
                display: 'flex',
                justifyContent: 'space-between',
                alignItems: 'center',
                flexDirection: isMobile ? 'column' : 'row'
            }}>
                <div style={{ width: '100%', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
                    <a href="index.html" style={{
                        fontSize: '1.5rem',
                        fontWeight: '700',
                        color: scrolled ? 'var(--charcoal)' : 'var(--cream)',
                        letterSpacing: '-0.02em',
                        transition: 'color 0.3s ease',
                        textDecoration: 'none'
                    }}>SAUCY'S</a>
                    {isMobile && (
                        <button onClick={() => setMobileMenuOpen(!mobileMenuOpen)} style={{
                            background: 'none',
                            border: 'none',
                            color: scrolled ? 'var(--charcoal)' : 'var(--cream)',
                            fontSize: '1.5rem',
                            cursor: 'pointer',
                            padding: '0.5rem'
                        }}>
                            {mobileMenuOpen ? '✕' : '☰'}
                        </button>
                    )}
                </div>
                <div style={{
                    display: isMobile ? (mobileMenuOpen ? 'flex' : 'none') : 'flex',
                    gap: isMobile ? '1rem' : '3rem',
                    alignItems: 'center',
                    flexDirection: isMobile ? 'column' : 'row',
                    width: isMobile ? '100%' : 'auto',
                    marginTop: isMobile ? '1rem' : '0'
                }}>
                    <a href="menu.html" style={{ ...navLinkStyle, color: scrolled ? 'var(--charcoal)' : 'var(--cream)', width: isMobile ? '100%' : 'auto', textAlign: isMobile ? 'center' : 'left' }}>Menu</a>
                    <a href="catering.html" style={{ ...navLinkStyle, color: scrolled ? 'var(--charcoal)' : 'var(--cream)', width: isMobile ? '100%' : 'auto', textAlign: isMobile ? 'center' : 'left' }}>Catering</a>
                    <a href="location.html" style={{ ...navLinkStyle, color: scrolled ? 'var(--charcoal)' : 'var(--cream)', width: isMobile ? '100%' : 'auto', textAlign: isMobile ? 'center' : 'left' }}>Visit</a>
                    <a href="jobs.html" style={{ ...navLinkStyle, color: scrolled ? 'var(--charcoal)' : 'var(--cream)', width: isMobile ? '100%' : 'auto', textAlign: isMobile ? 'center' : 'left' }}>Jobs</a>
                    <a href="contact-us.html" style={{ ...navLinkStyle, color: scrolled ? 'var(--charcoal)' : 'var(--cream)', width: isMobile ? '100%' : 'auto', textAlign: isMobile ? 'center' : 'left' }}>Contact</a>
                    <a href="order.html" style={{ ...buttonStyle, padding: '0.75rem 2rem', textDecoration: 'none', width: isMobile ? '100%' : 'auto', textAlign: 'center', background: 'var(--terracotta)', color: 'white' }}>Order Now</a>
                </div>
            </div>
        </nav>
    );
};

// Footer Component
const Footer = () => {
    const footerLinkStyle = {
        color: 'rgba(245, 241, 232, 0.7)',
        textDecoration: 'none',
        transition: 'color 0.2s',
        cursor: 'pointer'
    };

    return (
        <footer style={{ background: 'var(--charcoal)', padding: '4rem 4rem 2rem', color: 'var(--cream)' }}>
            <div style={{ maxWidth: '1400px', margin: '0 auto' }}>
                <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))', gap: '3rem', marginBottom: '3rem' }}>
                    <div>
                        <h3 style={{ fontSize: '2rem', fontFamily: "'DM Serif Display', serif", marginBottom: '1rem', color: 'var(--terracotta-light)' }}>Saucy's</h3>
                        <p style={{ fontSize: '0.95rem', lineHeight: '1.7', color: 'rgba(245, 241, 232, 0.7)', fontWeight: '300' }}>
                            Denver's favorite destination for authentic Southern BBQ, served with love since day one.
                        </p>
                    </div>
                    <div>
                        <h4 style={{ fontSize: '1.1rem', marginBottom: '1rem', fontWeight: '600', letterSpacing: '0.05em' }}>Quick Links</h4>
                        <div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem', fontSize: '0.95rem', fontWeight: '300' }}>
                            <a href="menu.html" style={footerLinkStyle}>Menu</a>
                            <a href="catering.html" style={footerLinkStyle}>Catering</a>
                            <a href="order.html" style={footerLinkStyle}>Order Online</a>
                            <a href="location.html" style={footerLinkStyle}>Location</a>
                            <a href="jobs.html" style={footerLinkStyle}>Jobs</a>
                            <a href="contact-us.html" style={footerLinkStyle}>Contact</a>
                        </div>
                    </div>
                    <div>
                        <h4 style={{ fontSize: '1.1rem', marginBottom: '1rem', fontWeight: '600', letterSpacing: '0.05em' }}>Connect</h4>
                        <div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem', fontSize: '0.95rem', fontWeight: '300' }}>
                            <a href="https://www.facebook.com/saucysouthern" target="_blank" rel="noopener noreferrer" style={footerLinkStyle}>Facebook</a>
                            <a href="https://www.instagram.com/saucysouthern" target="_blank" rel="noopener noreferrer" style={footerLinkStyle}>Instagram</a>
                            <a href="tel:7204846035" style={footerLinkStyle}>(720) 484-6035</a>
                        </div>
                    </div>
                </div>
                <div style={{ borderTop: '1px solid rgba(245, 241, 232, 0.1)', paddingTop: '2rem', textAlign: 'center', fontSize: '0.9rem', color: 'rgba(245, 241, 232, 0.5)', fontWeight: '300' }}>
                    © {new Date().getFullYear()} Saucy's Southern BBQ & Cuisine. All rights reserved.
                </div>
            </div>
        </footer>
    );
};

// Menu Card Component
const MenuCard = ({ item, delay }) => {
    return (
        <div style={{
            background: item.popular ? 'linear-gradient(135deg, rgba(212, 82, 42, 0.15), rgba(232, 131, 79, 0.05))' : 'rgba(245, 241, 232, 0.05)',
            padding: '2.5rem',
            borderRadius: '16px',
            border: item.popular ? '2px solid var(--terracotta)' : '1px solid rgba(245, 241, 232, 0.1)',
            position: 'relative',
            backdropFilter: 'blur(10px)'
        }}>
            {item.popular && (
                <div style={{
                    position: 'absolute',
                    top: '-12px',
                    right: '20px',
                    background: 'var(--terracotta)',
                    color: 'white',
                    padding: '0.5rem 1.5rem',
                    borderRadius: '20px',
                    fontSize: '0.8rem',
                    fontWeight: '600',
                    letterSpacing: '0.05em'
                }}>POPULAR</div>
            )}
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: '1.5rem' }}>
                <h3 style={{ fontSize: '2rem', fontFamily: "'DM Serif Display', serif", color: 'var(--cream)' }}>{item.name}</h3>
                <div style={{ fontSize: '2rem', fontWeight: '700', color: 'var(--terracotta-light)', fontFamily: "'DM Serif Display', serif" }}>{item.price}</div>
            </div>
            <p style={{ fontSize: '1.05rem', lineHeight: '1.7', color: 'rgba(245, 241, 232, 0.8)', fontWeight: '300' }}>{item.description}</p>
        </div>
    );
};

// Menu Page
const MenuPage = () => {
    const [isMobile, setIsMobile] = useState(false);

    useEffect(() => {
        const handleResize = () => setIsMobile(window.innerWidth <= 768);
        handleResize();
        window.addEventListener('resize', handleResize);
        return () => window.removeEventListener('resize', handleResize);
    }, []);

    const menuItems = [
        { name: "One Meat Plate", price: "$16.25", description: "Three ribs, two hotlinks, or six wings with your choice of two sides", popular: false },
        { name: "Two Meat Plate", price: "$18.25", description: "Mix and match any two of our signature smoked meats with two sides", popular: true },
        { name: "Three Meat Plate", price: "$23.25", description: "The ultimate BBQ experience - any combination of meats with two sides", popular: false }
    ];

    const buttonStyle = {
        display: 'inline-block',
        padding: '0.875rem 2rem',
        borderRadius: '8px',
        textDecoration: 'none',
        fontWeight: '600',
        fontSize: '1rem',
        transition: 'all 0.3s ease',
        cursor: 'pointer',
        border: 'none',
        letterSpacing: '0.02em'
    };

    return (
        <div>
            <Navigation />
            <section style={{
                padding: isMobile ? '6rem 1.5rem 4rem' : '10rem 4rem 8rem',
                background: 'linear-gradient(180deg, var(--charcoal) 0%, #2a1f1a 100%)',
                minHeight: '100vh'
            }}>
                <div style={{ maxWidth: '1400px', margin: '0 auto' }}>
                    <div style={{ marginBottom: '5rem', textAlign: 'center' }}>
                        <div style={{ fontSize: '0.9rem', letterSpacing: '0.3em', color: 'var(--terracotta-light)', marginBottom: '1rem', fontWeight: '500', textTransform: 'uppercase' }}>Our Plates</div>
                        <h1 style={{ fontSize: isMobile ? '2.5rem' : 'clamp(2.5rem, 5vw, 4.5rem)', fontFamily: "'DM Serif Display', serif", color: 'var(--cream)', marginBottom: '1.5rem' }}>Signature BBQ Plates</h1>
                        <p style={{ fontSize: '1.2rem', color: 'rgba(245, 241, 232, 0.7)', maxWidth: '700px', margin: '0 auto', fontWeight: '300', lineHeight: '1.7' }}>
                            Choose your adventure. All plates come with your choice of two house-made sides and our signature sauces.
                        </p>
                    </div>

                    <div style={{ display: 'grid', gridTemplateColumns: isMobile ? '1fr' : 'repeat(auto-fit, minmax(350px, 1fr))', gap: '2rem', marginBottom: '4rem' }}>
                        {menuItems.map((item, index) => <MenuCard key={index} item={item} delay={index * 0.2} />)}
                    </div>

                    <div style={{ padding: isMobile ? '2rem' : '3rem', background: 'rgba(212, 82, 42, 0.1)', borderRadius: '12px', border: '1px solid rgba(212, 82, 42, 0.2)', backdropFilter: 'blur(10px)' }}>
                        <h3 style={{ fontSize: '1.8rem', fontFamily: "'DM Serif Display', serif", color: 'var(--cream)', marginBottom: '1.5rem' }}>Popular Sides</h3>
                        <div style={{ display: 'grid', gridTemplateColumns: isMobile ? '1fr' : 'repeat(auto-fit, minmax(200px, 1fr))', gap: '1.5rem', color: 'var(--cream)', fontSize: '1.05rem', fontWeight: '300' }}>
                            <div>• Mac & Cheese</div>
                            <div>• Collard Greens</div>
                            <div>• Baked Beans</div>
                            <div>• Coleslaw</div>
                            <div>• Cornbread</div>
                            <div>• Potato Salad</div>
                        </div>
                    </div>

                    <div style={{ textAlign: 'center', marginTop: '4rem' }}>
                        <a href="order.html" style={{ ...buttonStyle, background: 'var(--terracotta)', color: 'white', padding: '1.2rem 3rem', fontSize: '1.1rem' }}>Order Now</a>
                    </div>
                </div>
            </section>
            <Footer />
        </div>
    );
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<MenuPage />);
