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>
    );
};

// Order Page
const OrderPage = () => {
    const [isMobile, setIsMobile] = React.useState(false);

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

    return (
        <div>
            <SmokeEffect />
            <Navigation />
            <section style={{
                padding: isMobile ? '6rem 1.5rem 4rem' : '10rem 4rem 8rem',
                background: 'var(--cream)',
                minHeight: '100vh'
            }}>
                <div style={{ maxWidth: '1200px', margin: '0 auto', textAlign: 'center' }}>
                    <div style={{ marginBottom: '4rem' }}>
                        <div style={{ fontSize: '0.9rem', letterSpacing: '0.3em', color: 'var(--terracotta-light)', marginBottom: '1rem', fontWeight: '500', textTransform: 'uppercase' }}>Order Now</div>
                        <h1 style={{ fontSize: isMobile ? '2.5rem' : 'clamp(2.5rem, 5vw, 4.5rem)', fontFamily: "'DM Serif Display', serif", color: 'var(--charcoal)', marginBottom: '1.5rem' }}>
                            Order Your <span style={{ fontStyle: 'italic', color: 'var(--terracotta)' }}>Favorites</span>
                        </h1>
                        <p style={{ fontSize: '1.2rem', color: 'var(--smoke)', maxWidth: '600px', margin: '0 auto', fontWeight: '300' }}>
                            Craving BBQ? Get it delivered, pick it up, or order ahead with our partners
                        </p>
                    </div>

                    <div style={{ display: 'grid', gridTemplateColumns: isMobile ? '1fr' : 'repeat(2, 1fr)', gap: '2rem', maxWidth: '900px', margin: '0 auto' }}>
                        <a href="https://www.doordash.com" target="_blank" rel="noopener noreferrer" style={{
                            background: 'linear-gradient(135deg, white, #fafafa)',
                            padding: '3rem',
                            borderRadius: '16px',
                            textDecoration: 'none',
                            border: '2px solid var(--terracotta)',
                            boxShadow: '0 20px 60px rgba(212, 82, 42, 0.15)',
                            transition: 'transform 0.3s'
                        }}>
                            <div style={{ fontSize: '4rem', marginBottom: '1rem' }}>🚗</div>
                            <h3 style={{ fontSize: '2rem', fontFamily: "'DM Serif Display', serif", color: 'var(--charcoal)', marginBottom: '1rem' }}>DoorDash</h3>
                            <p style={{ fontSize: '1.05rem', color: 'var(--smoke)', fontWeight: '300', marginBottom: '1.5rem' }}>Get Saucy's delivered straight to your door</p>
                            <div style={{ background: 'var(--terracotta)', color: 'white', padding: '1rem 2rem', borderRadius: '8px', display: 'inline-block', fontWeight: '600' }}>Order on DoorDash</div>
                        </a>

                        <a href="tel:7204846035" style={{
                            background: 'white',
                            padding: '3rem',
                            borderRadius: '16px',
                            textDecoration: 'none',
                            border: '1px solid rgba(212, 82, 42, 0.1)',
                            boxShadow: '0 10px 40px rgba(0,0,0,0.08)',
                            transition: 'transform 0.3s'
                        }}>
                            <div style={{ fontSize: '4rem', marginBottom: '1rem' }}>📞</div>
                            <h3 style={{ fontSize: '2rem', fontFamily: "'DM Serif Display', serif", color: 'var(--charcoal)', marginBottom: '1rem' }}>Call to Order</h3>
                            <p style={{ fontSize: '1.05rem', color: 'var(--smoke)', fontWeight: '300', marginBottom: '1.5rem' }}>Prefer the personal touch? Call us for pickup</p>
                            <div style={{ background: 'var(--charcoal)', color: 'white', padding: '1rem 2rem', borderRadius: '8px', display: 'inline-block', fontWeight: '600' }}>(720) 484-6035</div>
                        </a>
                    </div>

                    <div style={{ marginTop: '4rem', padding: isMobile ? '2rem' : '3rem', background: 'linear-gradient(135deg, var(--charcoal) 0%, var(--brown) 100%)', borderRadius: '16px', color: 'var(--cream)' }}>
                        <div style={{ fontSize: '0.9rem', letterSpacing: '0.3em', color: 'var(--terracotta-light)', marginBottom: '1rem', fontWeight: '500', textTransform: 'uppercase' }}>Coming Soon</div>
                        <h3 style={{ fontSize: '2.5rem', fontFamily: "'DM Serif Display', serif", marginBottom: '1rem' }}>Saucy's Mobile App</h3>
                        <p style={{ fontSize: '1.1rem', opacity: 0.8, marginBottom: '2rem', fontWeight: '300' }}>Skip the line. Earn rewards. Get exclusive deals. Order your favorites with just a tap.</p>
                        <div style={{ display: 'flex', gap: '1rem', justifyContent: 'center', flexWrap: 'wrap' }}>
                            <div style={{ background: 'white', color: 'var(--charcoal)', padding: '1rem 2rem', borderRadius: '12px', fontWeight: '600' }}>App Store</div>
                            <div style={{ background: 'white', color: 'var(--charcoal)', padding: '1rem 2rem', borderRadius: '12px', fontWeight: '600' }}>Google Play</div>
                        </div>
                    </div>
                </div>
            </section>
            <Footer />
        </div>
    );
};

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