/* Per-peptide accent + SVG glyph.
 * Loaded by both peptides/index.jsx and peptides/peptide.jsx via window globals.
 *
 * Each peptide gets:
 *   • a unique line-art SVG glyph that matches its mechanism in spirit
 *   • a brand-friendly accent color used for halo, dots, borders
 */

window.PEPTIDE_ACCENTS = {
  "sermorelin":   "#D9A47C",  // gold — GH/sleep
  "nad-plus":     "#7C5BFF",  // violet — mitochondrial
  "bpc-157":      "#10B981",  // green — healing
  "ipamorelin":   "#F08A4B",  // orange — GH amplifier
  "ghk-cu":       "#C68B7C",  // copper — copper-tripeptide
  "glutathione":  "#8FA3B8",  // silver-blue — antioxidant
  "selank":       "#6FD8FF",  // cyan — calm focus
  "dsip":         "#5A7BBA",  // deep blue — delta sleep
  "b12-mic":      "#E8C76B",  // yellow — energy
  "cjc-1295":     "#B8533A",  // brick — paired GHRH
};

window.PEPTIDE_GLYPH = ({ slug, color, size = 360 }) => {
  const stroke = color || window.PEPTIDE_ACCENTS[slug] || "#6b6b6b";
  const wash = stroke + "22";
  const common = { width: size, height: size, viewBox: "0 0 200 200", fill: "none", stroke, strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round" };

  if (slug === "sermorelin") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      {/* Crescent — nightly cycle */}
      <path d="M 154 78 C 134 78, 118 94, 118 114 C 118 132, 132 146, 150 148 C 138 144, 130 132, 130 116 C 130 96, 142 82, 154 78 Z" fill={wash} strokeWidth="2"/>
      {/* GH pulse wave */}
      <path d="M 30 130 C 40 130, 44 110, 54 110 C 64 110, 64 80, 74 80 C 84 80, 84 134, 94 134 C 102 134, 104 124, 110 124" strokeWidth="2.4"/>
      <circle cx="74" cy="80" r="4" fill={stroke}/>
      <circle cx="94" cy="134" r="3" fill={stroke}/>
    </svg>
  );

  if (slug === "nad-plus") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      {/* Hex molecule — nicotinamide ring */}
      <polygon points="100,52 132,70 132,108 100,126 68,108 68,70" fill={wash} strokeWidth="2.2"/>
      <circle cx="100" cy="52" r="4" fill={stroke}/>
      <circle cx="132" cy="70" r="4" fill={stroke}/>
      <circle cx="132" cy="108" r="4" fill={stroke}/>
      <circle cx="100" cy="126" r="4" fill={stroke}/>
      <circle cx="68" cy="108" r="4" fill={stroke}/>
      <circle cx="68" cy="70" r="4" fill={stroke}/>
      {/* Energy bolts */}
      <path d="M 144 124 L 148 138 L 156 134 L 152 152 M 152 152 L 158 144 L 168 144" strokeWidth="2.2"/>
      <path d="M 44 56 L 56 60 L 50 70" strokeWidth="2.2"/>
    </svg>
  );

  if (slug === "bpc-157") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      {/* Tendon strand — split + healing chevron */}
      <path d="M 40 70 C 60 70, 80 84, 90 100" strokeWidth="2.4"/>
      <path d="M 40 130 C 60 130, 80 116, 90 100" strokeWidth="2.4"/>
      <path d="M 110 100 C 120 100, 140 100, 160 100" strokeWidth="2.4"/>
      {/* Healing pulse cross */}
      <circle cx="100" cy="100" r="18" fill={wash} strokeWidth="2.4"/>
      <path d="M 100 88 L 100 112 M 88 100 L 112 100" strokeWidth="2.6"/>
      {/* Speed marks */}
      <path d="M 144 80 L 156 76 M 148 90 L 160 88 M 144 120 L 156 124 M 148 110 L 160 112" strokeWidth="2"/>
    </svg>
  );

  if (slug === "ipamorelin") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      {/* Stacked rising GH pulses */}
      <path d="M 30 150 C 50 150, 60 120, 80 120 C 100 120, 110 90, 130 90 C 150 90, 160 60, 174 60" strokeWidth="2.4"/>
      <path d="M 30 160 C 50 160, 60 140, 80 140 C 100 140, 110 120, 130 120 C 150 120, 160 100, 174 100" strokeWidth="2" opacity="0.55"/>
      <circle cx="80" cy="120" r="4" fill={stroke}/>
      <circle cx="130" cy="90" r="4" fill={stroke}/>
      <circle cx="174" cy="60" r="5" fill={stroke}/>
      {/* Up arrow at peak */}
      <path d="M 168 66 L 174 60 L 180 66" strokeWidth="2.4"/>
    </svg>
  );

  if (slug === "ghk-cu") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      {/* Tripeptide — 3 amino-acid nodes */}
      <line x1="62" y1="120" x2="100" y2="68" strokeWidth="2.2"/>
      <line x1="100" y1="68" x2="138" y2="120" strokeWidth="2.2"/>
      <line x1="62" y1="120" x2="138" y2="120" strokeWidth="2.2"/>
      <circle cx="62" cy="120" r="9" fill={wash} strokeWidth="2.4"/>
      <circle cx="100" cy="68" r="9" fill={wash} strokeWidth="2.4"/>
      <circle cx="138" cy="120" r="9" fill={wash} strokeWidth="2.4"/>
      {/* Copper droplet */}
      <path d="M 100 130 C 110 142, 110 156, 100 162 C 90 156, 90 142, 100 130 Z" fill={stroke} stroke="none"/>
      <text x="100" y="150" textAnchor="middle" fill="#fff" fontFamily="JetBrains Mono" fontSize="9" fontWeight="700">Cu</text>
    </svg>
  );

  if (slug === "glutathione") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      {/* Shield */}
      <path d="M 100 50 L 144 64 L 144 110 C 144 134, 124 152, 100 158 C 76 152, 56 134, 56 110 L 56 64 Z" fill={wash} strokeWidth="2.4"/>
      {/* Inner check */}
      <path d="M 80 104 L 94 118 L 122 90" strokeWidth="3" stroke={stroke} fill="none"/>
      {/* Free-radical particles being deflected */}
      <circle cx="42" cy="58" r="2.4" fill={stroke}/>
      <circle cx="32" cy="76" r="2" fill={stroke} opacity="0.7"/>
      <circle cx="160" cy="58" r="2.4" fill={stroke}/>
      <circle cx="170" cy="76" r="2" fill={stroke} opacity="0.7"/>
      <path d="M 36 60 L 46 64 M 28 80 L 38 82 M 156 60 L 166 64 M 162 80 L 172 82" strokeWidth="1.6" opacity="0.6"/>
    </svg>
  );

  if (slug === "selank") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      {/* Concentric calm rings */}
      <circle cx="100" cy="100" r="68" strokeDasharray="2 6" opacity="0.45"/>
      <circle cx="100" cy="100" r="50" strokeDasharray="3 5" opacity="0.6"/>
      <circle cx="100" cy="100" r="32" strokeDasharray="4 4" opacity="0.8"/>
      {/* Center focus dot */}
      <circle cx="100" cy="100" r="10" fill={stroke}/>
      <circle cx="100" cy="100" r="4" fill="#fff"/>
      {/* Brain wave */}
      <path d="M 30 38 C 46 38, 50 28, 64 28 C 78 28, 82 48, 96 48" strokeWidth="2"/>
      <path d="M 104 152 C 118 152, 122 172, 136 172 C 150 172, 154 162, 170 162" strokeWidth="2"/>
    </svg>
  );

  if (slug === "dsip") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      {/* Delta wave going deeper */}
      <path d="M 24 90 L 50 90 L 60 70 L 70 90 L 80 90 L 90 60 L 100 90 L 110 90 L 120 50 L 130 90 L 140 90 L 150 70 L 160 90 L 176 90" strokeWidth="2.2"/>
      <path d="M 24 130 L 50 130 L 65 108 L 80 130 L 95 130 L 110 100 L 125 130 L 140 130 L 155 110 L 170 130 L 176 130" strokeWidth="2" opacity="0.6"/>
      {/* Z's */}
      <text x="148" y="58" fontFamily="Archivo" fontWeight="900" fontSize="22" fill={stroke}>z</text>
      <text x="160" y="46" fontFamily="Archivo" fontWeight="900" fontSize="16" fill={stroke} opacity="0.7">z</text>
      <text x="170" y="38" fontFamily="Archivo" fontWeight="900" fontSize="11" fill={stroke} opacity="0.5">z</text>
    </svg>
  );

  if (slug === "b12-mic") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      {/* Vial */}
      <rect x="78" y="44" width="44" height="14" rx="3" fill={wash} strokeWidth="2.2"/>
      <rect x="86" y="58" width="28" height="6" fill={stroke} stroke="none"/>
      <path d="M 84 64 L 84 144 C 84 154, 92 162, 100 162 C 108 162, 116 154, 116 144 L 116 64 Z" fill={wash} strokeWidth="2.2"/>
      {/* Liquid level */}
      <path d="M 84 110 L 116 110 L 116 144 C 116 154, 108 162, 100 162 C 92 162, 84 154, 84 144 Z" fill={stroke} opacity="0.35" stroke="none"/>
      {/* Energy spike */}
      <path d="M 140 60 L 152 60 L 144 80 L 158 80 L 138 110 L 146 86 L 134 86 Z" fill={stroke} stroke="none"/>
    </svg>
  );

  if (slug === "cjc-1295") return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      {/* Twin paired pulses */}
      <path d="M 28 134 C 48 134, 56 92, 76 92 C 96 92, 104 130, 124 130" strokeWidth="2.4"/>
      <path d="M 76 134 C 96 134, 104 60, 124 60 C 144 60, 152 110, 172 110" strokeWidth="2.4" opacity="0.85"/>
      <circle cx="76" cy="92" r="5" fill={stroke}/>
      <circle cx="124" cy="60" r="5" fill={stroke}/>
      {/* Connect line */}
      <path d="M 76 92 L 124 60" strokeWidth="1.4" strokeDasharray="2 3" opacity="0.5"/>
      {/* Plus marker */}
      <path d="M 156 50 L 156 30 M 146 40 L 166 40" strokeWidth="2.2"/>
    </svg>
  );

  // Fallback — generic peptide chain
  return (
    <svg {...common}>
      <circle cx="100" cy="100" r="86" fill={wash} stroke="none"/>
      <circle cx="100" cy="100" r="80" strokeDasharray="2 6" opacity="0.55"/>
      <circle cx="60" cy="100" r="10" fill={wash} strokeWidth="2.2"/>
      <circle cx="100" cy="100" r="10" fill={wash} strokeWidth="2.2"/>
      <circle cx="140" cy="100" r="10" fill={wash} strokeWidth="2.2"/>
      <line x1="70" y1="100" x2="90" y2="100" strokeWidth="2"/>
      <line x1="110" y1="100" x2="130" y2="100" strokeWidth="2"/>
    </svg>
  );
};
