const { useState, useEffect, useRef } = React;

function Reveal({ children, as: Tag = "div", className = "", delay = 0, ...props }) {
  const ref = useRef(null);
  const [visible, setVisible] = useState(false);

  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const observer = new IntersectionObserver(
      ([entry]) => {
        if (entry.isIntersecting) {
          setVisible(true);
          observer.unobserve(el);
        }
      },
      { threshold: 0.15 }
    );
    observer.observe(el);
    return () => observer.disconnect();
  }, []);

  return (
    <Tag
      ref={ref}
      className={`reveal ${visible ? "visible" : ""} ${className}`}
      style={{ transitionDelay: `${delay}ms` }}
      {...props}
    >
      {children}
    </Tag>
  );
}

const NAV_LINKS = [
  { label: "Home", href: "#home" },
  { label: "Tour", href: "#tour" },
  { label: "Music", href: "#music" },
  { label: "Contact", href: "#contact" },
];

const TOUR_DATES = [
  { date: "JAN 17", city: "Example City, US", venue: "The Grand Hall" },
  { date: "FEB 02", city: "Sample Town, UK", venue: "Harbor Arena" },
  { date: "FEB 21", city: "Demo City, DE", venue: "Nordhalle" },
  { date: "MAR 09", city: "Placeholder, NL", venue: "Riverside Club" },
];

const RELEASES = [
  { title: "Latest Single", sub: "2026 Release" },
  { title: "Label Imprint One", sub: "Compilation" },
  { title: "Label Imprint Two", sub: "Compilation" },
];

const SOCIALS = ["IG", "X", "YT", "SC", "SP"];

function Nav() {
  const [open, setOpen] = useState(false);
  return (
    <header className="nav">
      <a className="nav-logo" href="#home">ANNA&nbsp;MARIA&nbsp;BARTH</a>
      <button className="nav-toggle" onClick={() => setOpen(!open)} aria-label="Toggle menu">
        {open ? "✕" : "☰"}
      </button>
      <nav className={`nav-links ${open ? "open" : ""}`}>
        {NAV_LINKS.map((l) => (
          <a key={l.href} href={l.href} onClick={() => setOpen(false)}>{l.label}</a>
        ))}
      </nav>
    </header>
  );
}

function Hero() {
  return (
    <section id="home" className="hero">
      <div className="hero-bg" style={{ backgroundImage: "url('assets/portrait.png')" }} />
      <div className="hero-overlay" />
      <div className="hero-content">
        <h1>ANNA MARIA BARTH</h1>
        <p>Placeholder tagline — swap in your own bio line here.</p>
      </div>
      <a className="scroll-hint" href="#tour">Scroll Down ↓</a>
    </section>
  );
}

function Tour() {
  return (
    <section id="tour" className="tour">
      <Reveal as="h2">Tour Dates</Reveal>
      <div className="tour-list">
        {TOUR_DATES.map((t, i) => (
          <Reveal as="div" className="tour-card" key={i} delay={i * 80}>
            <div className="tour-date">{t.date}</div>
            <div className="tour-info">
              <div className="tour-venue">{t.venue}</div>
              <div className="tour-city">{t.city}</div>
            </div>
            <a className="btn" href="#">Tickets</a>
          </Reveal>
        ))}
      </div>
    </section>
  );
}

function Music() {
  return (
    <section id="music" className="music">
      <Reveal as="h2">Music</Reveal>
      <div className="release-grid">
        {RELEASES.map((r, i) => (
          <Reveal as="div" className="release-card" key={i} delay={i * 100}>
            <div className="release-art" />
            <div className="release-title">{r.title}</div>
            <div className="release-sub">{r.sub}</div>
            <a className="btn btn-outline" href="#">Listen</a>
          </Reveal>
        ))}
      </div>
    </section>
  );
}

function Socials() {
  return (
    <div className="socials">
      {SOCIALS.map((s) => (
        <a key={s} href="#" className="social-icon" aria-label={s}>{s}</a>
      ))}
    </div>
  );
}

function Footer() {
  return (
    <footer id="contact" className="footer">
      <Reveal as="div">
        <Socials />
        <p className="footer-text">© 2026 Anna Maria Barth. All rights reserved.</p>
        <div className="footer-links">
          <a href="#">Privacy Policy</a>
          <a href="#">Cookie Policy</a>
        </div>
      </Reveal>
    </footer>
  );
}

function App() {
  return (
    <>
      <Nav />
      <Hero />
      <Tour />
      <Music />
      <Footer />
    </>
  );
}

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