// Shared atoms: logo mark, icons, placeholders
const { useState, useEffect, useRef, useMemo } = React;

const LogoMark = ({ size = 40, className = "" }) => (
  <img
    src="/assets/favicon.png"
    alt=""
    className={className}
    aria-hidden="true"
    style={{width: size, height: size, objectFit: "contain", display: "inline-block"}}
  />
);

const Brand = ({ dark = false, href = "/", onClick }) => (
  <a className="brand" href={href} onClick={onClick} style={{alignItems: "center"}}>
    <img src="/assets/caaba-logo.png" alt="CAABA — Central Asian American Bar Association"
      style={{
        height: "clamp(58px, 9vw, 76px)",
        width: "auto",
        display: "block",
      }}/>
  </a>
);

const Arrow = ({ size = 14 }) => (
  <svg width={size} height={size} viewBox="0 0 16 16" className="arr" fill="none" aria-hidden="true">
    <path d="M1 8H15M15 8L9 2M15 8L9 14" stroke="currentColor" strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round"/>
  </svg>
);

// Image placeholder — subtly striped, monospace label
const Placeholder = ({ label = "image", ratio = "4/5", tone = "paper", className = "", style = {} }) => {
  const isDark = tone === "ink";
  return (
    <div className={className} style={{
      aspectRatio: ratio,
      width: "100%",
      background: isDark
        ? "repeating-linear-gradient(135deg, #132537 0 8px, #0f2031 8px 16px)"
        : "repeating-linear-gradient(135deg, #ede7d8 0 8px, #e5dcc4 8px 16px)",
      border: `1px solid ${isDark ? "#2A3B4D" : "#D9D0BB"}`,
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      color: isDark ? "#8A9099" : "#8a7d60",
      fontFamily: "var(--mono)",
      fontSize: 11,
      letterSpacing: "0.18em",
      textTransform: "uppercase",
      ...style
    }}>
      {label}
    </div>
  );
};

// Headshot placeholder — monogram in a circle with gold ring
const Headshot = ({ name = "", size = 88 }) => {
  const initials = name.split(" ").map(w => w[0]).join("").slice(0,2).toUpperCase();
  // deterministic soft hue per name
  const hash = name.split("").reduce((a,c) => a + c.charCodeAt(0), 0);
  const hues = [30, 210, 195, 40, 220, 180];
  const hue = hues[hash % hues.length];
  return (
    <div style={{
      width: size, height: size, borderRadius: "50%",
      background: `radial-gradient(circle at 30% 30%, oklch(0.85 0.02 ${hue}), oklch(0.7 0.03 ${hue}))`,
      border: "1px solid var(--gold)",
      boxShadow: "inset 0 0 0 4px var(--paper-3)",
      display: "flex", alignItems: "center", justifyContent: "center",
      fontFamily: "var(--serif)",
      fontSize: size * 0.34,
      color: "var(--ink)",
      letterSpacing: "0.02em",
      flexShrink: 0,
    }}>{initials}</div>
  );
};

// Monochrome pillar icon — thin line glyphs
const PillarIcon = ({ name, size = 28 }) => {
  const s = size;
  const common = { width: s, height: s, viewBox: "0 0 32 32", fill: "none", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeLinejoin: "round" };
  const glyphs = {
    development: (<svg {...common}><path d="M6 26V14M12 26V8M18 26V18M24 26V11"/><circle cx="6" cy="11" r="1.4"/><circle cx="12" cy="5" r="1.4"/><circle cx="18" cy="15" r="1.4"/><circle cx="24" cy="8" r="1.4"/></svg>),
    network: (<svg {...common}><circle cx="16" cy="16" r="3"/><circle cx="6" cy="6" r="2"/><circle cx="26" cy="6" r="2"/><circle cx="6" cy="26" r="2"/><circle cx="26" cy="26" r="2"/><path d="M8 7L14 14M24 7L18 14M8 25L14 18M24 25L18 18"/></svg>),
    mentor: (<svg {...common}><circle cx="16" cy="10" r="4"/><path d="M7 26c0-5 4-9 9-9s9 4 9 9"/><path d="M11 4l2 2M21 4l-2 2"/></svg>),
    referral: (<svg {...common}><path d="M4 16l6-6 6 6 6-6 6 6"/><path d="M4 22h24"/><circle cx="10" cy="10" r="1.4"/><circle cx="22" cy="10" r="1.4"/></svg>),
    visibility: (<svg {...common}><circle cx="16" cy="16" r="10"/><path d="M2 16h4M26 16h4M16 2v4M16 26v4"/><circle cx="16" cy="16" r="3"/></svg>),
    global: (<svg {...common}><circle cx="16" cy="16" r="12"/><ellipse cx="16" cy="16" rx="5" ry="12"/><path d="M4 16h24"/></svg>),
    bridge: (<svg {...common}><path d="M4 22V14M28 22V14M4 14c6 0 10-4 12-4s6 4 12 4"/><path d="M10 22V16M16 22V14M22 22V16"/><path d="M2 26h28"/></svg>),
    future: (<svg {...common}><path d="M16 4v8M16 12l-6 8h12l-6-8"/><rect x="6" y="20" width="20" height="8"/><path d="M10 24h2M14 24h2M18 24h2"/></svg>),
  };
  return <span style={{color: "var(--gold-2)", display: "inline-flex"}}>{glyphs[name] || glyphs.network}</span>;
};

Object.assign(window, { LogoMark, Brand, Arrow, Placeholder, Headshot, PillarIcon });
