// ============================================================
//  MediCore — Medicine Form-Type Icons (client-side)
//  File: assets/form-icons.js
//  Mirrors includes/form_icons.php — keep both in sync. Loaded
//  globally via includes/header.php so any page's JS can call
//  formIcon(form) or formIconName(form, name) without importing
//  anything extra.
// ============================================================
(function (global) {
  const FORM_ICON_MAP = {
    TABLET:      '🌗',
    CAPSULE:     '💊',
    SYRUP:       '🥄',
    INJECTION:   '💉',
    CREAM:       '🧴',
    DROPS:       '💧',
    INHALER:     '💨',
    SUPPOSITORY: '🔺',
    POWDER:      '🧂',
    SUSPENSION:  '🌀',
    GEL:         '🫧',
    OINTMENT:    '🧈',
    PATCH:       '🩹',
    OTHER:       '❔',
  };

  function formIcon(form) {
    if (!form) return '';
    const key = String(form).trim().toUpperCase();
    return FORM_ICON_MAP[key] || '';
  }

  // Convenience: "<icon> <escaped name>" ready to drop into a template
  // literal. Callers that already HTML-escape the name themselves
  // should just use formIcon(form) directly instead.
  function formIconName(form, name) {
    const icon = formIcon(form);
    const esc  = String(name || '').replace(/&/g,'&amp;').replace(/</g,'&lt;')
                                    .replace(/>/g,'&gt;').replace(/"/g,'&quot;');
    return icon ? `${icon} ${esc}` : esc;
  }

  global.FORM_ICON_MAP = FORM_ICON_MAP;
  global.formIcon      = formIcon;
  global.formIconName  = formIconName;
})(window);
