// Bee Blossom — Main App
// Tweakable defaults: palette lead, font pairing, imagery style, hero layout

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "palette": "green",
  "fontPair": "cormorant_manrope",
  "imagery": "stripes",
  "heroLayout": "split"
}/*EDITMODE-END*/;

// ── Palette presets ───────────────────────────────────
const PALETTES = {
  green: {
    "--bg": "#faf6ea", "--bg-2": "#f3eddb",
    "--ink": "#1a2e1f", "--ink-soft": "#3d4a3f",
    "--primary": "#2f5d3a", "--primary-deep": "#1f4128",
    "--accent": "#d97433", "--gold": "#c69a3c", "--gold-soft": "#e0c684",
    "--line": "rgba(26, 46, 31, 0.14)",
  },
  orange: {
    "--bg": "#fbf7ea", "--bg-2": "#f5ead4",
    "--ink": "#2a1a0e", "--ink-soft": "#4a3322",
    "--primary": "#d97433", "--primary-deep": "#b25923",
    "--accent": "#2f5d3a", "--gold": "#c69a3c", "--gold-soft": "#e0c684",
    "--line": "rgba(42, 26, 14, 0.14)",
  },
  gold: {
    "--bg": "#fbf6e2", "--bg-2": "#f3e9c6",
    "--ink": "#2a2110", "--ink-soft": "#52472a",
    "--primary": "#a8842a", "--primary-deep": "#7c601a",
    "--accent": "#2f5d3a", "--gold": "#c69a3c", "--gold-soft": "#e0c684",
    "--line": "rgba(42, 33, 16, 0.16)",
  },
  forest: {
    "--bg": "#0f1e14", "--bg-2": "#162b1c",
    "--ink": "#f3eddb", "--ink-soft": "#cdc7b3",
    "--primary": "#c69a3c", "--primary-deep": "#a8842a",
    "--accent": "#e07b2a", "--gold": "#e0c684", "--gold-soft": "#f3eddb",
    "--line": "rgba(243, 237, 219, 0.16)",
  },
};

// ── Font pairings ─────────────────────────────────────
// Each pairing also imports its Google Font in the page <head> already.
const FONT_PAIRS = {
  cormorant_manrope: {
    "--font-display": '"Cormorant Garamond", Georgia, serif',
    "--font-body":    '"Manrope", ui-sans-serif, system-ui, sans-serif',
  },
  playfair_dmsans: {
    "--font-display": '"Playfair Display", Georgia, serif',
    "--font-body":    '"DM Sans", ui-sans-serif, system-ui, sans-serif',
  },
  italiana_workSans: {
    "--font-display": '"Italiana", Georgia, serif',
    "--font-body":    '"Work Sans", ui-sans-serif, system-ui, sans-serif',
  },
};

const SITE_IMAGES = {
  hero: { src: "images/1.jpeg", alt: "Bee Blossom mobile cocktail bar serving guests at an outdoor event" },
  about: { src: "", alt: "Bee Blossom bar trailer serving guests during an evening garden party" },
};

// Honeycomb mark — simple geometric only
const HoneycombMark = ({ size = 30, color = "currentColor" }) => (
  <svg width={size} height={size} viewBox="0 0 30 30" fill="none" aria-hidden="true">
    <path d="M15 2.5 L25.4 8 L25.4 19 L15 24.5 L4.6 19 L4.6 8 Z"
          stroke={color} strokeWidth="1.4" />
    <path d="M15 9.5 L20.5 12.4 L20.5 18.1 L15 21 L9.5 18.1 L9.5 12.4 Z"
          fill={color} opacity="0.35" />
  </svg>
);

const HoneycombBand = ({ className = "" }) => (
  <svg className={`bb-honey-band ${className}`} viewBox="0 0 200 220" fill="none" aria-hidden="true">
    {Array.from({ length: 5 }).map((_, row) =>
      Array.from({ length: 3 }).map((_, col) => {
        const x = 20 + col * 60 + (row % 2 ? 30 : 0);
        const y = 20 + row * 40;
        return (
          <path key={`${row}-${col}`}
                d={`M${x} ${y} l25 0 l12.5 21.6 l-12.5 21.6 l-25 0 l-12.5 -21.6 z`}
                stroke="var(--gold)" strokeWidth="1" opacity="0.55" />
        );
      })
    )}
  </svg>
);

// ── Nav ──────────────────────────────────────────────
function Nav({ activeSection }) {
  const [scrolled, setScrolled] = React.useState(false);
  const [open, setOpen] = React.useState(false);

  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 24);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  const links = [
    ["about", "About"], ["menu", "Menu"], ["calculator", "Calculator"], ["contact", "Contact"],
  ];

  const go = (id) => {
    setOpen(false);
    const el = document.getElementById(id);
    if (el) window.scrollTo({ top: el.offsetTop - 60, behavior: "smooth" });
  };

  return (
    <nav className={`bb-nav ${scrolled ? "scrolled" : ""}`}>
      <a href="#top" className="bb-logo" onClick={(e) => { e.preventDefault(); window.scrollTo({ top: 0, behavior: "smooth" }); }}>
        <span className="mark"><HoneycombMark size={26} /></span>
        Bee Blossom
      </a>
      <div className={`bb-nav-links ${open ? "open" : ""}`}>
        {links.map(([id, label]) => (
          <button key={id} type="button"
                  className={`bb-nav-link ${activeSection === id ? "active" : ""}`}
                  onClick={() => go(id)}>{label}</button>
        ))}
        <button type="button" className="bb-cta" onClick={() => go("contact")}>Book the bar</button>
      </div>
      <button className="bb-mobile-toggle" type="button" aria-label="Menu" onClick={() => setOpen(o => !o)}>
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6">
          {open ? <path d="M6 6l12 12M18 6L6 18" strokeLinecap="round" /> : (
            <g><path d="M4 7h16" /><path d="M4 17h16" /></g>
          )}
        </svg>
      </button>
    </nav>
  );
}

// ── Hero ──────────────────────────────────────────────
function Hero({ layout, imageryStyle }) {
  const imgClass = `bb-img tall ${imageryStyle === "botanical" ? "botanical" : "stripes"}`;
  return (
    <section id="top" className={`bb-hero layout-${layout}`}>
      <HoneycombBand className="top-right" />
      <div className="bb-hero-inner">
        <div>
          <div className="bb-eyebrow" style={{ marginBottom: 24 }}>Mobile cocktail bar · est. 2019</div>
          <h1 className="bb-display">
            Drinks <em>on</em> the go.<br />
             
          </h1>
          <p className="bb-hero-lede" style={{ marginTop: 28 }}>
            Bee Blossom builds beautiful, season-driven bars for weddings,
            launches and the kind of parties guests still talk about months later.
            Mobile setup, signature menu, your venue — anywhere within 60 miles.
          </p>
          <div className="bb-hero-actions">
            <a href="#contact" className="bb-cta bb-cta-accent" onClick={(e) => { e.preventDefault(); document.getElementById("contact")?.scrollIntoView({ behavior: "smooth", block: "start" }); }}>
              Book the bar
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M5 12h14M13 6l6 6-6 6" strokeLinecap="round" strokeLinejoin="round" /></svg>
            </a>
            <a href="#menu" className="bb-cta bb-cta-ghost" onClick={(e) => { e.preventDefault(); document.getElementById("menu")?.scrollIntoView({ behavior: "smooth", block: "start" }); }}>
              Taste the menu
            </a>
          </div>
          {layout === "editorial" && (
            <div className="bb-hero-meta" style={{ marginTop: 64 }}>
              <div className="bb-hero-meta-item"><span className="bb-eyebrow">Service area</span><b>60 mi · Bay Area</b></div>
              <div className="bb-hero-meta-item"><span className="bb-eyebrow">Crafted since</span><b>2019</b></div>
              <div className="bb-hero-meta-item"><span className="bb-eyebrow">Events booked</span><b>340+</b></div>
            </div>
          )}
        </div>
        <div className="bb-hero-art">
          <div className={`${imgClass} photo`}>
            <img src={SITE_IMAGES.hero.src} alt={SITE_IMAGES.hero.alt} loading="eager" />
          </div>
        </div>
      </div>
    </section>
  );
}

// ── About ────────────────────────────────────────────
function About({ imageryStyle }) {
  const imgClass = `bb-img tall ${imageryStyle === "botanical" ? "botanical" : "stripes"}`;
  return (
    <section id="about" className="bb-section cream" data-screen-label="02 About">
      <div className="bb-container">
        <div className="bb-about">
          <div className="bb-about-art">
            <div className={`${imgClass} photo`}>
              <img src={SITE_IMAGES.about.src} alt={SITE_IMAGES.about.alt} loading="lazy" />
            </div>
          </div>
          <div>
            <div className="bb-eyebrow">About Bee Blossom</div>
            <h2 className="bb-display" style={{ fontFamily: "var(--font-display)", fontWeight: 400, fontSize: "clamp(40px, 5.5vw, 64px)", margin: "14px 0 28px", lineHeight: 1.05 }}>
              A small bar with <em style={{ color: "var(--accent)" }}>big-hearted</em> service.
            </h2>
            <p className="lead">
              We started Bee Blossom in 2019 with one bar cart, a notebook of
              honey-cocktail recipes, and a stubborn belief that great drinks
              shouldn't stay locked inside restaurants.
            </p>
            <p>
              Today our two-truck team caters weddings, launches and private
              gatherings across the Bay Area — building seasonal menus around
              local apiaries, small distillers, and whatever's flowering that month.
              Every event is led by our founders. We arrive early, set up
              beautifully, and pour with care until your last guest is happy.
            </p>
            <div className="bb-about-stats">
              <div className="bb-about-stat">
                <b>340+</b>
                <span>Events poured</span>
              </div>
              <div className="bb-about-stat">
                <b>12</b>
                <span>Local apiaries</span>
              </div>
              <div className="bb-about-stat">
                <b>4.9</b>
                <span>★ guest rating</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ── Menu Section ─────────────────────────────────────
function MenuSection({ imageryStyle }) {
  return (
    <section id="menu" className="bb-section" data-screen-label="03 Menu">
      <HoneycombBand className="bottom-left" />
      <div className="bb-container">
        <div className="bb-section-head">
          <div>
            <div className="bb-eyebrow">The Signature Menu</div>
            <h2 className="bb-display">Built around <em>honey</em>, <br />led by the season.</h2>
          </div>
          <p>
            Every menu starts with a conversation. The six below are our most
            requested — fully customizable, swappable, and dressed up or down
            for the occasion. We'll tailor pours, ingredients and presentation
            to your event.
          </p>
        </div>
        <div className="bb-menu-grid">
          {COCKTAILS.map((c) => <Cocktail key={c.id} c={c} imageryStyle={imageryStyle} />)}
        </div>
      </div>
    </section>
  );
}

// ── Calculator Section ───────────────────────────────
function CalculatorSection({ imageryStyle }) {
  return (
    <section id="calculator" className="bb-section dark" data-screen-label="04 Calculator">
      <div className="bb-container">
        <div className="bb-section-head">
          <div>
            <div className="bb-eyebrow">How much do I need?</div>
            <h2 className="bb-display">The <em>honest</em> <br />pour calculator.</h2>
          </div>
          <div>
            <p>
              Tell us about your event and we'll estimate quantities, categories
              and all-in cost — no upselling, no mystery. Move the sliders to
              see things update in real time.
            </p>
            <a href="packages.html" className="bb-cta bb-cta-accent" style={{ marginTop: 18 }}>
              See our Additional Packages
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12h14M13 5l7 7-7 7"/></svg>
            </a>
          </div>
        </div>
        <Calculator imageryStyle={imageryStyle} />
      </div>
    </section>
  );
}

// ── Contact Section ──────────────────────────────────
function ContactSection() {
  return (
    <section id="contact" className="bb-section cream" data-screen-label="05 Contact">
      <div className="bb-container">
        <div className="bb-section-head">
          <div>
            <div className="bb-eyebrow">Let's design your bar</div>
            <h2 className="bb-display">Tell us about <em>the night</em>.</h2>
          </div>
          <p>
            We book six months out for weddings and three weeks for private
            parties. The more you share now, the faster we'll come back with
            a tailored menu and quote.
          </p>
        </div>

        <div className="bb-contact">
          <aside className="bb-contact-aside">
            <h3>What happens <em>next.</em></h3>
            <ol style={{ margin: 0, paddingLeft: 18, color: "var(--ink-soft)", lineHeight: 1.7, fontSize: 15 }}>
              <li>We respond within one business day with availability.</li>
              <li>A 20-minute consultation — by phone, video or coffee.</li>
              <li>Custom menu & pricing within 72 hours.</li>
              <li>50% deposit secures your date. We handle the rest.</li>
            </ol>
            <div className="bb-contact-meta">
              <div className="bb-contact-meta-row">
                <svg className="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M21 8a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2m18 0v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8m18 0-9 6-9-6" strokeLinejoin="round" /></svg>
                <div><b>Email</b><span>hello@beeblossombar.co</span></div>
              </div>
              <div className="bb-contact-meta-row">
                <svg className="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.37 1.9.72 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.35 1.85.59 2.81.72A2 2 0 0 1 22 16.92Z" strokeLinejoin="round" /></svg>
                <div><b>Phone</b><span>(415) 555-0142</span></div>
              </div>
              <div className="bb-contact-meta-row">
                <svg className="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0Z" /><circle cx="12" cy="10" r="3" /></svg>
                <div><b>Service area</b><span>60 mi · San Francisco Bay</span></div>
              </div>
              <div className="bb-contact-meta-row">
                <svg className="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><rect x="3" y="4" width="18" height="18" rx="2" /><path d="M16 2v4M8 2v4M3 10h18" /></svg>
                <div><b>Booking window</b><span>Thursday – Sunday · year-round</span></div>
              </div>
            </div>
          </aside>
          <ContactForm />
        </div>
      </div>
    </section>
  );
}

// ── Footer ───────────────────────────────────────────
function Footer() {
  return (
    <footer className="bb-footer">
      <div className="bb-footer-inner">
        <div>
          <div className="bb-footer-brand">Bee Blossom</div>
          <p className="bb-footer-tag">A mobile cocktail bar built on local honey, seasonal botanicals, and the belief that the best drink of your life shouldn't require a reservation.</p>
        </div>
        <div>
          <h4>Visit</h4>
          <a href="#about">About us</a>
          <a href="#menu">Menu</a>
          <a href="#calculator">Calculator</a>
          <a href="#contact">Book the bar</a>
        </div>
        <div>
          <h4>Reach</h4>
          <a href="mailto:hello@beeblossombar.co">hello@beeblossombar.co</a>
          <a href="tel:+14155550142">(415) 555-0142</a>
          <a href="#">Instagram</a>
          <a href="#">Pinterest</a>
        </div>
        <div>
          <h4>Hours</h4>
          <a style={{ pointerEvents: "none" }}>Thu – Sun, by booking</a>
          <a style={{ pointerEvents: "none" }}>Studio open Tue – Wed</a>
        </div>
      </div>
      <div className="bb-footer-bottom">
        <span>© 2026 Bee Blossom Mobile Bar · Drink curiously.</span>
        <span>CA Caterer's License · ABC #62418</span>
      </div>
    </footer>
  );
}

// ── App ──────────────────────────────────────────────
function App() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const [activeSection, setActiveSection] = React.useState("top");

  // Apply tokens to :root
  React.useEffect(() => {
    const root = document.documentElement;
    const palette = PALETTES[t.palette] || PALETTES.green;
    Object.entries(palette).forEach(([k, v]) => root.style.setProperty(k, v));
    const fonts = FONT_PAIRS[t.fontPair] || FONT_PAIRS.cormorant_manrope;
    Object.entries(fonts).forEach(([k, v]) => root.style.setProperty(k, v));
  }, [t.palette, t.fontPair]);

  // Scroll-spy for active nav
  React.useEffect(() => {
    const ids = ["top", "about", "menu", "calculator", "contact"];
    const onScroll = () => {
      const y = window.scrollY + 120;
      let cur = "top";
      for (const id of ids) {
        const el = document.getElementById(id);
        if (el && el.offsetTop <= y) cur = id;
      }
      setActiveSection(cur);
    };
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  return (
    <>
      <Nav activeSection={activeSection} />
      <Hero layout={t.heroLayout} imageryStyle={t.imagery} />
      <About imageryStyle={t.imagery} />
      <MenuSection imageryStyle={t.imagery} />
      <CalculatorSection imageryStyle={t.imagery} />
      <ContactSection />
      <Footer />

      <TweaksPanel title="Tweaks">
        <TweakSection label="Palette" />
        <TweakColor label="Lead palette"
                    value={t.palette === "green" ? ["#2f5d3a", "#d97433", "#c69a3c", "#faf6ea"] :
                           t.palette === "orange" ? ["#d97433", "#2f5d3a", "#c69a3c", "#fbf7ea"] :
                           t.palette === "gold" ? ["#c69a3c", "#2f5d3a", "#d97433", "#fbf6e2"] :
                           ["#0f1e14", "#c69a3c", "#e07b2a", "#f3eddb"]}
                    options={[
                      ["#2f5d3a", "#d97433", "#c69a3c", "#faf6ea"],
                      ["#d97433", "#2f5d3a", "#c69a3c", "#fbf7ea"],
                      ["#c69a3c", "#2f5d3a", "#d97433", "#fbf6e2"],
                      ["#0f1e14", "#c69a3c", "#e07b2a", "#f3eddb"],
                    ]}
                    onChange={(v) => {
                      const map = {
                        '["#2f5d3a","#d97433","#c69a3c","#faf6ea"]': "green",
                        '["#d97433","#2f5d3a","#c69a3c","#fbf7ea"]': "orange",
                        '["#c69a3c","#2f5d3a","#d97433","#fbf6e2"]': "gold",
                        '["#0f1e14","#c69a3c","#e07b2a","#f3eddb"]': "forest",
                      };
                      setTweak("palette", map[JSON.stringify(v)] || "green");
                    }} />

        <TweakSection label="Typography" />
        <TweakSelect label="Font pairing" value={t.fontPair}
                     options={[
                       { value: "cormorant_manrope", label: "Cormorant / Manrope" },
                       { value: "playfair_dmsans", label: "Playfair / DM Sans" },
                       { value: "italiana_workSans", label: "Italiana / Work Sans" },
                     ]}
                     onChange={(v) => setTweak("fontPair", v)} />

        <TweakSection label="Imagery" />
        <TweakRadio label="Placeholder style" value={t.imagery}
                    options={[
                      { value: "stripes", label: "Stripes" },
                      { value: "botanical", label: "Botanical" },
                    ]}
                    onChange={(v) => setTweak("imagery", v)} />

        <TweakSection label="Hero" />
        <TweakSelect label="Layout" value={t.heroLayout}
                     options={[
                       { value: "split", label: "Split (text + art)" },
                       { value: "centered", label: "Centered" },
                       { value: "editorial", label: "Editorial / asymmetric" },
                     ]}
                     onChange={(v) => setTweak("heroLayout", v)} />
      </TweaksPanel>
    </>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
