// ============================================================
// EditorialImage — full-bleed-ish SVG placeholders that read
// as editorial fashion photography. Used for hero, lookbook,
// collection covers, about, etc.  No real photo? This is the
// gracious stand-in.
// ============================================================

function JmEditorialImage({ kind = 'hero-portrait', tone = 'warm', className = '' }) {
  // Ảnh người mẫu thật (nếu đã chạy tools/cap-nhat-san-pham.ps1)
  const photo = JM.photoFor ? JM.photoFor(kind) : null;
  if (photo) {
    return (
      <img className={`jm-editorial-img jm-photo ${className}`} src={photo} alt="" loading="lazy"/>
    );
  }

  const palette = {
    bg:    tone === 'shadow' ? '#1C1412' : '#F2EDE8',  // linen or espresso
    skin1: tone === 'shadow' ? '#3F2E26' : '#E6CDB5',
    skin2: tone === 'shadow' ? '#5B4438' : '#D6B597',
    hair:  tone === 'shadow' ? '#0F0B09' : '#3A2A20',
    gold:  '#B07A3F',
    ember: '#C05C2A',
    cream: tone === 'shadow' ? '#2D211B' : '#FAF8F5',
  };

  const labelText = '';

  function render() {
    switch (kind) {
      case 'hero-portrait':
        return (
          <g>
            {/* soft window light */}
            <rect x="0" y="0" width="900" height="1200" fill={palette.bg}/>
            <polygon points="0,0 600,0 380,1200 0,1200" fill={palette.cream} opacity="0.8"/>
            {/* neck + shoulders */}
            <path d="M260 1200 L260 880 Q260 760 360 700 Q420 670 460 640 Q500 670 560 700 Q660 760 660 880 L660 1200 Z" fill={palette.skin1}/>
            <path d="M460 640 Q420 670 360 700 Q330 720 320 760" stroke={palette.skin2} strokeWidth="1.5" fill="none" opacity="0.6"/>
            {/* head silhouette */}
            <ellipse cx="460" cy="500" rx="130" ry="170" fill={palette.skin1}/>
            {/* hair */}
            <path d="M330 480 Q320 320 460 290 Q610 310 600 510 Q580 460 540 440 Q500 430 460 430 Q420 430 380 450 Q346 466 330 480 Z" fill={palette.hair}/>
            <path d="M340 540 Q330 700 410 760" stroke={palette.hair} strokeWidth="40" fill="none" strokeLinecap="round" opacity="0.85"/>
            {/* ear + earring */}
            <ellipse cx="335" cy="540" rx="14" ry="22" fill={palette.skin2}/>
            <g fill="none" stroke={palette.gold} strokeWidth="2" strokeLinecap="round">
              <path d="M335 565 Q325 600 335 640"/>
              <circle cx="335" cy="660" r="14"/>
              <circle cx="335" cy="660" r="8" fill={palette.gold} opacity="0.8"/>
            </g>
            {/* necklace */}
            <g fill="none" stroke={palette.gold} strokeWidth="2.2" strokeLinecap="round">
              <path d="M320 840 Q460 1010 600 840"/>
              <path d="M340 850 Q460 990 580 850" opacity="0.5"/>
              <ellipse cx="460" cy="1006" rx="14" ry="20" fill={palette.gold} opacity="0.95"/>
            </g>
          </g>
        );

      case 'hand-ring':
        return (
          <g>
            <rect x="0" y="0" width="900" height="1200" fill={palette.bg}/>
            {/* draped fabric backdrop */}
            <path d="M0 0 L900 0 L900 700 Q700 760 500 720 Q300 680 0 760 Z" fill={palette.cream} opacity="0.7"/>
            {/* hand */}
            <path d="M180 1200 L180 880 Q190 760 260 720 Q320 690 360 650 Q380 540 410 480 Q440 440 470 460 Q470 540 460 620 Q500 620 530 640 Q560 630 590 640 Q620 630 640 660 Q660 700 640 740 Q620 800 580 830 L520 900 Q500 960 510 1040 Q520 1140 540 1200 Z" fill={palette.skin1}/>
            {/* knuckle shadow */}
            <path d="M420 620 Q450 640 480 640" stroke={palette.skin2} strokeWidth="2" fill="none" opacity="0.6"/>
            {/* ring on finger */}
            <g fill="none" stroke={palette.gold} strokeWidth="3" strokeLinecap="round">
              <ellipse cx="430" cy="552" rx="32" ry="14"/>
              <ellipse cx="430" cy="552" rx="32" ry="11" fill={palette.gold} opacity="0.25"/>
              <path d="M422 538 L430 522 L438 538 Z" fill={palette.ember}/>
            </g>
          </g>
        );

      case 'ear-stud':
        return (
          <g>
            <rect x="0" y="0" width="900" height="1200" fill={palette.bg}/>
            {/* close-up ear */}
            <path d="M0 0 L900 0 L900 1200 L0 1200 Z" fill={palette.bg}/>
            <path d="M300 200 Q400 100 600 150 Q780 220 760 500 Q740 760 620 900 Q500 1000 360 980 Q220 940 240 700 Q260 460 300 200 Z" fill={palette.skin1}/>
            {/* ear inner */}
            <path d="M460 360 Q540 320 600 400 Q620 500 580 600 Q540 680 460 660 Q400 620 420 520 Q430 420 460 360 Z" fill={palette.skin2} opacity="0.85"/>
            <path d="M480 460 Q520 440 540 480 Q540 520 510 540 Q480 540 470 510 Q470 480 480 460 Z" fill={palette.skin1} opacity="0.7"/>
            {/* hair */}
            <path d="M0 0 L0 700 Q60 600 140 580 Q100 360 200 200 Q150 100 200 0 Z" fill={palette.hair}/>
            {/* earring stud */}
            <circle cx="540" cy="760" r="22" fill={palette.gold}/>
            <circle cx="540" cy="760" r="14" fill={palette.cream}/>
            <circle cx="540" cy="760" r="7" fill={palette.gold}/>
            {/* second earring (hoop) higher */}
            <circle cx="500" cy="590" r="6" fill={palette.gold}/>
            <path d="M500 596 Q480 620 500 644" stroke={palette.gold} strokeWidth="2.5" fill="none" strokeLinecap="round"/>
          </g>
        );

      case 'neck-pendant':
        return (
          <g>
            <rect x="0" y="0" width="900" height="1200" fill={palette.bg}/>
            {/* shoulders */}
            <path d="M0 1200 L0 760 Q200 660 360 720 Q450 750 540 720 Q700 660 900 760 L900 1200 Z" fill={palette.skin1}/>
            {/* neck */}
            <path d="M380 760 Q400 600 450 540 Q500 600 520 760 Z" fill={palette.skin1}/>
            <path d="M450 540 Q480 560 480 600" stroke={palette.skin2} strokeWidth="1.5" fill="none" opacity="0.5"/>
            {/* collarbone */}
            <path d="M150 800 Q300 850 440 870 Q580 850 730 800" stroke={palette.skin2} strokeWidth="2" fill="none" opacity="0.5"/>
            {/* fine chain */}
            <g fill="none" stroke={palette.gold} strokeWidth="2.5" strokeLinecap="round">
              <path d="M260 740 Q460 960 660 740"/>
              <ellipse cx="460" cy="956" rx="18" ry="26" fill={palette.gold} opacity="0.95"/>
              <ellipse cx="460" cy="956" rx="10" ry="16" fill={palette.cream}/>
            </g>
          </g>
        );

      case 'collection-vellum':
        return (
          <g>
            <rect x="0" y="0" width="900" height="1200" fill="#E8DFD3"/>
            {/* flat-lay tray */}
            <rect x="120" y="180" width="660" height="840" fill={palette.cream} opacity="0.85"/>
            {/* pieces scattered */}
            <g fill="none" stroke={palette.gold} strokeWidth="2.5" strokeLinecap="round">
              <ellipse cx="280" cy="380" rx="90" ry="92"/>
              <ellipse cx="280" cy="380" rx="78" ry="80"/>
            </g>
            <g fill="none" stroke={palette.gold} strokeWidth="2" strokeLinecap="round">
              <path d="M460 540 Q540 760 660 540"/>
              <circle cx="560" cy="708" r="12" fill={palette.gold} opacity="0.9"/>
            </g>
            <g fill="none" stroke="#9A9087" strokeWidth="2" strokeLinecap="round">
              {Array.from({length: 8}).map((_,i)=>(
                <ellipse key={i} cx={250 + i*46} cy="900" rx="22" ry="12"/>
              ))}
            </g>
            <g fill="none" stroke={palette.gold} strokeWidth="2" strokeLinecap="round">
              <circle cx="600" cy="280" r="14" fill={palette.gold} opacity="0.85"/>
              <circle cx="640" cy="280" r="14" fill={palette.gold} opacity="0.85"/>
            </g>
          </g>
        );

      case 'collection-fingerprint':
        return (
          <g>
            <rect x="0" y="0" width="900" height="1200" fill="#1C1412"/>
            {/* fingerprint mark */}
            <g fill="none" stroke={palette.ember} strokeWidth="2" strokeLinecap="round" opacity="0.9">
              {[0,1,2,3,4,5,6,7,8].map(i => {
                const r = 70 + i*36;
                return <path key={i} d={`M${450 - r} 600 Q${450 - r/2} ${500 - i*8} ${450 + r/2} ${500 - i*8} Q${450 + r} 600 ${450 + r/3} ${720 + i*6} Q${450 - r/3} ${720 + i*6} ${450 - r} 600 Z`} opacity={0.85 - i*0.08}/>;
              })}
              <circle cx="450" cy="600" r="36" fill={palette.ember}/>
            </g>
          </g>
        );

      case 'collection-thu':
        return (
          <g>
            <rect x="0" y="0" width="900" height="1200" fill={palette.bg}/>
            {/* arc light */}
            <path d="M0 0 L900 0 L900 600 Q600 800 300 700 Q150 660 0 720 Z" fill="#FAF8F5"/>
            {/* model in profile */}
            <ellipse cx="500" cy="500" rx="170" ry="220" fill={palette.skin1}/>
            <path d="M340 460 Q330 280 480 250 Q650 280 660 500 Q650 650 600 740 L630 1200 L900 1200 L900 0 L340 0 Z" fill={palette.hair}/>
            {/* ear */}
            <ellipse cx="378" cy="520" rx="14" ry="22" fill={palette.skin2}/>
            {/* earring drop */}
            <g fill={palette.ember} stroke={palette.ember}>
              <circle cx="378" cy="546" r="4"/>
              <path d="M378 550 L378 600" stroke={palette.gold} strokeWidth="1.6"/>
              <ellipse cx="378" cy="616" rx="10" ry="16" fill={palette.gold}/>
            </g>
            {/* shoulder */}
            <path d="M0 1200 L0 880 Q180 780 360 820 Q520 860 700 800 Q840 760 900 800 L900 1200 Z" fill={palette.skin1}/>
          </g>
        );

      case 'about-studio':
        return (
          <g>
            <rect x="0" y="0" width="900" height="1200" fill={palette.bg}/>
            {/* workbench */}
            <rect x="0" y="800" width="900" height="400" fill="#A8896B" opacity="0.55"/>
            <rect x="0" y="800" width="900" height="14" fill="#1C1412" opacity="0.25"/>
            {/* lamp arm from top */}
            <path d="M120 0 L120 240 Q180 280 240 280" stroke="#1C1412" strokeWidth="3" fill="none"/>
            <circle cx="240" cy="280" r="36" fill="#1C1412"/>
            <ellipse cx="320" cy="500" rx="220" ry="60" fill={palette.cream} opacity="0.65"/>
            {/* hands working */}
            <path d="M260 1100 Q300 900 380 880 Q440 870 480 900 Q520 880 560 870 Q620 880 660 910 Q680 970 640 1010 L640 1200 Z" fill={palette.skin1}/>
            <path d="M0 1200 L0 1080 Q120 1040 220 1080 L240 1200 Z" fill={palette.skin1}/>
            {/* tool */}
            <rect x="420" y="820" width="8" height="80" fill="#1C1412"/>
            <ellipse cx="424" cy="900" rx="14" ry="6" fill={palette.gold}/>
          </g>
        );

      case 'editorial-styling':
        return (
          <g>
            <rect x="0" y="0" width="900" height="1200" fill={palette.bg}/>
            {/* model torso, three-quarter */}
            <path d="M0 1200 L0 760 Q200 640 380 700 Q450 730 540 700 Q720 640 900 760 L900 1200 Z" fill={palette.cream}/>
            {/* neck/face */}
            <path d="M380 760 Q400 600 460 520 Q520 600 540 760 Z" fill={palette.skin1}/>
            <ellipse cx="460" cy="440" rx="120" ry="150" fill={palette.skin1}/>
            <path d="M340 420 Q320 240 460 230 Q610 250 600 460 Q580 410 540 390 Q500 380 460 380 Q420 380 380 400 Q350 410 340 420 Z" fill={palette.hair}/>
            {/* layered necklaces */}
            <g fill="none" stroke={palette.gold} strokeWidth="2.2" strokeLinecap="round">
              <path d="M320 780 Q460 900 600 780"/>
              <path d="M280 820 Q460 980 640 820"/>
              <path d="M240 870 Q460 1060 680 870"/>
              <ellipse cx="460" cy="894" rx="6" ry="9" fill={palette.gold}/>
              <ellipse cx="460" cy="976" rx="9" ry="13" fill={palette.gold}/>
              <ellipse cx="460" cy="1058" rx="12" ry="18" fill={palette.ember}/>
            </g>
          </g>
        );

      default:
        return <rect x="0" y="0" width="900" height="1200" fill={palette.bg}/>;
    }
  }

  return (
    <svg
      className={`jm-editorial-img ${className}`}
      viewBox="0 0 900 1200"
      preserveAspectRatio="xMidYMid slice"
      role="img"
      aria-label={kind}
      style={{ width: '100%', height: '100%', display: 'block', background: palette.bg }}
    >
      {render()}
    </svg>
  );
}

window.JmEditorialImage = JmEditorialImage;
