/* global React */
const { useEffect, useRef, useState } = React;

const LINKS = {
  booksy: "https://jcutzzllc.booksy.com/j/",
  ig: "https://www.instagram.com/jcutzz_llc/",
  maps: "https://www.google.com/maps/dir/?api=1&destination=3122+W+Indian+School+Rd,+Phoenix,+AZ+85017",
};

/* ---------- Light streaks ---------- */
function Streaks({ count = 12 }) {
  const items = Array.from({ length: count }, (_, i) => {
    const left = (i * 8.7 + 5) % 100;
    const delay = (i * 0.5) % 6;
    const dur = 5 + ((i * 1.3) % 4);
    const h = 60 + ((i * 17) % 140);
    return (
      <span
        key={i}
        className="streak"
        style={{ left: `${left}%`, height: `${h}px`, animationDelay: `${delay}s`, animationDuration: `${dur}s` }}
      />
    );
  });
  return <div className="streaks">{items}</div>;
}

/* ---------- Icons ---------- */
const Icons = {
  haircut: (
    <svg width="28" height="28" viewBox="0 0 32 32" fill="none" stroke="#ededf2" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="9" cy="9" r="4" /><circle cx="9" cy="23" r="4" />
      <path d="M12 11 L28 21" /><path d="M12 21 L28 11" />
    </svg>
  ),
  fade: (
    <svg width="28" height="28" viewBox="0 0 32 32" fill="none" stroke="#ededf2" strokeWidth="1.4">
      <path d="M4 24 L28 24" /><path d="M4 20 L28 20" opacity=".75" />
      <path d="M4 16 L28 16" opacity=".5" /><path d="M4 12 L28 12" opacity=".3" /><path d="M4 8 L28 8" opacity=".15" />
    </svg>
  ),
  beard: (
    <svg width="28" height="28" viewBox="0 0 32 32" fill="none" stroke="#ededf2" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M8 10 C8 18 11 26 16 26 C21 26 24 18 24 10" />
      <path d="M8 10 L24 10" /><circle cx="13" cy="14" r="1" fill="#ededf2" /><circle cx="19" cy="14" r="1" fill="#ededf2" />
    </svg>
  ),
  kid: (
    <svg width="28" height="28" viewBox="0 0 32 32" fill="none" stroke="#ededf2" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="16" cy="11" r="6" />
      <path d="M9 11 C9 7 12 5 16 5 C20 5 23 7 23 11" />
      <path d="M9 24 C9 18 23 18 23 24" /><path d="M9 24 L9 28" /><path d="M23 24 L23 28" />
    </svg>
  ),
  mobile: (
    <svg width="28" height="28" viewBox="0 0 32 32" fill="none" stroke="#ededf2" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <rect x="9" y="3" width="14" height="26" rx="2" />
      <path d="M14 25 L18 25" />
      <circle cx="16" cy="11" r="2.5" /><path d="M11.5 17 L20.5 17" />
    </svg>
  ),
  pin: (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M12 2 C8 2 5 5 5 9 C5 14 12 22 12 22 C12 22 19 14 19 9 C19 5 16 2 12 2 Z" />
      <circle cx="12" cy="9" r="2.5" />
    </svg>
  ),
  clock: (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="9" /><path d="M12 7 L12 12 L15 14" />
    </svg>
  ),
  ig: (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6">
      <rect x="3" y="3" width="18" height="18" rx="5" />
      <circle cx="12" cy="12" r="4" /><circle cx="17.5" cy="6.5" r="1" fill="currentColor" />
    </svg>
  ),
  arrow: (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M2 8 H13" /><path d="M9 4 L13 8 L9 12" />
    </svg>
  ),
};

/* ---------- Reveal hook ---------- */
function useReveal() {
  useEffect(() => {
    const els = document.querySelectorAll(".reveal");
    const io = new IntersectionObserver(
      (entries) => {
        entries.forEach((e) => {
          if (e.isIntersecting) {
            e.target.classList.add("in");
            io.unobserve(e.target);
          }
        });
      },
      { threshold: 0.12, rootMargin: "0px 0px -60px 0px" }
    );
    els.forEach((el) => io.observe(el));
    return () => io.disconnect();
  }, []);
}

/* ---------- Nav ---------- */
function Nav() {
  const [scrolled, setScrolled] = useState(false);
  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 30);
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  return (
    <nav className={`nav ${scrolled ? "scrolled" : ""}`}>
      <div className="wrap nav-inner">
        <div className="nav-logo chrome chrome-shine" data-text="JCUTZZ">JCUTZZ</div>
        <div className="nav-links">
          <a href="#services">Services</a>
          <a href="#work">Work</a>
          <a href="#visit">Visit</a>
        </div>
        <a className="btn btn-red" href={LINKS.booksy} target="_blank" rel="noreferrer" style={{ padding: "10px 16px" }}>
          Book Now {Icons.arrow}
        </a>
      </div>
    </nav>
  );
}

/* ---------- Hero ---------- */
function Hero() {
  return (
    <section className="hero">
      <div className="hero-bg">
        <img className="hero-bg-img" src="assets/hero/hero.jpg" alt="" />
        <div className="hero-vignette" />
        <Streaks count={10} />
      </div>

      <div className="wrap hero-content">
        <div className="hero-meta reveal">
          <span className="eyebrow"><span className="dot" />Phoenix, AZ · By Appointment</span>
          <span className="divider" />
          <span className="eyebrow">Private Studio · Mobile Available</span>
        </div>

        <h1 className="display hero-title chrome chrome-shine reveal delay-1" data-text="JCUTZZ">JCUTZZ</h1>

        <div className="hero-tag reveal delay-2">
          <h2><span className="red-bar" />Precision Cuts.<br />Premium Experience.</h2>
        </div>

        <p className="hero-sub reveal delay-3">
          Phoenix's private barber studio. Book on Booksy or DM for mobile service.
        </p>

        <div className="hero-cta reveal delay-4">
          <a href={LINKS.booksy} target="_blank" rel="noreferrer" className="btn btn-red pulse">Book on Booksy {Icons.arrow}</a>
          <a href="#work" className="btn btn-chrome">See Cuts {Icons.arrow}</a>
          <a href={LINKS.ig} target="_blank" rel="noreferrer" className="btn btn-ghost">
            {Icons.ig} DM for Mobile
          </a>
        </div>

        <div className="hero-stats reveal delay-5">
          <div className="hero-stat">
            <div className="k chrome">5★</div>
            <div className="v">Client Rated</div>
          </div>
          <div className="hero-stat">
            <div className="k chrome">PHX</div>
            <div className="v">Indian School Rd</div>
          </div>
          <div className="hero-stat">
            <div className="k chrome">WED/SAT</div>
            <div className="v">9 to 7</div>
          </div>
          <div className="hero-stat">
            <div className="k chrome">1:1</div>
            <div className="v">Private Studio</div>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ---------- About ---------- */
function About() {
  return (
    <section id="about" className="about">
      <div className="wrap">
        <div className="about-grid">
          <div className="about-copy reveal">
            <span className="eyebrow"><span className="dot" />01 / The Studio</span>
            <h3 className="chrome chrome-shine" data-text="A Cut Above. By Design.">A Cut Above.<br />By Design.</h3>
            <p>
              Private studio in Phoenix. <strong>One chair, one client, one standard.</strong> Mobile service available across the valley.
            </p>
            <ul className="about-points">
              <li>By Appointment</li>
              <li>Single-Client Sessions</li>
              <li>Sanitized Tools</li>
              <li>Mobile Available</li>
              <li>Consult Included</li>
              <li>Booksy Booking</li>
            </ul>
          </div>

          <div className="about-card reveal delay-2">
            <img className="about-card-img" src="assets/about/about.jpg" alt="JCUTZZ barber at work" />
            <div className="about-card-tint" />
            <div className="corners"><span className="tl" /><span className="tr" /><span className="bl" /><span className="br" /></div>
            <div className="badge">
              <span className="star chrome">★</span>
              <div className="txt">5-Star Barber<br /><small>Phoenix · Mobile Avail.</small></div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ---------- Services ---------- */
const SERVICES = [
  { n: "01", icon: Icons.haircut, title: "Haircut",          price: "$50" },
  { n: "02", icon: Icons.beard,   title: "Beard",            price: "$20" },
  { n: "03", icon: Icons.fade,    title: "Haircut + Beard",  price: "$60" },
  { n: "04", icon: Icons.kid,     title: "Kid's Haircut",    price: "$35" },
];

function Services() {
  return (
    <section id="services" className="services">
      <div className="wrap">
        <div className="section-head reveal">
          <div className="left">
            <span className="eyebrow"><span className="dot" />02 / The Menu</span>
            <h2 className="chrome chrome-shine" data-text="Services">Services</h2>
          </div>
          <p>Pick a service. Book it on Booksy. Or DM me for mobile.</p>
        </div>

        <div className="services-grid services-grid-4">
          {SERVICES.map((s, i) => (
            <a
              key={s.title}
              href={LINKS.booksy}
              target="_blank" rel="noreferrer"
              className={`service service-link reveal delay-${(i % 4) + 1}`}
            >
              <div className="num">{s.n} / 05</div>
              <div className="icon-wrap">{s.icon}</div>
              <h3>{s.title}</h3>
              <div className="price"><span className="price-num">{s.price}</span></div>
              <span className="service-cta">Book on Booksy {Icons.arrow}</span>
            </a>
          ))}
        </div>

        <a
          href={LINKS.ig}
          target="_blank" rel="noreferrer"
          className="service-mobile reveal delay-2"
        >
          <div className="service-mobile-icon">{Icons.mobile}</div>
          <div className="service-mobile-copy">
            <div className="num">05 / 05</div>
            <h3>Mobile Service</h3>
            <p>I come to you. Anywhere in the valley. DM me to set it up.</p>
          </div>
          <div className="service-mobile-cta">
            <span className="price-num">DM Me</span>
            <span className="service-cta">{Icons.ig} On Instagram {Icons.arrow}</span>
          </div>
        </a>
      </div>
    </section>
  );
}

Object.assign(window, { Streaks, Icons, useReveal, Nav, Hero, About, Services, LINKS });
