// 幾何圓形/橢圓拼出人物剪影 - SVG illustrations
// Keep STRICTLY geometric: circles, ellipses, stacked rects. No hand-drawn curves.

const PeopleGathering = ({ size = 280, palette }) => {
  const p = palette || window.HAOLIN_TOKENS.colors;
  return (
    <svg viewBox="0 0 280 200" width={size} height={size * 200/280} style={{display:'block'}}>
      {/* warm circle backdrop */}
      <circle cx="140" cy="110" r="95" fill={p.primarySoft} opacity="0.55"/>
      {/* ground line */}
      <ellipse cx="140" cy="175" rx="110" ry="6" fill={p.bgAlt}/>
      {/* person A - large */}
      <circle cx="80" cy="92" r="22" fill={p.gold}/>
      <rect x="58" y="112" width="44" height="56" rx="22" fill={p.primary}/>
      {/* person B - mid */}
      <circle cx="140" cy="82" r="20" fill={p.accent}/>
      <rect x="120" y="100" width="40" height="70" rx="20" fill={p.bgAlt} stroke={p.accent} strokeWidth="2"/>
      {/* person C - small, child-ish */}
      <circle cx="188" cy="108" r="15" fill={p.warm}/>
      <rect x="174" y="121" width="30" height="48" rx="15" fill={p.gold}/>
      {/* dot between them */}
      <circle cx="110" cy="140" r="3" fill={p.ink}/>
      <circle cx="168" cy="140" r="3" fill={p.ink}/>
    </svg>
  );
};

const HomePlate = ({ size = 200, palette }) => {
  const p = palette || window.HAOLIN_TOKENS.colors;
  return (
    <svg viewBox="0 0 200 160" width={size} height={size * 160/200}>
      <circle cx="100" cy="85" r="70" fill={p.accentSoft}/>
      <rect x="60" y="60" width="80" height="70" rx="4" fill={p.primary}/>
      <polygon points="55,60 100,30 145,60" fill={p.primaryDark}/>
      <rect x="90" y="90" width="20" height="40" fill={p.bgAlt}/>
      <circle cx="105" cy="112" r="2" fill={p.ink}/>
    </svg>
  );
};

const HandsCircle = ({ size = 200, palette }) => {
  const p = palette || window.HAOLIN_TOKENS.colors;
  return (
    <svg viewBox="0 0 200 160" width={size} height={size * 160/200}>
      <circle cx="100" cy="82" r="58" fill={p.primarySoft} opacity="0.7"/>
      {/* four head-circles around a center */}
      <circle cx="60"  cy="82" r="16" fill={p.primary}/>
      <circle cx="140" cy="82" r="16" fill={p.accent}/>
      <circle cx="100" cy="42" r="16" fill={p.gold}/>
      <circle cx="100" cy="122" r="16" fill={p.warm}/>
      {/* center small circle - representing 'match' */}
      <circle cx="100" cy="82" r="8" fill={p.ink}/>
    </svg>
  );
};

const ChatBubbles = ({ size = 200, palette }) => {
  const p = palette || window.HAOLIN_TOKENS.colors;
  return (
    <svg viewBox="0 0 200 160" width={size} height={size * 160/200}>
      <rect x="20" y="30" width="110" height="50" rx="24" fill={p.primary}/>
      <rect x="70" y="75" width="100" height="55" rx="24" fill={p.accent}/>
      <circle cx="40" cy="55" r="3" fill={p.bg}/>
      <circle cx="55" cy="55" r="3" fill={p.bg}/>
      <circle cx="70" cy="55" r="3" fill={p.bg}/>
      <circle cx="100" cy="103" r="3" fill={p.bg}/>
      <circle cx="115" cy="103" r="3" fill={p.bg}/>
      <circle cx="130" cy="103" r="3" fill={p.bg}/>
    </svg>
  );
};

const EmptyIllustration = ({ size = 160, palette }) => {
  const p = palette || window.HAOLIN_TOKENS.colors;
  return (
    <svg viewBox="0 0 160 140" width={size} height={size * 140/160}>
      <ellipse cx="80" cy="125" rx="55" ry="5" fill={p.line}/>
      <circle cx="80" cy="70" r="42" fill={p.bgAlt}/>
      <circle cx="70" cy="65" r="3" fill={p.inkSoft}/>
      <circle cx="90" cy="65" r="3" fill={p.inkSoft}/>
      <rect x="70" y="82" width="20" height="3" rx="1.5" fill={p.inkSoft}/>
    </svg>
  );
};

// Small avatar (for 主揪 profile images) - geometric head+shoulders in a circle
const AvatarGeo = ({ size = 48, seed = 0, palette }) => {
  const p = palette || window.HAOLIN_TOKENS.colors;
  const tones = [p.primary, p.accent, p.gold, p.warm, p.info];
  const bgs = [p.primarySoft, p.accentSoft, p.bgAlt, p.lineSoft];
  const tone = tones[seed % tones.length];
  const bg = bgs[(seed*3) % bgs.length];
  return (
    <svg viewBox="0 0 48 48" width={size} height={size} style={{borderRadius: '50%', overflow: 'hidden', display:'block'}}>
      <rect width="48" height="48" fill={bg}/>
      <circle cx="24" cy="20" r="8" fill={tone}/>
      <rect x="12" y="30" width="24" height="24" rx="12" fill={tone}/>
    </svg>
  );
};

// Subtly-striped placeholder for real photos
const PhotoPlaceholder = ({ width=300, height=200, label='社區照片', src, palette, style }) => {
  if (src) {
    return (
      <img src={src} alt={label} loading="lazy" style={{
        width:'100%', height:'100%', objectFit:'cover',
        display:'block', ...style,
      }}/>
    );
  }
  const p = palette || window.HAOLIN_TOKENS.colors;
  const stripeId = 'ph_' + Math.random().toString(36).slice(2,8);
  return (
    <svg viewBox={`0 0 ${width} ${height}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{display:'block', ...style}}>
      <defs>
        <pattern id={stripeId} width="14" height="14" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
          <rect width="14" height="14" fill={p.bgAlt}/>
          <rect width="7" height="14" fill={p.lineSoft}/>
        </pattern>
      </defs>
      <rect width={width} height={height} fill={`url(#${stripeId})`}/>
      <text x={width/2} y={height/2+4} textAnchor="middle" fill={p.inkMuted} fontSize="11" fontFamily="ui-monospace, SFMono-Regular, monospace">[ {label} ]</text>
    </svg>
  );
};

// === New: hand-drawn-ish supportive illustrations (still stylized) ===

// Two hands overlapping / holding — softer curves, but kept geometric
const HandsOverlap = ({ size = 180, palette }) => {
  const p = palette || window.HAOLIN_TOKENS.colors;
  return (
    <svg viewBox="0 0 200 160" width={size} height={size * 160/200} style={{display:'block'}}>
      {/* Soft circle backdrop */}
      <circle cx="100" cy="82" r="70" fill={p.primarySoft} opacity="0.55"/>
      {/* Lower forearm + hand (primary) */}
      <path d="M 30 130 C 50 120, 72 114, 96 108 C 110 105, 122 104, 130 110 C 138 117, 134 128, 120 132 C 100 138, 60 140, 30 130 Z"
        fill={p.primary}/>
      <ellipse cx="128" cy="115" rx="10" ry="7" fill={p.primaryDark} opacity="0.4"/>
      {/* Upper hand (accent, reaching in from the other side) */}
      <path d="M 170 36 C 150 48, 130 60, 110 74 C 96 84, 86 90, 90 100 C 96 112, 110 108, 128 98 C 150 86, 168 70, 180 52 C 186 42, 180 30, 170 36 Z"
        fill={p.accent}/>
      <ellipse cx="120" cy="94" rx="9" ry="6" fill={p.accentDark || '#7A9D6B'} opacity="0.4"/>
      {/* Warmth dots */}
      <circle cx="80" cy="48" r="3" fill={p.warm}/>
      <circle cx="60" cy="72" r="2" fill={p.gold}/>
      <circle cx="160" cy="108" r="2.5" fill={p.warm}/>
    </svg>
  );
};

// Side-by-side walking figures
const SideBySide = ({ size = 200, palette }) => {
  const p = palette || window.HAOLIN_TOKENS.colors;
  return (
    <svg viewBox="0 0 200 160" width={size} height={size * 160/200} style={{display:'block'}}>
      <ellipse cx="100" cy="140" rx="80" ry="8" fill={p.line} opacity="0.6"/>
      {/* Path behind */}
      <path d="M 20 120 Q 100 100, 180 120" stroke={p.gold} strokeWidth="2" strokeDasharray="3 4" fill="none" opacity="0.5"/>
      {/* Person A */}
      <g transform="translate(65, 40)">
        <circle cx="0" cy="0" r="14" fill={p.primary}/>
        <rect x="-14" y="14" width="28" height="42" rx="12" fill={p.primary}/>
        <rect x="-8" y="55" width="6" height="28" rx="2" fill={p.primaryDark}/>
        <rect x="2" y="55" width="6" height="28" rx="2" fill={p.primaryDark}/>
      </g>
      {/* Person B */}
      <g transform="translate(125, 38)">
        <circle cx="0" cy="0" r="14" fill={p.accent}/>
        <rect x="-14" y="14" width="28" height="42" rx="12" fill={p.accent}/>
        <rect x="-8" y="55" width="6" height="28" rx="2" fill={p.accentDark || '#7A9D6B'}/>
        <rect x="2" y="55" width="6" height="28" rx="2" fill={p.accentDark || '#7A9D6B'}/>
      </g>
      {/* Holding hands line between */}
      <line x1="78" y1="72" x2="112" y2="72" stroke={p.warm} strokeWidth="4" strokeLinecap="round"/>
    </svg>
  );
};

// === Six facet icons (~80x80 illustrations) ===
const FacetMegaphone = ({ size = 80, color, bg }) => {
  const p = window.HAOLIN_TOKENS.colors;
  const tone = color || p.primary;
  const sft  = bg || p.primarySoft;
  return (
    <svg viewBox="0 0 80 80" width={size} height={size}>
      <circle cx="40" cy="40" r="36" fill={sft}/>
      <path d="M 22 42 L 22 38 L 50 26 L 58 26 L 58 54 L 50 54 L 22 42 Z" fill={tone}/>
      <rect x="16" y="36" width="8" height="10" rx="2" fill={tone} opacity="0.7"/>
      {/* Sound waves */}
      <path d="M 62 32 Q 70 40, 62 48" stroke={tone} strokeWidth="2.5" fill="none" strokeLinecap="round"/>
      <path d="M 66 28 Q 78 40, 66 52" stroke={tone} strokeWidth="2" fill="none" strokeLinecap="round" opacity="0.6"/>
    </svg>
  );
};

const FacetClipboard = ({ size = 80, color, bg }) => {
  const p = window.HAOLIN_TOKENS.colors;
  const tone = color || p.gold;
  const sft  = bg || p.bgAlt;
  return (
    <svg viewBox="0 0 80 80" width={size} height={size}>
      <circle cx="40" cy="40" r="36" fill={sft}/>
      <rect x="24" y="20" width="32" height="42" rx="4" fill={p.paper} stroke={tone} strokeWidth="2"/>
      <rect x="32" y="15" width="16" height="8" rx="2" fill={tone}/>
      <line x1="30" y1="32" x2="46" y2="32" stroke={tone} strokeWidth="2" strokeLinecap="round"/>
      <line x1="30" y1="40" x2="50" y2="40" stroke={tone} strokeWidth="2" strokeLinecap="round" opacity="0.6"/>
      <line x1="30" y1="48" x2="48" y2="48" stroke={tone} strokeWidth="2" strokeLinecap="round" opacity="0.6"/>
      <circle cx="28" cy="32" r="1.5" fill={tone}/>
      <circle cx="28" cy="40" r="1.5" fill={tone}/>
      <circle cx="28" cy="48" r="1.5" fill={tone}/>
    </svg>
  );
};

const FacetGear = ({ size = 80, color, bg }) => {
  const p = window.HAOLIN_TOKENS.colors;
  const tone = color || p.info;
  const sft  = bg || '#E2EBF1';
  return (
    <svg viewBox="0 0 80 80" width={size} height={size}>
      <circle cx="40" cy="40" r="36" fill={sft}/>
      {/* Chat bubble */}
      <path d="M 18 28 Q 18 22, 24 22 L 44 22 Q 50 22, 50 28 L 50 40 Q 50 46, 44 46 L 30 46 L 22 52 L 24 46 Q 18 46, 18 40 Z" fill={p.paper} stroke={tone} strokeWidth="2"/>
      <circle cx="28" cy="34" r="1.8" fill={tone}/>
      <circle cx="34" cy="34" r="1.8" fill={tone}/>
      <circle cx="40" cy="34" r="1.8" fill={tone}/>
      {/* Gear */}
      <g transform="translate(54, 50)">
        <circle r="10" fill={tone}/>
        <circle r="4" fill={sft}/>
        {[0,45,90,135,180,225,270,315].map((a,i)=>(
          <rect key={i} x="-1.5" y="-14" width="3" height="4" fill={tone} transform={`rotate(${a})`}/>
        ))}
      </g>
    </svg>
  );
};

const FacetTwoChairs = ({ size = 80, color, bg }) => {
  const p = window.HAOLIN_TOKENS.colors;
  const tone = color || p.accent;
  const sft  = bg || p.accentSoft;
  return (
    <svg viewBox="0 0 80 80" width={size} height={size}>
      <circle cx="40" cy="40" r="36" fill={sft}/>
      {/* Person A */}
      <circle cx="26" cy="32" r="6" fill={tone}/>
      <rect x="19" y="38" width="14" height="18" rx="6" fill={tone}/>
      {/* Person B */}
      <circle cx="54" cy="32" r="6" fill={p.warm}/>
      <rect x="47" y="38" width="14" height="18" rx="6" fill={p.warm}/>
      {/* Heart bubble between them */}
      <path d="M 40 48 C 35 44, 32 48, 36 52 L 40 56 L 44 52 C 48 48, 45 44, 40 48 Z" fill={p.primary}/>
      <ellipse cx="40" cy="62" rx="22" ry="3" fill={tone} opacity="0.3"/>
    </svg>
  );
};

const FacetThreePeople = ({ size = 80, color, bg }) => {
  const p = window.HAOLIN_TOKENS.colors;
  const tone = color || p.warm;
  const sft  = bg || '#F7E3D2';
  return (
    <svg viewBox="0 0 80 80" width={size} height={size}>
      <circle cx="40" cy="40" r="36" fill={sft}/>
      <circle cx="22" cy="32" r="5" fill={p.primary}/>
      <rect x="16" y="37" width="12" height="16" rx="5" fill={p.primary}/>
      <circle cx="40" cy="30" r="6" fill={tone}/>
      <rect x="33" y="36" width="14" height="18" rx="6" fill={tone}/>
      <circle cx="58" cy="32" r="5" fill={p.accent}/>
      <rect x="52" y="37" width="12" height="16" rx="5" fill={p.accent}/>
      <ellipse cx="40" cy="62" rx="28" ry="3" fill={tone} opacity="0.25"/>
    </svg>
  );
};

const FacetCandle = ({ size = 80, color, bg }) => {
  const p = window.HAOLIN_TOKENS.colors;
  const tone = color || p.gold;
  const sft  = bg || p.bgAlt;
  return (
    <svg viewBox="0 0 80 80" width={size} height={size}>
      <circle cx="40" cy="40" r="36" fill={sft}/>
      {/* Candle */}
      <rect x="34" y="40" width="12" height="22" rx="2" fill={p.paper} stroke={tone} strokeWidth="1.5"/>
      <rect x="30" y="60" width="20" height="4" rx="1" fill={tone}/>
      {/* Flame */}
      <path d="M 40 38 C 36 32, 36 26, 40 22 C 44 26, 44 32, 40 38 Z" fill={p.primary}/>
      <ellipse cx="40" cy="32" rx="2" ry="4" fill={p.warm}/>
      {/* Halo */}
      <circle cx="40" cy="30" r="14" fill={p.primary} opacity="0.12"/>
    </svg>
  );
};

Object.assign(window, {
  PeopleGathering, HomePlate, HandsCircle, ChatBubbles,
  EmptyIllustration, AvatarGeo, PhotoPlaceholder,
  HandsOverlap, SideBySide,
  FacetMegaphone, FacetClipboard, FacetGear, FacetTwoChairs, FacetThreePeople, FacetCandle,
});
