/* global React */
/* ═══ MIROR NUM — Shared components ═══ */

/* Monogramme « M » avec filet et reflet (marque Miror Num) */
window.HCSymbol = function HCSymbol({ size = 40, color = "var(--ink)", accent = "var(--clay)" }) {
  const gid = "mn-reflect-" + Math.round(size);
  return (
    <svg viewBox="0 0 130 130" width={size} height={size} aria-hidden="true" style={{ display: "block" }}>
      <defs>
        <linearGradient id={gid} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor={accent} stopOpacity="0" />
          <stop offset="0.55" stopColor={accent} stopOpacity="0" />
          <stop offset="1" stopColor={accent} stopOpacity="0.4" />
        </linearGradient>
      </defs>
      <text x="65" y="72" textAnchor="middle" fontFamily="Satoshi, sans-serif" fontWeight="700" fontSize="66" letterSpacing="-3" fill={color}>M</text>
      <rect x="37" y="77" width="56" height="1.6" fill={accent} />
      <g transform="translate(0,154) scale(1,-1)">
        <text x="65" y="72" textAnchor="middle" fontFamily="Satoshi, sans-serif" fontWeight="700" fontSize="66" letterSpacing="-3" fill={`url(#${gid})`}>M</text>
      </g>
    </svg>
  );
};

/* Horizontal logo lockup */
window.Logo = function Logo({ symbolSize = 38, nameSize = 21, color = "var(--ink)", accent = "var(--clay)", href = "#top", onClick }) {
  return (
    <a className="logo" href={href} onClick={onClick} aria-label="Miror Num">
      <span className="sym"><window.HCSymbol size={symbolSize} color={color} accent={accent} /></span>
      <span className="name" style={{ fontSize: nameSize, color }}>
        Miror <em style={{ color: accent }}>Num</em>
      </span>
    </a>
  );
};

/* Stacked logo (footer / hero) */
window.LogoStack = function LogoStack({ symbolSize = 64, nameSize = 30, color = "var(--ink)", accent = "var(--clay)", tagline }) {
  return (
    <div className="logo stack">
      <span className="sym"><window.HCSymbol size={symbolSize} color={color} accent={accent} /></span>
      <span className="name" style={{ fontSize: nameSize, color }}>
        Miror <em style={{ color: accent }}>Num</em>
      </span>
      {tagline && <span className="tag" style={{ color }}>{tagline}</span>}
    </div>
  );
};

/* Line icons (stroke, brown) */
window.Icon = function Icon({ name, size = 28, color = "currentColor", stroke = 1.4 }) {
  const common = { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: stroke, strokeLinecap: "round", strokeLinejoin: "round" };
  const paths = {
    phone: <path d="M5 4h3l1.5 4.5L7.5 10a11 11 0 0 0 5 5l1.5-2 4.5 1.5V18a2 2 0 0 1-2 2A14 14 0 0 1 3 6a2 2 0 0 1 2-2z" />,
    video: <><rect x="3" y="6" width="12" height="12" rx="2" /><path d="m15 10 6-3v10l-6-3" /></>,
    mail: <><rect x="3" y="5" width="18" height="14" rx="2" /><path d="m3 7 9 6 9-6" /></>,
    lock: <><rect x="5" y="11" width="14" height="9" rx="1.5" /><path d="M8 11V8a4 4 0 0 1 8 0v3" /></>,
    arrow: <path d="M5 12h14M13 6l6 6-6 6" />,
    instagram: <><rect x="3" y="3" width="18" height="18" rx="5" /><circle cx="12" cy="12" r="4" /><circle cx="16.8" cy="7.2" r="1.1" fill="currentColor" stroke="none" /></>
  };
  return <svg {...common} aria-hidden="true">{paths[name]}</svg>;
};

/* Renders a multi-line title array where each line may contain <em> html */
window.Title = function Title({ lines, className = "h2" }) {
  return (
    <h2 className={className}>
      {lines.map((ln, i) => (
        <React.Fragment key={i}>
          <span dangerouslySetInnerHTML={{ __html: ln }} />
          {i < lines.length - 1 && <br />}
        </React.Fragment>
      ))}
    </h2>
  );
};

window.HtmlText = function HtmlText({ html, as = "span", className, style }) {
  const Tag = as;
  return <Tag className={className} style={style} dangerouslySetInnerHTML={{ __html: html }} />;
};

/* Scroll-reveal wrapper */
window.Reveal = function Reveal({ children, className = "", style, delay = 0 }) {
  const ref = React.useRef(null);
  React.useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting) { setTimeout(() => el.classList.add("in"), delay); io.unobserve(el); }
      });
    }, { threshold: 0.12, rootMargin: "0px 0px -40px 0px" });
    io.observe(el);
    return () => io.disconnect();
  }, [delay]);
  return <div ref={ref} className={`reveal ${className}`} style={style}>{children}</div>;
};
