// Shared brand components — Logo, Bracket, Badge, ButtonGroup, etc.

// ── Logo glyph ───────────────────────────────────────
function ArbLogo({ size = 32, variant = 'gold-mono' }) {
  // Geometric "A" letterform — simplified construction
  const stroke = variant === 'black-gold' ? '#0D0D0D' : 'currentColor';
  const goldId = `lg-${size}-${variant}`;
  if (variant === 'gold-gradient') {
    return (
      <svg width={size} height={size} viewBox="0 0 64 64" className="logo-glyph">
        <defs>
          <linearGradient id={goldId} x1="0" y1="0" x2="1" y2="1">
            <stop offset="0%" stopColor="#E6C44A" />
            <stop offset="50%" stopColor="#D4AF37" />
            <stop offset="100%" stopColor="#B8941B" />
          </linearGradient>
        </defs>
        <g fill="none" stroke={`url(#${goldId})`} strokeWidth="3">
          <path d="M8 56 L32 8 L56 56" strokeLinejoin="miter" />
          <path d="M18 36 L46 36" />
          <rect x="2" y="2" width="60" height="60" opacity="0.2" />
        </g>
      </svg>
    );
  }
  if (variant === 'black-gold') {
    return (
      <svg width={size} height={size} viewBox="0 0 64 64" className="logo-glyph">
        <g fill="none" strokeWidth="3">
          <path d="M8 56 L32 8 L56 56" stroke="#0D0D0D" strokeLinejoin="miter" />
          <path d="M18 36 L46 36" stroke="#D4AF37" />
          <rect x="2" y="2" width="60" height="60" stroke="#0D0D0D" opacity="0.2" />
        </g>
      </svg>
    );
  }
  // gold-mono (default)
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" className="logo-glyph" style={{ color: '#D4AF37' }}>
      <g fill="none" stroke="currentColor" strokeWidth="3">
        <path d="M8 56 L32 8 L56 56" strokeLinejoin="miter" />
        <path d="M18 36 L46 36" />
        <rect x="2" y="2" width="60" height="60" opacity="0.25" />
      </g>
    </svg>
  );
}

function ArbWordmark({ size = 11, variant = 'gold-mono' }) {
  return (
    <span style={{ display: 'inline-flex', alignItems: 'center', gap: 10 }}>
      <ArbLogo size={size * 1.6} variant={variant} />
      <span className="mono" style={{
        fontSize: size,
        fontWeight: 700,
        letterSpacing: '0.18em',
      }}>[ ARB CAPITAL ]</span>
    </span>
  );
}

// ── Bracket box wrapper ──────────────────────────────
function Brackets({ children, style, className = '' }) {
  return (
    <div className={`brackets ${className}`} style={style}>
      <span className="bc-bl" />
      <span className="bc-br" />
      {children}
    </div>
  );
}

// ── Section number label ─────────────────────────────
function SectionNum({ n, label }) {
  const num = String(n).padStart(2, '0');
  return (
    <div className="section-num">
      <span>[ {num} ]</span>
      <span className="div" />
      <span>{label}</span>
    </div>
  );
}

// ── File-type icon — Arb brand "A" mark in an outlined box ─────
// Same brand glyph for every file kind (brand-assets/logos/logo-gold.svg).
// File type is already conveyed by the card's title + status label, so the
// icon's job is to read as "Arb document" at a glance.
function FileIcon({ kind, size = 28 }) {
  const cls = `ft-${kind.toLowerCase()}`;
  const glyph = Math.round(size * 0.62);
  return (
    <div style={{
      width: size * 0.8, height: size,
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      border: '1px solid var(--border)',
      color: '#D4AF37',
    }} className={cls}>
      <svg width={glyph} height={glyph} viewBox="0 0 256 256" fill="none" style={{ display: 'block' }}>
        <path d="M 134.07,19.18 C 131.86,15.09 129.34,15 126.96,15 C 124.58,15 122.11,15.31 119.81,19.18 L 5.78,233.28 C 4.17,236.38 5.17,240.99 10.02,240.99 H 85.78 C 91.91,240.99 95.47,234.98 96.39,233.09 L 136.48,158.41 H 93.41 L 127.23,94.51 L 202.81,233.09 C 205.61,238.14 207.73,240.43 211.58,240.43 H 246.09 C 250.68,240.43 252.11,236.11 250.22,232.64 L 134.07,19.18 Z" fill="currentColor" />
      </svg>
    </div>
  );
}

// ── Watermark layer ──────────────────────────────────
function Watermark({ email }) {
  if (!email) return null;
  const lines = [];
  // Stagger pattern
  for (let r = -1; r < 14; r++) {
    for (let c = -1; c < 8; c++) {
      const offsetX = (r % 2 === 0 ? 0 : 180);
      lines.push(
        <span key={`${r}-${c}`} className="wm-text"
          style={{ left: c * 360 + offsetX, top: r * 90 }}
        >{email} · CONFIDENTIAL · ARB_CAPITAL_DATAROOM</span>
      );
    }
  }
  return <div className="watermark">{lines}</div>;
}

// ── Sparkline ────────────────────────────────────────
function Sparkline({ data, width = 80, height = 24, color = 'currentColor' }) {
  const max = Math.max(...data);
  const min = Math.min(...data);
  const range = max - min || 1;
  const pts = data.map((d, i) => {
    const x = (i / (data.length - 1)) * width;
    const y = height - ((d - min) / range) * height;
    return `${x.toFixed(1)},${y.toFixed(1)}`;
  }).join(' ');
  return (
    <svg width={width} height={height} style={{ display: 'block' }}>
      <polyline points={pts} fill="none" stroke={color} strokeWidth="1" />
    </svg>
  );
}

// ── Heatmap dot row ──────────────────────────────────
function HeatRow({ values, height = 14 }) {
  return (
    <div style={{ display: 'flex', gap: 2, height }}>
      {values.map((v, i) => (
        <div key={i} style={{
          flex: 1, height: '100%',
          background: `rgba(212,175,55,${0.08 + v * 0.92})`,
          border: '1px solid var(--border)',
        }} />
      ))}
    </div>
  );
}

// Export to global scope for cross-file usage
Object.assign(window, {
  ArbLogo, ArbWordmark, Brackets, SectionNum, FileIcon, Watermark, Sparkline, HeatRow,
});
