// fc-ui-icons.jsx, OnWeight functional UI icon set (Tier 2).
//
// The companion to the bespoke sport marks: a lighter monoline utility set on the
// same 64-unit grid, rounded terminals, ONE constant stroke. Single-ink by default;
// brand red is reserved for the live/accent detail (the day dot, the goal flag, the
// projected point, an alert), never decorative. Pace glyphs are single-colour so the
// tone system (green / amber / red) can recolour the whole mark in context.

const U_VB = 64;
const U_SW = 4;       // constant stroke
const U_SW2 = 3;      // secondary detail
let _UW = 1;          // optical-weight multiplier, set per render size

const u = (c = 'var(--ink)', w = U_SW) => ({ fill: 'none', stroke: c, strokeWidth: +(w * _UW).toFixed(2), strokeLinecap: 'round', strokeLinejoin: 'round', vectorEffect: 'non-scaling-stroke' });
const ud = (c = 'var(--ink)', w = U_SW) => ({ ...u(c, w), strokeDasharray: '3 4.5' });

const UI_ICONS = {
  // ── NAVIGATION ─────────────────────────────────────────────
  today: (c, a) => (<g><rect x="13" y="16" width="38" height="34" rx="6" {...u(c)} /><path d="M13 26 H51" {...u(c)} /><path d="M23 11 V19 M41 11 V19" {...u(c)} /><circle cx="32" cy="38" r="3.6" fill={a} /></g>),
  plan: (c) => (<g><rect x="15" y="15" width="34" height="38" rx="5" {...u(c)} /><rect x="25" y="11" width="14" height="8" rx="3" {...u(c)} /><path d="M23 31 H41 M23 39 H40 M23 47 H34" {...u(c, U_SW2)} /></g>),
  trend: (c) => (<g><path d="M16 13 V50 H51" {...u(c)} /><path d="M22 25 L30 34 L37 30 L48 42" {...u(c)} /></g>),
  more: (c) => (<g><circle cx="17" cy="32" r="3.6" fill={c} /><circle cx="32" cy="32" r="3.6" fill={c} /><circle cx="47" cy="32" r="3.6" fill={c} /></g>),
  log: (c, a) => (<g><path d="M32 16 V48 M16 32 H48" {...u(a, 4.6)} /></g>),

  // ── ACTIONS & UI ───────────────────────────────────────────
  back: (c) => (<g><path d="M38 15 L23 32 L38 49" {...u(c)} /></g>),
  forward: (c) => (<g><path d="M26 15 L41 32 L26 49" {...u(c)} /></g>),
  close: (c) => (<g><path d="M19 19 L45 45 M45 19 L19 45" {...u(c)} /></g>),
  check: (c) => (<g><path d="M16 33 L28 45 L48 20" {...u(c)} /></g>),
  add: (c) => (<g><path d="M32 16 V48 M16 32 H48" {...u(c)} /></g>),
  gear: (c) => (<g><path d="M13 22 H51 M13 32 H51 M13 42 H51" {...u(c, U_SW2)} /><circle cx="27" cy="22" r="4.5" fill="var(--paper)" {...u(c, U_SW2)} /><circle cx="40" cy="32" r="4.5" fill="var(--paper)" {...u(c, U_SW2)} /><circle cx="22" cy="42" r="4.5" fill="var(--paper)" {...u(c, U_SW2)} /></g>),
  info: (c) => (<g><circle cx="32" cy="32" r="18" {...u(c)} /><path d="M32 31 V42" {...u(c)} /><path d="M32 22 V22.5" {...u(c)} /></g>),
  calendar: (c) => (<g><rect x="13" y="16" width="38" height="34" rx="6" {...u(c)} /><path d="M13 26 H51" {...u(c)} /><path d="M23 11 V19 M41 11 V19" {...u(c)} /></g>),
  bell: (c) => (<g><path d="M32 13 a12 12 0 0 1 12 12 v7 l4 7 H16 l4 -7 v-7 a12 12 0 0 1 12 -12 Z" {...u(c)} /><path d="M27 46 a5 5 0 0 0 10 0" {...u(c, U_SW2)} /></g>),

  // ── PACE & DATA ────────────────────────────────────────────
  scale: (c) => (<g><path d="M32 12 V49" {...u(c)} /><circle cx="32" cy="12" r="2.6" fill={c} /><path d="M15 21 H49" {...u(c)} /><path d="M15 21 L9 30 M15 21 L21 30 M9 30 a6 4.5 0 0 0 12 0" {...u(c, U_SW2)} /><path d="M49 21 L43 30 M49 21 L55 30 M43 30 a6 4.5 0 0 0 12 0" {...u(c, U_SW2)} /><path d="M24 50 H40" {...u(c)} /></g>),
  loss: (c) => (<g><path d="M32 16 V46 M21 35 L32 48 L43 35" {...u(c)} /></g>),
  gain: (c) => (<g><path d="M32 48 V18 M21 29 L32 16 L43 29" {...u(c)} /></g>),
  ontrack: (c) => (<g><circle cx="32" cy="32" r="18" {...u(c)} /><path d="M23 33 L29 40 L42 24" {...u(c)} /></g>),
  toofast: (c) => (<g><path d="M20 22 L32 33 L44 22" {...u(c)} /><path d="M20 33 L32 44 L44 33" {...u(c)} /></g>),
  behind: (c) => (<g><circle cx="32" cy="32" r="17" {...u(c)} /><path d="M32 23 V33 L39 38" {...u(c)} /></g>),
  offpace: (c) => (<g><path d="M32 14 L51 47 H13 Z" {...u(c)} /><path d="M32 27 V37" {...u(c)} /><path d="M32 42.5 V43" {...u(c)} /></g>),
  goal: (c, a) => (<g><path d="M22 15 H42 V24 a10 10 0 0 1 -20 0 Z" {...u(c)} /><path d="M22 18 H15 a7 7 0 0 0 7 9 M42 18 H49 a7 7 0 0 1 -7 9" {...u(c, U_SW2)} /><path d="M32 34 V41 M24 50 H40 M28 41 H36 V50" {...u(c)} /><path d="M32 16.8 L33.5 20 L37 20.3 L34.3 22.6 L35.2 26 L32 24.2 L28.8 26 L29.7 22.6 L27 20.3 L30.5 20 Z" fill={a} /></g>),
  velocity: (c, a) => (<g><path d="M14 43 a18 18 0 0 1 36 0" {...u(c)} /><path d="M32 43 L43 28" {...u(a)} /><circle cx="32" cy="43" r="2.6" fill={c} /></g>),

  // ── PLAN & ONBOARDING ──────────────────────────────────────
  openEnded: (c) => (<g><path d="M13 32 H44 M36 23 L48 32 L36 41" {...u(c)} /></g>),
  target: (c, a) => (<g><circle cx="32" cy="32" r="18" {...u(c)} /><circle cx="32" cy="32" r="10" {...u(c)} /><circle cx="32" cy="32" r="3.2" fill={a} /></g>),
  strategy: (c, a) => (<g><path d="M15 17 C26 21 24 33 33 37 C40 40 42 44 49 47" {...u(c)} /><circle cx="15" cy="17" r="3" fill={c} /><circle cx="49" cy="47" r="3.8" fill={a} /></g>),
  confirm: (c, a) => (<g><rect x="15" y="15" width="34" height="38" rx="5" {...u(c)} /><rect x="25" y="11" width="14" height="8" rx="3" {...u(c)} /><path d="M23 34 L29 40 L41 27" {...u(a)} /></g>),
  lock: (c) => (<g><rect x="17" y="29" width="30" height="21" rx="4" {...u(c)} /><path d="M23 29 V23 a9 9 0 0 1 18 0 V29" {...u(c)} /><circle cx="32" cy="39" r="2.2" fill={c} /></g>),
  division: (c) => (<g><circle cx="32" cy="32" r="18" {...u(c)} /><circle cx="32" cy="32" r="6" {...u(c)} /></g>),
  equipment: (c, a) => (<g><path d="M16 18 H48 L45 46 H35 L32 33 L29 46 H19 Z" {...u(c)} /><path d="M16 24 H48" {...u(c, U_SW2)} /><path d="M22 25 L24 44" {...u(a)} /></g>),
  refresh: (c) => (<g><path d="M47 24 a17 17 0 1 0 3.5 13" {...u(c)} /><path d="M48 13 V25 H36" {...u(c)} /></g>),
  hydration: (c) => (<g><path d="M32 13 C41 28 45 34 45 40 a13 13 0 0 1 -26 0 C19 34 23 28 32 13 Z" {...u(c)} /></g>),
  rehydration: (c, a) => (<g><path d="M28 13 C37 28 41 34 41 40 a13 13 0 0 1 -26 0 C15 34 19 28 28 13 Z" {...u(c)} /><path d="M47 18 V30 M41 24 H53" {...u(a)} /></g>),
  refeed: (c) => (<g><path d="M15 31 H49 a17 17 0 0 1 -34 0 Z" {...u(c)} /><path d="M28 21 q3 -4 0 -9 M37 21 q3 -4 0 -9" {...u(c, U_SW2)} /></g>),
  cycle: (c, a) => (<g><circle cx="32" cy="32" r="17" {...u(c)} /><path d="M32 15 A17 17 0 0 1 49 32" {...u(a)} /><circle cx="49" cy="32" r="3.2" fill={a} /></g>),
  retention: (c, a) => (<g><path d="M13 38 C21 24 28 24 32 33 C36 42 43 42 51 26" {...u(c)} /><circle cx="32" cy="33" r="3.4" fill={a} /></g>),
  profile: (c, a) => (<g><circle cx="32" cy="22" r="9" {...u(c)} /><path d="M16 49 a16 16 0 0 1 32 0" {...u(c)} /><path d="M23.5 18 H40.5" {...u(a)} /></g>),

  // ── LIFECYCLE & MORE ───────────────────────────────────────
  noCamp: (c) => (<g><path d="M43 34 a15 15 0 1 1 -15 -16 a12 12 0 0 0 15 16 Z" {...u(c)} /></g>),
  descent: (c) => (<g><path d="M13 19 H25 V31 H37 V43 H51" {...u(c)} /></g>),
  made: (c, a) => (<g><path d="M22 15 H42 V24 a10 10 0 0 1 -20 0 Z" {...u(c)} /><path d="M22 18 H15 a7 7 0 0 0 7 9 M42 18 H49 a7 7 0 0 1 -7 9" {...u(c, U_SW2)} /><path d="M32 34 V41 M24 50 H40 M28 41 H36 V50" {...u(c)} /></g>),
  missed: (c) => (<g><path d="M32 13 V47" {...u(c)} /><path d="M16 18 L48 26" {...u(c)} /><path d="M16 18 L11 27 M16 18 L21 27 M11 27 a5 4 0 0 0 10 0" {...u(c, U_SW2)} /><path d="M48 26 L43 35 M48 26 L53 35 M43 35 a5 4 0 0 0 10 0" {...u(c, U_SW2)} /><path d="M24 50 H40" {...u(c)} /></g>),
  paused: (c) => (<g><path d="M26 16 V48 M38 16 V48" {...u(c, 5)} /></g>),
  checkin: (c, a) => (<g><rect x="13" y="16" width="38" height="34" rx="6" {...u(c)} /><path d="M13 26 H51" {...u(c)} /><path d="M23 11 V19 M41 11 V19" {...u(c)} /><path d="M24 38 L30 44 L42 31" {...u(a)} /></g>),
  streak: (c, a) => (<g><path d="M32 11 C40 22 42 30 42 38 a10 10 0 0 1 -20 0 C22 30 24 22 32 11 Z" {...u(c)} /><path d="M32 29 C35.5 33 36 37 34 40 a2.5 2.5 0 0 1 -4 0 C28 37 28.5 33 32 29 Z" fill={a} /></g>),
  archive: (c) => (<g><path d="M14 22 L21 14 H43 L50 22 V48 a2 2 0 0 1 -2 2 H16 a2 2 0 0 1 -2 -2 Z" {...u(c)} /><path d="M14 22 H50 M26 31 H38" {...u(c, U_SW2)} /></g>),
  learn: (c) => (<g><path d="M32 18 C27 14 19 14 14 16 V46 C19 44 27 44 32 48 C37 44 45 44 50 46 V16 C45 14 37 14 32 18 Z" {...u(c)} /><path d="M32 18 V48" {...u(c, U_SW2)} /></g>),
};

const UI_GROUPS = [
  { title: 'Navigation', sub: 'Four tabs plus the primary Log action (accented).', items: [
    { key: 'today', label: 'Today' }, { key: 'plan', label: 'Plan' }, { key: 'trend', label: 'Trend' }, { key: 'more', label: 'More' }, { key: 'log', label: 'Log · primary' },
  ]},
  { title: 'Actions & universal UI', sub: 'On every screen, chrome and controls.', items: [
    { key: 'back', label: 'Back' }, { key: 'forward', label: 'Disclosure' }, { key: 'close', label: 'Close' }, { key: 'check', label: 'Check' }, { key: 'add', label: 'Add' }, { key: 'gear', label: 'Settings' }, { key: 'info', label: 'Info' }, { key: 'calendar', label: 'Calendar' }, { key: 'bell', label: 'Reminder / alerts' },
  ]},
  { title: 'Pace & data', sub: 'Diagnosis, projection, the numbers. Pace marks recolour with the tone system.', items: [
    { key: 'scale', label: 'Scale / weigh-in' }, { key: 'loss', label: 'Loss' }, { key: 'gain', label: 'Gain' }, { key: 'ontrack', label: 'On track' }, { key: 'toofast', label: 'Cutting fast' }, { key: 'behind', label: 'Behind' }, { key: 'offpace', label: 'Off pace' }, { key: 'goal', label: 'Goal / win' }, { key: 'velocity', label: 'Rate of loss' },
  ]},
  { title: 'Plan & onboarding', sub: 'Setup, division rules, the cut and the cycle.', items: [
    { key: 'openEnded', label: 'Open-ended camp' }, { key: 'target', label: 'Target weight' }, { key: 'strategy', label: 'Cut strategy' }, { key: 'confirm', label: 'Confirm details' }, { key: 'lock', label: 'Unlock / paywall' }, { key: 'division', label: 'Division' }, { key: 'equipment', label: 'Equipment' }, { key: 'refresh', label: 'Re-weigh' }, { key: 'hydration', label: 'Hydration' }, { key: 'rehydration', label: 'Rehydration' }, { key: 'refeed', label: 'Refeed' }, { key: 'cycle', label: 'Cycle / phase' }, { key: 'retention', label: 'Retention curve' }, { key: 'profile', label: 'Profile' },
  ]},
  { title: 'Lifecycle & more', sub: 'Camp states, outcomes, archive and learn.', items: [
    { key: 'noCamp', label: 'No camp' }, { key: 'descent', label: 'Descent protocol' }, { key: 'made', label: 'Made / won' }, { key: 'missed', label: 'Missed' }, { key: 'paused', label: 'Paused' }, { key: 'checkin', label: 'Weekly check-in' }, { key: 'streak', label: 'Streak' }, { key: 'archive', label: 'Past camps' }, { key: 'learn', label: 'Learn' },
  ]},
];

function UIIcon({ name, size = 32, color = 'var(--ink)', accent = 'var(--red)' }) {
  const fn = UI_ICONS[name];
  if (!fn) return null;
  // non-scaling-stroke renders strokeWidth in literal px, so keep these light to sit
  // with the app's hairline UI: ~1.3px at list/tab sizes, a touch more at hero size.
  _UW = size >= 40 ? 0.4 : size >= 24 ? 0.32 : 0.3;
  return (
    <svg width={size} height={size} viewBox={`0 0 ${U_VB} ${U_VB}`} fill="none" role="img" aria-label={name}>
      {fn(color, accent)}
    </svg>
  );
}

Object.assign(window, { UI_ICONS, UI_GROUPS, UIIcon });
