// Shared visual primitives for the portfolio site
// Striped image placeholders, project glyphs, knight piece, scroll knight

function SiteImagePlaceholder({ label = 'screenshot', ratio = '16/10', radius = 16, accent, dark = true, height }) {
  const stripeA = dark ? 'rgba(255,255,255,0.05)' : 'rgba(0,0,0,0.05)';
  const stripeB = dark ? 'rgba(255,255,255,0.02)' : 'rgba(0,0,0,0.02)';
  return (
    <div style={{
      aspectRatio: height ? undefined : ratio,
      height: height,
      width: '100%',
      borderRadius: radius,
      background: `repeating-linear-gradient(135deg, ${stripeA} 0 10px, ${stripeB} 10px 20px)`,
      border: dark ? '1px solid rgba(255,255,255,0.08)' : '1px solid rgba(0,0,0,0.08)',
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      fontFamily: 'ui-monospace, "SF Mono", Menlo, monospace',
      fontSize: 11, letterSpacing: '0.08em', textTransform: 'uppercase',
      color: accent || (dark ? 'rgba(255,255,255,0.4)' : 'rgba(0,0,0,0.45)'),
      position: 'relative', overflow: 'hidden',
    }}>
      <span style={{ position: 'relative', zIndex: 2 }}>{label}</span>
      {accent && <div style={{
        position: 'absolute', inset: 0,
        background: `radial-gradient(60% 50% at 30% 20%, ${accent}33, transparent 70%)`,
        pointerEvents: 'none',
      }} />}
    </div>
  );
}

function SiteGlyph({ id, color = '#fff', size = 24 }) {
  const s = { width: size, height: size, display: 'block' };
  if (id === 'unishare') return (
    <svg viewBox="0 0 24 24" style={s} fill="none" stroke={color} strokeWidth="1.5" strokeLinecap="round">
      <circle cx="6" cy="7" r="2.4"/><circle cx="18" cy="7" r="2.4"/><circle cx="12" cy="17" r="2.4"/>
      <path d="M7.5 8.5 10.5 15.5 M16.5 8.5 13.5 15.5 M8.4 7 15.6 7"/>
    </svg>
  );
  if (id === 'carsim') return (
    <svg viewBox="0 0 24 24" style={s} fill="none" stroke={color} strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
      <rect x="4" y="10" width="16" height="6" rx="1.5"/>
      <path d="M7 10 8 6 16 6 17 10"/>
      <circle cx="8" cy="17.5" r="1.4"/><circle cx="16" cy="17.5" r="1.4"/>
    </svg>
  );
  if (id === 'face') return (
    <svg viewBox="0 0 24 24" style={s} fill="none" stroke={color} strokeWidth="1.5" strokeLinecap="round">
      <path d="M5 4H4V8 M19 4H20V8 M5 20H4V16 M19 20H20V16"/>
      <circle cx="12" cy="12" r="4"/>
      <circle cx="10.5" cy="11" r=".7" fill={color} stroke="none"/>
      <circle cx="13.5" cy="11" r=".7" fill={color} stroke="none"/>
      <path d="M10.5 13.5 Q12 14.5 13.5 13.5"/>
    </svg>
  );
  if (id === 'routes') return (
    <svg viewBox="0 0 24 24" style={s} fill="none" stroke={color} strokeWidth="1.5" strokeLinecap="round">
      <circle cx="6" cy="6" r="1.6"/><circle cx="18" cy="6" r="1.6"/>
      <circle cx="6" cy="18" r="1.6"/><circle cx="18" cy="18" r="1.6"/>
      <path d="M7.5 6 H16.5 M6 7.5 V16.5 M7.2 7.2 16.8 16.8"/>
    </svg>
  );
  return null;
}

// Stylized knight — modern, minimal, premium. Layered gradient + soft inner glow.
function KnightPiece({ size = 60, color = 'currentColor', opacity = 1, glow = true }) {
  const uid = React.useMemo(() => 'k' + Math.random().toString(36).slice(2, 8), []);
  return (
    <svg width={size} height={size} viewBox="0 0 100 100" style={{ opacity, display: 'block', overflow: 'visible' }}>
      <defs>
        <linearGradient id={`${uid}-fill`} x1="20%" y1="0%" x2="80%" y2="100%">
          <stop offset="0%" stopColor={color} stopOpacity="0.95" />
          <stop offset="55%" stopColor={color} stopOpacity="0.55" />
          <stop offset="100%" stopColor={color} stopOpacity="0.18" />
        </linearGradient>
        <linearGradient id={`${uid}-stroke`} x1="0%" y1="0%" x2="100%" y2="100%">
          <stop offset="0%" stopColor={color} stopOpacity="1" />
          <stop offset="100%" stopColor={color} stopOpacity="0.35" />
        </linearGradient>
        <radialGradient id={`${uid}-glow`} cx="55%" cy="35%" r="60%">
          <stop offset="0%" stopColor={color} stopOpacity="0.55" />
          <stop offset="60%" stopColor={color} stopOpacity="0.08" />
          <stop offset="100%" stopColor={color} stopOpacity="0" />
        </radialGradient>
      </defs>
      {glow && <circle cx="55" cy="42" r="42" fill={`url(#${uid}-glow)`} />}
      {/* Minimal modernist knight silhouette — clean negative-space ear, mane crease, eye */}
      <path
        d="M 30 88
           L 30 76
           C 30 64 36 58 41 51
           C 44 47 44 43 41 41
           C 37 44 33 47 28 49
           C 25 47 24 41 27 36
           C 32 27 41 19 51 17
           C 66 17 78 30 80 47
           C 81 60 79 73 79 88 Z"
        fill={`url(#${uid}-fill)`}
        stroke={`url(#${uid}-stroke)`}
        strokeWidth="1.2"
        strokeLinejoin="round"
      />
      {/* Mane crease — single confident stroke */}
      <path d="M 56 22 C 64 30 70 38 73 50"
        stroke={color} strokeOpacity="0.45" strokeWidth="1.2" fill="none" strokeLinecap="round" />
      {/* Eye */}
      <circle cx="46" cy="33" r="1.6" fill={color} opacity="0.85" />
      {/* Pointed ear (small triangle highlight) */}
      <path d="M 56 18 L 60 14 L 62 21 Z" fill={color} opacity="0.6" />
    </svg>
  );
}

window.SiteImagePlaceholder = SiteImagePlaceholder;
window.SiteGlyph = SiteGlyph;
window.KnightPiece = KnightPiece;
