/**
 * Shared map marker utilities — single-color markers with 5-tier color scale.
 *
 * Exposes window.PNMarkers = { scoreColor, makeIcon }
 *
 * scoreColor(score) → hex color string (5 tiers, colorblind-safe luminance steps)
 * makeIcon(opts)    → L.divIcon with single-color circle
 *
 * opts = {
 *   size:       number,           // marker diameter in px
 *   color:      string,           // hex color (from scoreColor)
 *   muted:      boolean,          // faded, no click affordance
 *   highlight:  boolean,          // blue outer glow (user's geo city)
 *   pulse:      boolean,          // gentle pulse (high score)
 * }
 */
(function() {
  'use strict';

  // 5-tier color scale — distinct luminance at each tier for deuteranopia/protanopia
  function scoreColor(score) {
    if (score >= 80) return '#15803D'; // deep green — excellent
    if (score >= 60) return '#0D9488'; // teal — good
    if (score >= 40) return '#D97706'; // amber — moderate
    if (score >= 20) return '#EA580C'; // orange-red — below avg
    return '#DC2626';                  // red — poor
  }

  function makeIcon(opts) {
    var s = Math.round(opts.size);

    var cls = 'pn-marker';
    if (opts.muted)     cls += ' pn-marker--muted';
    if (opts.highlight) cls += ' pn-marker--highlight';
    if (opts.pulse && !opts.muted) cls += ' pn-marker--pulse';

    var html = '<div class="' + cls + '" style="width:' + s + 'px;height:' + s + 'px;background:' + opts.color + ';"></div>';

    return L.divIcon({
      className: '',
      html: html,
      iconSize: [s, s],
      iconAnchor: [s / 2, s / 2],
    });
  }

  window.PNMarkers = {
    scoreColor: scoreColor,
    makeIcon: makeIcon,
  };
})();
