// Article cover SVG motifs — abstract editorial illustrations
// One per article based on its `motif` field.

const Motif = ({ kind, accent = "#00C853" }) => {
  const ink = "rgba(255,255,255,0.92)";
  const sub = "rgba(255,255,255,0.45)";
  switch (kind) {
    case "chip":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          <g opacity="0.92">
            <rect x="140" y="70" width="120" height="100" rx="8" fill="none" stroke={ink} strokeWidth="1.5" />
            <rect x="155" y="85" width="90" height="70" rx="3" fill={accent} fillOpacity="0.18" stroke={accent} strokeWidth="1" />
            <text x="200" y="125" textAnchor="middle" fill={ink} fontSize="11" fontFamily="ui-monospace" letterSpacing="2">B200</text>
            {[0,1,2,3,4,5,6,7].map(i => (
              <g key={i}>
                <line x1={150 + i*14} y1="70" x2={150 + i*14} y2="58" stroke={ink} strokeWidth="1" />
                <line x1={150 + i*14} y1="170" x2={150 + i*14} y2="182" stroke={ink} strokeWidth="1" />
                <line x1="140" y1={85 + i*10} x2="128" y2={85 + i*10} stroke={ink} strokeWidth="1" />
                <line x1="260" y1={85 + i*10} x2="272" y2={85 + i*10} stroke={ink} strokeWidth="1" />
              </g>
            ))}
            <circle cx="160" cy="95" r="2" fill={accent} />
            <circle cx="240" cy="145" r="2" fill={accent} />
          </g>
        </svg>
      );
    case "wafer":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          <circle cx="200" cy="120" r="85" fill="none" stroke={ink} strokeWidth="1.5" />
          <circle cx="200" cy="120" r="85" fill={accent} fillOpacity="0.08" />
          <g clipPath="url(#waferClip)">
            <defs><clipPath id="waferClip"><circle cx="200" cy="120" r="83" /></clipPath></defs>
            {Array.from({length: 11}).map((_, r) =>
              Array.from({length: 11}).map((_, c) => (
                <rect key={`${r}-${c}`} x={120 + c*16} y={40 + r*16} width="14" height="14"
                      fill="none" stroke={ink} strokeOpacity="0.5" strokeWidth="0.6" />
              ))
            )}
            <rect x="200" y="104" width="14" height="14" fill={accent} fillOpacity="0.6" />
            <rect x="184" y="120" width="14" height="14" fill={accent} fillOpacity="0.4" />
          </g>
          <line x1="115" y1="180" x2="135" y2="195" stroke={ink} strokeWidth="1.5" />
        </svg>
      );
    case "reactor":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          <g transform="translate(200,120)">
            <ellipse rx="80" ry="22" fill="none" stroke={ink} strokeWidth="1" opacity="0.6" />
            <ellipse rx="80" ry="22" fill="none" stroke={accent} strokeWidth="1" transform="rotate(60)" />
            <ellipse rx="80" ry="22" fill="none" stroke={ink} strokeWidth="1" opacity="0.5" transform="rotate(120)" />
            <circle r="14" fill={accent} />
            <circle r="22" fill="none" stroke={accent} strokeOpacity="0.5" strokeWidth="1" />
            <circle r="34" fill="none" stroke={ink} strokeOpacity="0.3" strokeWidth="1" strokeDasharray="2 4" />
          </g>
        </svg>
      );
    case "graph":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          <g opacity="0.85">
            {[60, 100, 140, 180].map(y =>
              <line key={y} x1="60" y1={y} x2="340" y2={y} stroke={ink} strokeOpacity="0.18" strokeWidth="0.5" />
            )}
            <path d="M 60 175 Q 130 165 160 130 T 240 80 T 340 55" fill="none" stroke={accent} strokeWidth="2" />
            <path d="M 60 185 Q 130 178 170 155 T 260 115 T 340 95" fill="none" stroke={ink} strokeOpacity="0.6" strokeWidth="1.5" strokeDasharray="3 3" />
            {[[80,170],[150,135],[220,98],[300,65]].map(([x,y], i) => (
              <circle key={i} cx={x} cy={y} r="3" fill={accent} />
            ))}
          </g>
        </svg>
      );
    case "lens":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          <g transform="translate(200,120)">
            <ellipse rx="100" ry="60" fill="none" stroke={ink} strokeOpacity="0.7" strokeWidth="1" />
            <ellipse rx="80" ry="48" fill="none" stroke={ink} strokeOpacity="0.5" strokeWidth="1" />
            <ellipse rx="60" ry="36" fill="none" stroke={accent} strokeOpacity="0.6" strokeWidth="1" />
            <ellipse rx="40" ry="24" fill={accent} fillOpacity="0.15" stroke={accent} strokeWidth="1.2" />
            <line x1="-130" y1="0" x2="130" y2="0" stroke={accent} strokeWidth="0.8" strokeDasharray="2 3" />
          </g>
        </svg>
      );
    case "curve":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          <path d="M 50 200 Q 120 195 180 150 T 280 60 L 350 50" fill="none" stroke={accent} strokeWidth="2" />
          <path d="M 280 60 L 350 50" stroke={accent} strokeWidth="3" />
          <circle cx="280" cy="60" r="5" fill={accent} />
          <text x="290" y="48" fill={ink} fontSize="10" fontFamily="ui-monospace">plateau ?</text>
          <line x1="50" y1="210" x2="350" y2="210" stroke={ink} strokeOpacity="0.4" />
          <line x1="50" y1="40" x2="50" y2="210" stroke={ink} strokeOpacity="0.4" />
        </svg>
      );
    case "joints":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          <g transform="translate(200,120)" stroke={ink} strokeWidth="1.5" fill="none">
            <circle cx="0" cy="-50" r="14" fill={accent} fillOpacity="0.2" />
            <line x1="0" y1="-36" x2="0" y2="20" />
            <line x1="0" y1="-20" x2="-30" y2="0" />
            <line x1="0" y1="-20" x2="30" y2="0" />
            <line x1="0" y1="20" x2="-15" y2="60" />
            <line x1="0" y1="20" x2="15" y2="60" />
            {[[0,-50],[0,-20],[-30,0],[30,0],[0,20],[-15,60],[15,60]].map(([x,y], i) =>
              <circle key={i} cx={x} cy={y} r="3.5" fill={accent} stroke="none" />
            )}
          </g>
        </svg>
      );
    case "stack":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          {[0,1,2,3].map(i => (
            <g key={i} transform={`translate(${140 + i*8}, ${60 + i*16})`}>
              <rect width="120" height="24" rx="3" fill={i === 1 ? accent : ink} fillOpacity={i === 1 ? 0.85 : 0.15} stroke={ink} strokeWidth="1" />
              <circle cx="10" cy="12" r="3" fill={i === 1 ? "white" : accent} />
            </g>
          ))}
        </svg>
      );
    case "wave":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          {[0,1,2,3,4].map(i => (
            <path key={i}
              d={`M 0 ${100 + i*15} Q 100 ${80 + i*15} 200 ${100 + i*15} T 400 ${100 + i*15}`}
              fill="none" stroke={i === 2 ? accent : ink} strokeOpacity={i === 2 ? 0.9 : 0.3} strokeWidth={i === 2 ? 1.5 : 1} />
          ))}
        </svg>
      );
    case "nodes":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          {[[120,80],[280,80],[200,140],[100,180],[300,180],[200,60]].map(([x,y], i) =>
            [[120,80],[280,80],[200,140],[100,180],[300,180],[200,60]].slice(i+1).map(([x2,y2], j) =>
              <line key={`${i}-${j}`} x1={x} y1={y} x2={x2} y2={y2} stroke={ink} strokeOpacity="0.25" strokeWidth="0.5" />
            )
          )}
          {[[120,80],[280,80],[200,140],[100,180],[300,180],[200,60]].map(([x,y], i) =>
            <g key={i}>
              <circle cx={x} cy={y} r="6" fill={i % 2 ? accent : ink} fillOpacity={i % 2 ? 0.9 : 0.7} />
              <circle cx={x} cy={y} r="14" fill="none" stroke={i % 2 ? accent : ink} strokeOpacity="0.25" />
            </g>
          )}
        </svg>
      );
    case "globe":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          <g transform="translate(200,120)">
            <circle r="70" fill="none" stroke={ink} strokeWidth="1" />
            {[0,30,60,90,120,150].map(deg =>
              <ellipse key={deg} rx="70" ry="22" fill="none" stroke={ink} strokeOpacity="0.3" strokeWidth="0.5" transform={`rotate(${deg})`} />
            )}
            {[-40,-20,0,20,40].map(y =>
              <line key={y} x1={-Math.sqrt(70*70 - y*y)} y1={y} x2={Math.sqrt(70*70 - y*y)} y2={y} stroke={ink} strokeOpacity="0.2" strokeWidth="0.5" />
            )}
            <circle cx="-20" cy="-15" r="3" fill={accent} />
            <circle cx="35" cy="20" r="3" fill={accent} />
          </g>
        </svg>
      );
    case "bars":
      return (
        <svg viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
          {[60,100,80,140,110,170,130].map((h, i) => (
            <rect key={i} x={70 + i*40} y={200 - h} width="22" height={h}
                  fill={i === 5 ? accent : ink} fillOpacity={i === 5 ? 0.85 : 0.4} />
          ))}
          <line x1="50" y1="200" x2="360" y2="200" stroke={ink} strokeOpacity="0.5" />
        </svg>
      );
    default:
      return null;
  }
};

window.Motif = Motif;
