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

// Contact Page
const ContactPage = () => {
    const [isMobile, setIsMobile] = React.useState(false);
    const [formData, setFormData] = React.useState({ name: '', email: '', phone: '', message: '' });
    const [submitted, setSubmitted] = React.useState(false);

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

    const handleSubmit = (e) => {
        e.preventDefault();
        setSubmitted(true);
        console.log('Form submitted:', formData);
        setTimeout(() => {
            setSubmitted(false);
            setFormData({ name: '', email: '', phone: '', message: '' });
        }, 3000);
    };

    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>
            <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' }}>
                    <div style={{ textAlign: 'center', marginBottom: '4rem' }}>
                        <div style={{ fontSize: '0.9rem', letterSpacing: '0.3em', color: 'var(--terracotta-light)', marginBottom: '1rem', fontWeight: '500', textTransform: 'uppercase' }}>Get In Touch</div>
                        <h1 style={{ fontSize: isMobile ? '2.5rem' : 'clamp(2.5rem, 5vw, 4rem)', fontFamily: "'DM Serif Display', serif", marginBottom: '1.5rem', color: 'var(--charcoal)' }}>
                            Contact <span style={{ fontStyle: 'italic', color: 'var(--terracotta)' }}>Us</span>
                        </h1>
                        <p style={{ fontSize: '1.2rem', color: 'var(--smoke)', maxWidth: '600px', margin: '0 auto', fontWeight: '300' }}>
                            Questions about catering? Want to reserve a table? We'd love to hear from you!
                        </p>
                    </div>

                    <div style={{ maxWidth: '700px', margin: '0 auto', background: 'white', padding: isMobile ? '2rem' : '3rem', borderRadius: '16px', boxShadow: '0 20px 60px rgba(0,0,0,0.1)', border: '1px solid rgba(212, 82, 42, 0.1)' }}>
                        {submitted ? (
                            <div style={{ textAlign: 'center', padding: '3rem', color: 'var(--terracotta)' }}>
                                <div style={{ fontSize: '3rem', marginBottom: '1rem' }}>✓</div>
                                <h3 style={{ fontSize: '1.8rem', fontFamily: "'DM Serif Display', serif", marginBottom: '1rem', color: 'var(--charcoal)' }}>Thank You!</h3>
                                <p style={{ fontSize: '1.1rem', color: 'var(--smoke)', fontWeight: '300' }}>We've received your message and will get back to you soon.</p>
                            </div>
                        ) : (
                            <form onSubmit={handleSubmit}>
                                <div style={{ marginBottom: '1.5rem' }}>
                                    <label style={{ display: 'block', marginBottom: '0.5rem', fontSize: '0.95rem', fontWeight: '600', color: 'var(--charcoal)' }}>Name *</label>
                                    <input type="text" required value={formData.name} onChange={(e) => setFormData({...formData, name: e.target.value})} style={{ width: '100%', padding: '1rem', fontSize: '1rem', border: '2px solid rgba(212, 82, 42, 0.2)', borderRadius: '8px', fontFamily: "'Archivo', sans-serif", outline: 'none' }} />
                                </div>
                                <div style={{ marginBottom: '1.5rem' }}>
                                    <label style={{ display: 'block', marginBottom: '0.5rem', fontSize: '0.95rem', fontWeight: '600', color: 'var(--charcoal)' }}>Email *</label>
                                    <input type="email" required value={formData.email} onChange={(e) => setFormData({...formData, email: e.target.value})} style={{ width: '100%', padding: '1rem', fontSize: '1rem', border: '2px solid rgba(212, 82, 42, 0.2)', borderRadius: '8px', fontFamily: "'Archivo', sans-serif", outline: 'none' }} />
                                </div>
                                <div style={{ marginBottom: '1.5rem' }}>
                                    <label style={{ display: 'block', marginBottom: '0.5rem', fontSize: '0.95rem', fontWeight: '600', color: 'var(--charcoal)' }}>Phone</label>
                                    <input type="tel" value={formData.phone} onChange={(e) => setFormData({...formData, phone: e.target.value})} style={{ width: '100%', padding: '1rem', fontSize: '1rem', border: '2px solid rgba(212, 82, 42, 0.2)', borderRadius: '8px', fontFamily: "'Archivo', sans-serif", outline: 'none' }} />
                                </div>
                                <div style={{ marginBottom: '2rem' }}>
                                    <label style={{ display: 'block', marginBottom: '0.5rem', fontSize: '0.95rem', fontWeight: '600', color: 'var(--charcoal)' }}>Message *</label>
                                    <textarea required rows="6" value={formData.message} onChange={(e) => setFormData({...formData, message: e.target.value})} style={{ width: '100%', padding: '1rem', fontSize: '1rem', border: '2px solid rgba(212, 82, 42, 0.2)', borderRadius: '8px', fontFamily: "'Archivo', sans-serif", outline: 'none', resize: 'vertical' }} />
                                </div>
                                <button type="submit" style={{ ...buttonStyle, background: 'var(--terracotta)', color: 'white', padding: '1.2rem 3rem', width: '100%', fontSize: '1.1rem', fontWeight: '600', cursor: 'pointer' }}>Send Message</button>
                            </form>
                        )}
                    </div>
                </div>
            </section>
            <Footer />
        </div>
    );
};

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