// HeroStreak.jsx — alternate hero with a "never-ending" light streak (Streak-style).
// Same copy as Hero.jsx; the background swaps the looping video for a layered
// system: a static lit arc (base art) + drifting ambient bloom + an SVG path
// carrying a bright white highlight that flows along the arc forever. The arc
// path is the exact curve from the source art (3832×1642), extended off-screen
// at both ends so the moving highlight is born and dies out of view.

function StarRating({ brand, alt, brandH, score, kind, base = 2.1, step = 0.15 }) {
  const STARS = 5;
  const [rated, setRated] = useState(false);
  const starsRef = useRef(null);
  useEffect(() => {
    const whiteAt = (base + (STARS - 1) * step + 0.5) * 1000;
    const t = setTimeout(() => setRated(true), whiteAt);
    return () => clearTimeout(t);
  }, []);
  // pointer-following spotlight: brand color blooms under the cursor across the stars
  const track = (e) => {
    const el = starsRef.current; if (!el) return;
    const r = el.getBoundingClientRect();
    el.style.setProperty("--mx", (e.clientX - r.left).toFixed(1) + "px");
    el.style.setProperty("--my", (e.clientY - r.top).toFixed(1) + "px");
  };
  const reset = () => {
    const el = starsRef.current; if (!el) return;
    el.style.setProperty("--mx", "-200px");
  };
  return (
    <div className={"rating-badge rating-anim badge-" + kind + (rated ? " is-rated" : "")}
      onPointerMove={track} onPointerLeave={reset}>
      <img className="rating-brand" src={assetUrl(brand)} alt={alt} style={{ height: brandH }} />
      <span className="rating-div" />
      <span ref={starsRef} className="rating-stars" aria-label={`${score} out of 5 stars`}>
        {Array.from({ length: STARS }).map((_, i) => (
          <span key={i} className="rstar" style={{ animationDelay: (base + i * step).toFixed(2) + "s" }}>★</span>
        ))}
      </span>
      <b className="rating-score" style={{ animationDelay: (base + (STARS - 1) * step + 0.55).toFixed(2) + "s" }}>{score}</b>
    </div>
  );
}

function Hero() {
  return (
    <header id="top" className="hh-hero" style={{ position: "relative", overflow: "hidden", paddingTop: 74 }}>
      <div className="haze-bloom" style={{ opacity: 0.4 }} />

      <div className="wrap" style={{ position: "relative", zIndex: 2, paddingTop: 64, paddingBottom: 80 }}>
        <div className="hero-grid" style={{ display: "grid", gridTemplateColumns: "minmax(0,1fr) 560px", gap: 56, alignItems: "center" }}>
          {/* copy */}
          <div>
            <div className="eyebrow">
              <span className="dot ld-word" style={{ animationDelay: ".2s" }} />
              <span><WordWaves text="Human-led Shopify CRO audits" base={0.2} step={0.08} /></span>
            </div>
            <h1 className="hero-h1" style={{
              fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 56, lineHeight: 1.05,
              letterSpacing: "-0.02em", color: "var(--fg1)", margin: "20px 0 0", textWrap: "balance",
            }}>
              <WordWaves base={0.35} step={0.07} text="Find what’s costing you conversions." />
            </h1>
            <p className="hero-sub" style={{
              fontFamily: "var(--font-body)", fontWeight: 300, fontSize: 18, lineHeight: 1.6,
              color: "var(--fg2)", margin: "24px 0 0", maxWidth: 520,
            }}>
              <WordWaves base={0.9} step={0.04} text="Conversion Works connects to Shopify, GA4, GTM, and store context, then turns your funnel data into a one-week audit roadmap with 5 prioritized fixes your team can ship, test, and measure." />
            </p>
            <div className="hero-rise hero-cta-row" style={{ display: "flex", gap: 14, marginTop: 34, flexWrap: "wrap", animationDelay: "1.05s" }}>
              <a href="#cta" className="btn btn-primary">Book a Shopify audit consult <i className="ri-arrow-right-line" /></a>
              <a href="#cta" className="btn btn-secondary">Get 5 free fixes</a>
            </div>
            <div className="hero-rise hero-ratings" style={{ animationDelay: "1.35s" }}>
              <StarRating brand="assets/clutch-wordmark.png" alt="Clutch" brandH={15} score="5.0" kind="clutch" base={1.45} />
              <StarRating brand="assets/trustpilot-wordmark.png" alt="Trustpilot" brandH={14} score="4.8" kind="trustpilot" base={1.6} />
            </div>
          </div>

          {/* looping store-surrounded-by-CRO-surfaces visual */}
          <div className="hs-col hero-rise" style={{ animationDelay: "0.45s" }}>
            <HeroScene />
          </div>
        </div>
      </div>
      <div className="streak" />
    </header>
  );
}

Object.assign(window, { Hero });
