// Shared UI atoms & icons for DealVault
// Exposes globals via window.* at the bottom.

const { useState, useEffect, useRef, useCallback, useMemo } = React;

/* ──────────────────────────────────────────────────────────
   Logo / Brand
   ────────────────────────────────────────────────────────── */
function LogoMark({ size = 28, color }) {
  return (
    <img
      src="assets/logo-mark.png"
      alt="DealVault"
      width={size}
      height={size}
      style={{
        width: size,
        height: size,
        objectFit: "contain",
        // Auto-invert for dark theme since the mark is solid black
        filter: "var(--logo-invert, none)",
        display: "block",
      }}
    />
  );
}

function BrandLockup({ tagline = false }) {
  return (
    <div className="brand" aria-label="DealVault">
      <span className="brand-mark"><LogoMark size={28} /></span>
      <span>DealVault</span>
      {tagline && (
        <span
          className="mono"
          style={{
            fontSize: 10,
            letterSpacing: "0.22em",
            color: "var(--muted)",
            marginLeft: 8,
            textTransform: "uppercase",
            borderLeft: "1px solid var(--line)",
            paddingLeft: 10,
          }}
        >
          Media Partnership Advisory
        </span>
      )}
    </div>
  );
}

/* ──────────────────────────────────────────────────────────
   Reveal-on-scroll hook
   ────────────────────────────────────────────────────────── */
function useReveal() {
  useEffect(() => {
    const els = document.querySelectorAll(".reveal:not(.in)");
    if (!("IntersectionObserver" in window)) {
      els.forEach((el) => el.classList.add("in"));
      return;
    }
    const io = new IntersectionObserver(
      (entries) => {
        entries.forEach((e) => {
          if (e.isIntersecting) {
            e.target.classList.add("in");
            io.unobserve(e.target);
          }
        });
      },
      { rootMargin: "0px 0px -10% 0px", threshold: 0.05 }
    );
    els.forEach((el) => io.observe(el));
    return () => io.disconnect();
  });
}

/* ──────────────────────────────────────────────────────────
   Icons
   ────────────────────────────────────────────────────────── */
const ArrowUR = ({ size = 14 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden>
    <path d="M7 17 17 7M9 7h8v8" stroke="currentColor" strokeWidth="2" strokeLinecap="square" />
  </svg>
);
const ArrowR = ({ size = 14 }) => (
  <svg className="arr" width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden>
    <path d="M5 12h14M13 6l6 6-6 6" stroke="currentColor" strokeWidth="2" strokeLinecap="square" />
  </svg>
);
const Check = ({ size = 16 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden>
    <path d="M5 12.5 10 18l9-12" stroke="currentColor" strokeWidth="2.5" strokeLinecap="square" />
  </svg>
);
const X = ({ size = 14 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden>
    <path d="M6 6l12 12M18 6 6 18" stroke="currentColor" strokeWidth="2" strokeLinecap="square" />
  </svg>
);
const Plus = ({ size = 14 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden>
    <path d="M12 5v14M5 12h14" stroke="currentColor" strokeWidth="2" strokeLinecap="square" />
  </svg>
);

Object.assign(window, {
  LogoMark,
  BrandLockup,
  useReveal,
  ArrowUR,
  ArrowR,
  Check,
  X,
  Plus,
});
