/* Placeholder graphics — drawn with SVG so user can replace with real photos later.
   Style: theatrical, dark, deliberate. Each placeholder telegraphs what it is for. */

const PlaceholderTag = ({ label }) => (
  <div style={{
    position: 'absolute', bottom: 8, left: 8, right: 8,
    fontSize: 9, fontWeight: 800, letterSpacing: '0.18em', textTransform: 'uppercase',
    color: 'rgba(245,238,220,0.55)', textAlign: 'center',
    padding: '4px 6px', border: '1px dashed rgba(245,238,220,0.25)', borderRadius: 3,
    backdropFilter: 'blur(4px)', pointerEvents: 'none',
  }}>{label}</div>
);

// Theatrical stage hero — dark navy theater with stage lights, performers as silhouettes
const HeroStagePlaceholder = ({ showTag = true }) => (
  <div style={{ position: 'absolute', inset: 0, background: 'var(--navy-900)' }}>
    <svg viewBox="0 0 1600 600" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%' }}>
      <defs>
        <radialGradient id="hero-spot-1" cx="0.55" cy="0.25" r="0.55">
          <stop offset="0%" stopColor="#FFE89B" stopOpacity="0.55" />
          <stop offset="40%" stopColor="#E0B656" stopOpacity="0.2" />
          <stop offset="100%" stopColor="#08112C" stopOpacity="0" />
        </radialGradient>
        <radialGradient id="hero-spot-2" cx="0.75" cy="0.35" r="0.4">
          <stop offset="0%" stopColor="#7DA8FF" stopOpacity="0.5" />
          <stop offset="100%" stopColor="#08112C" stopOpacity="0" />
        </radialGradient>
        <radialGradient id="hero-spot-3" cx="0.92" cy="0.3" r="0.35">
          <stop offset="0%" stopColor="#C77CE2" stopOpacity="0.4" />
          <stop offset="100%" stopColor="#08112C" stopOpacity="0" />
        </radialGradient>
        <linearGradient id="hero-floor" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#1a1037" />
          <stop offset="100%" stopColor="#080714" />
        </linearGradient>
        <linearGradient id="hero-curtain" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#3a0d18" />
          <stop offset="50%" stopColor="#5a1426" />
          <stop offset="100%" stopColor="#220812" />
        </linearGradient>
      </defs>
      {/* Background */}
      <rect width="1600" height="600" fill="#0a0f24" />
      {/* Curtains */}
      <path d="M0,0 L0,600 L120,600 Q130,480 110,360 Q140,260 100,160 Q130,80 90,0 Z" fill="url(#hero-curtain)" opacity="0.9" />
      <path d="M120,600 L120,600 Q150,500 140,400 Q170,320 150,240 Q180,160 160,80 Q190,0 200,0 L200,600 Z" fill="url(#hero-curtain)" opacity="0.5" />
      {/* Stage lights overhead */}
      {[160, 320, 480, 640, 800, 960, 1120, 1280, 1440].map((x, i) => (
        <g key={i}>
          <circle cx={x} cy="20" r="6" fill="#FFE89B" opacity="0.7" />
          <path d={`M${x},25 L${x - 60},${130 + (i % 3) * 20} L${x + 60},${130 + (i % 3) * 20} Z`} fill="url(#hero-spot-1)" opacity="0.35" />
        </g>
      ))}
      {/* Big spots */}
      <ellipse cx="900" cy="200" rx="500" ry="320" fill="url(#hero-spot-1)" />
      <ellipse cx="1200" cy="280" rx="380" ry="260" fill="url(#hero-spot-2)" />
      <ellipse cx="1480" cy="240" rx="280" ry="200" fill="url(#hero-spot-3)" />
      {/* Stage */}
      <rect x="200" y="340" width="1400" height="180" fill="url(#hero-floor)" />
      <line x1="200" y1="340" x2="1600" y2="340" stroke="#E0B656" strokeOpacity="0.25" strokeWidth="1" />
      {/* Performer silhouettes (5 figures on stage center-right) */}
      {[700, 820, 940, 1060, 1180].map((x, i) => (
        <g key={i} fill="#020410" opacity="0.95">
          <ellipse cx={x} cy={335} rx="14" ry="6" opacity="0.4" />
          <circle cx={x} cy={290} r="14" />
          <path d={`M${x - 18},305 Q${x},300 ${x + 18},305 L${x + 22},340 L${x - 22},340 Z`} />
        </g>
      ))}
      {/* Audience seats silhouette */}
      <path d="M0,520 Q200,500 400,510 Q600,500 800,510 Q1000,500 1200,510 Q1400,505 1600,520 L1600,600 L0,600 Z" fill="#03061a" opacity="0.95" />
      {[...Array(40)].map((_, i) => (
        <circle key={i} cx={40 + i * 40} cy={540 + (i % 3) * 8} r="6" fill="#0a0e22" />
      ))}
    </svg>
    {showTag && <PlaceholderTag label="Hero Image — Theater Stage" />}
  </div>
);

// Generic theater audience for venue band
const TheaterAudiencePlaceholder = () => (
  <div style={{ position: 'absolute', inset: 0 }}>
    <svg viewBox="0 0 1600 500" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%' }}>
      <defs>
        <radialGradient id="aud-glow" cx="0.5" cy="0.1" r="0.7">
          <stop offset="0%" stopColor="#C77CE2" stopOpacity="0.6" />
          <stop offset="40%" stopColor="#5b2a8a" stopOpacity="0.4" />
          <stop offset="100%" stopColor="#0B1635" stopOpacity="0" />
        </radialGradient>
      </defs>
      <rect width="1600" height="500" fill="#1a0e3a" />
      <ellipse cx="800" cy="50" rx="900" ry="320" fill="url(#aud-glow)" />
      {/* Stage glow */}
      <ellipse cx="800" cy="180" rx="600" ry="80" fill="#FFE89B" opacity="0.18" />
      <ellipse cx="800" cy="180" rx="300" ry="40" fill="#FFE89B" opacity="0.25" />
      {/* Audience rows */}
      {[...Array(8)].map((_, r) => {
        const y = 280 + r * 32;
        const count = 40 + r * 4;
        return (
          <g key={r} opacity={0.95 - r * 0.05}>
            {[...Array(count)].map((_, i) => (
              <circle key={i} cx={(1600 / count) * i + (r % 2 ? 10 : 0)} cy={y} r={6 + r * 0.5} fill="#040618" />
            ))}
          </g>
        );
      })}
    </svg>
  </div>
);

// Performer headshot polaroid placeholders — varying compositions
const PolaroidPlaceholder = ({ kind, label }) => {
  // kinds: comedian, magician, audience, gameShow
  const presets = {
    comedian: { bg: '#16223f', accent: '#E0B656', figure: 'mic' },
    magician: { bg: '#0e1738', accent: '#7DA8FF', figure: 'cards' },
    audience: { bg: '#221033', accent: '#FFE89B', figure: 'crowd' },
    gameShow: { bg: '#3a0c4f', accent: '#FF6BB5', figure: 'tune' },
    hypnotist: { bg: '#1a0c3a', accent: '#C77CE2', figure: 'eye' },
  };
  const p = presets[kind] || presets.comedian;

  return (
    <div className="polaroid-img" style={{ background: p.bg, position: 'relative' }}>
      <svg viewBox="0 0 400 300" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%' }}>
        <defs>
          <radialGradient id={`pol-${kind}-glow`} cx="0.5" cy="0.4" r="0.6">
            <stop offset="0%" stopColor={p.accent} stopOpacity="0.5" />
            <stop offset="100%" stopColor={p.bg} stopOpacity="0" />
          </radialGradient>
        </defs>
        <rect width="400" height="300" fill={p.bg} />
        <ellipse cx="200" cy="130" rx="260" ry="160" fill={`url(#pol-${kind}-glow)`} />

        {p.figure === 'mic' && (
          <g fill="#040618">
            <ellipse cx="200" cy="290" rx="80" ry="10" opacity="0.5" />
            <circle cx="200" cy="120" r="38" />
            <path d="M150 165 Q200 155 250 165 L260 270 L140 270 Z" />
            <rect x="194" y="155" width="12" height="8" fill={p.accent} />
            <rect x="192" y="160" width="16" height="22" rx="6" fill={p.accent} />
          </g>
        )}
        {p.figure === 'cards' && (
          <g>
            <ellipse cx="200" cy="290" rx="70" ry="8" fill="#040618" opacity="0.5" />
            <g fill="#040618">
              <circle cx="200" cy="125" r="34" />
              <path d="M155 160 Q200 152 245 160 L255 270 L145 270 Z" />
            </g>
            {/* flying cards */}
            {[
              { x: 90, y: 80, r: -25 }, { x: 320, y: 100, r: 20 },
              { x: 70, y: 180, r: 15 }, { x: 340, y: 200, r: -15 },
              { x: 270, y: 60, r: 35 },
            ].map((c, i) => (
              <g key={i} transform={`translate(${c.x} ${c.y}) rotate(${c.r})`}>
                <rect x="-14" y="-20" width="28" height="40" rx="3" fill="#fff" />
                <text x="0" y="2" fontSize="14" fontFamily="serif" textAnchor="middle" fill={i % 2 ? '#c0392b' : '#040618'} fontWeight="700">{['♠','♥','♦','♣','A'][i]}</text>
              </g>
            ))}
          </g>
        )}
        {p.figure === 'crowd' && (
          <g>
            <rect x="0" y="80" width="400" height="60" fill="#FFE89B" opacity="0.2" />
            <rect x="0" y="80" width="400" height="6" fill={p.accent} opacity="0.4" />
            {[...Array(6)].map((_, r) =>
              [...Array(14)].map((__, i) => (
                <g key={`${r}-${i}`} fill="#040618" opacity={0.95 - r * 0.05}>
                  <circle cx={20 + i * 28 + (r % 2 ? 14 : 0)} cy={170 + r * 22} r="8" />
                  <path d={`M${10 + i * 28 + (r % 2 ? 14 : 0)},${184 + r * 22} L${30 + i * 28 + (r % 2 ? 14 : 0)},${184 + r * 22} L${28 + i * 28 + (r % 2 ? 14 : 0)},${198 + r * 22} L${12 + i * 28 + (r % 2 ? 14 : 0)},${198 + r * 22} Z`} />
                </g>
              ))
            )}
          </g>
        )}
        {p.figure === 'tune' && (
          <g>
            <ellipse cx="200" cy="290" rx="80" ry="8" fill="#040618" opacity="0.5" />
            {/* neon sign feel */}
            <rect x="60" y="50" width="280" height="120" rx="14" fill="none" stroke={p.accent} strokeWidth="3" opacity="0.6" />
            <text x="200" y="110" fontSize="36" fontFamily="serif" fontWeight="700" textAnchor="middle" fill="#FFE89B" letterSpacing="2">NAME THAT</text>
            <text x="200" y="150" fontSize="34" fontFamily="serif" fontWeight="700" textAnchor="middle" fill={p.accent}>TUNE</text>
            <g fill="#040618">
              <circle cx="200" cy="220" r="22" />
              <path d="M168 245 Q200 240 232 245 L240 290 L160 290 Z" />
            </g>
          </g>
        )}
        {p.figure === 'eye' && (
          <g>
            <ellipse cx="200" cy="290" rx="80" ry="8" fill="#040618" opacity="0.5" />
            {/* swirling lines */}
            {[...Array(7)].map((_, i) => (
              <circle key={i} cx="200" cy="120" r={20 + i * 16} fill="none" stroke={p.accent} strokeWidth="2" opacity={0.4 - i * 0.04} />
            ))}
            <g fill="#040618">
              <circle cx="200" cy="170" r="32" />
              <path d="M160 200 Q200 195 240 200 L250 290 L150 290 Z" />
            </g>
          </g>
        )}
      </svg>
      {label && <PlaceholderTag label={label} />}
    </div>
  );
};

// Event poster placeholder — vertical card stylized by show type
const EventPosterPlaceholder = ({ style, title }) => {
  const presets = {
    'comedy-red':   { bg: '#7A1818', bg2: '#3a0a0a', accent: '#FFE89B', label: 'COMEDY NIGHT WITH', name: title.replace('Comedy Night with ', '').replace(' Comedy Night', '') },
    'comedy-amber': { bg: '#8a4413', bg2: '#3a1a05', accent: '#F2C14E', label: 'COMEDY NIGHT WITH', name: title.replace('Comedy Night with ', '').replace(' Comedy Night', '') },
    'magic-navy':   { bg: '#0F1F3D', bg2: '#070d1c', accent: '#D4A642', label: 'THE MAGIC OF', name: title.replace('The Magic of ', '') },
    'hypnosis-purple': { bg: '#1a0a3a', bg2: '#0a0420', accent: '#7DA8FF', label: 'STARRING ERIK KELLER', name: 'HYPNOSIS\nUNLEASHED' },
    'tune-neon':    { bg: '#0a1240', bg2: '#040820', accent: '#FF6BB5', label: '', name: title },
    'family-teal':  { bg: '#0e3a3a', bg2: '#031a1a', accent: '#FFE89B', label: 'FAMILY SHOW', name: title.replace(' Family Show', '') },
  };
  const p = presets[style] || presets['comedy-red'];

  return (
    <div style={{ position: 'absolute', inset: 0 }}>
      <svg viewBox="0 0 300 400" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%' }}>
        <defs>
          <radialGradient id={`poster-${style}`} cx="0.5" cy="0.4" r="0.7">
            <stop offset="0%" stopColor={p.bg} />
            <stop offset="100%" stopColor={p.bg2} />
          </radialGradient>
          <radialGradient id={`poster-${style}-glow`} cx="0.5" cy="0.35" r="0.5">
            <stop offset="0%" stopColor={p.accent} stopOpacity="0.35" />
            <stop offset="100%" stopColor={p.bg2} stopOpacity="0" />
          </radialGradient>
        </defs>
        <rect width="300" height="400" fill={`url(#poster-${style})`} />
        <ellipse cx="150" cy="160" rx="200" ry="140" fill={`url(#poster-${style}-glow)`} />

        {/* Label */}
        {p.label && (
          <text x="150" y="50" textAnchor="middle" fontSize="11" fontFamily="Manrope, sans-serif" fontWeight="800" letterSpacing="2" fill={p.accent}>
            {p.label}
          </text>
        )}

        {/* Headline / name */}
        {style === 'tune-neon' ? (
          <g>
            <rect x="40" y="60" width="220" height="160" rx="14" fill="none" stroke={p.accent} strokeWidth="3" opacity="0.75" />
            <text x="150" y="110" textAnchor="middle" fontSize="22" fontFamily="serif" fontWeight="700" fill="#FFE89B" letterSpacing="1.5">NAME THAT</text>
            <text x="150" y="150" textAnchor="middle" fontSize="36" fontFamily="serif" fontWeight="700" fill={p.accent}>TUNE</text>
            <text x="150" y="190" textAnchor="middle" fontSize="20" fontFamily="serif" fontStyle="italic" fontWeight="700" fill="#FFE89B">Live!</text>
          </g>
        ) : style === 'hypnosis-purple' ? (
          <g>
            <text x="150" y="105" textAnchor="middle" fontSize="28" fontFamily="serif" fontWeight="800" fill="#FFE89B" letterSpacing="2">HYPNOSIS</text>
            <text x="150" y="140" textAnchor="middle" fontSize="22" fontFamily="serif" fontWeight="800" fill={p.accent} letterSpacing="3">UNLEASHED</text>
          </g>
        ) : (
          <text x="150" y="115" textAnchor="middle" fontSize={p.name.length > 12 ? 24 : 34} fontFamily="serif" fontWeight="800" fill="#FFE89B" letterSpacing="1">
            {p.name.split(' ').slice(0, 2).map((w, i) => (
              <tspan key={i} x="150" dy={i === 0 ? 0 : 30}>{w}</tspan>
            ))}
          </text>
        )}

        {/* Performer silhouette */}
        <g fill="#040618" transform="translate(0, 30)">
          <circle cx="150" cy="240" r="34" />
          <path d="M100 280 Q150 270 200 280 L210 400 L90 400 Z" />
          {/* Mic */}
          {(style.includes('comedy') || style === 'tune-neon') && (
            <g fill={p.accent}>
              <rect x="144" y="200" width="12" height="12" />
              <rect x="140" y="208" width="20" height="26" rx="8" />
              <rect x="148" y="232" width="4" height="20" />
            </g>
          )}
        </g>
      </svg>
      <PlaceholderTag label="Event Poster" />
    </div>
  );
};

// Generic photo placeholder
const PhotoPlaceholder = ({ label, h = 220, accent = '#E0B656' }) => (
  <div style={{ position: 'relative', width: '100%', height: '100%', minHeight: h, background: '#0F1A3A' }}>
    <svg viewBox="0 0 400 300" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%' }}>
      <defs>
        <radialGradient id="ph-glow" cx="0.5" cy="0.5" r="0.6">
          <stop offset="0%" stopColor={accent} stopOpacity="0.25" />
          <stop offset="100%" stopColor="#0F1A3A" stopOpacity="0" />
        </radialGradient>
      </defs>
      <rect width="400" height="300" fill="#0F1A3A" />
      <ellipse cx="200" cy="150" rx="240" ry="160" fill="url(#ph-glow)" />
      <g stroke={accent} strokeWidth="1.5" fill="none" opacity="0.5">
        <rect x="150" y="115" width="100" height="70" rx="4" />
        <circle cx="180" cy="140" r="8" />
        <path d="M150 175 L185 150 L210 165 L250 130" />
      </g>
    </svg>
    {label && <PlaceholderTag label={label} />}
  </div>
);

// WAND logo (drawn). Bold serif wordmark with "PRESENTS" tracking below
// WAND Presents logo — official white lockup (star-swirl mark + wordmark).
const WandLogo = ({ height = 48 }) => (
  <img
    src="assets/wand-logo-white.png"
    alt="WAND Presents"
    className="logo-img"
    style={{ height: `${height}px` }}
  />
);

// Sparkle accent
const SparkleDecoration = ({ size = 24, top, left, right, bottom, opacity = 1 }) => (
  <svg
    width={size} height={size} viewBox="0 0 24 24"
    style={{ position: 'absolute', top, left, right, bottom, opacity, color: 'var(--gold-500)', pointerEvents: 'none' }}
    fill="currentColor"
  >
    <path d="M12 2 L13.4 9.6 L21 11 L13.4 12.4 L12 20 L10.6 12.4 L3 11 L10.6 9.6 Z" />
  </svg>
);

Object.assign(window, {
  HeroStagePlaceholder, TheaterAudiencePlaceholder,
  PolaroidPlaceholder, EventPosterPlaceholder, PhotoPlaceholder,
  WandLogo, SparkleDecoration, PlaceholderTag,
});
