<?php
// ============================================================
//  MediCore — Medicine Form-Type Icons
//  File: includes/form_icons.php
//  Shared icon lookup so staff can visually identify a medicine's
//  form (Tablet, Capsule, Syrup, Injection, ...) at a glance across
//  every screen that lists products. Keep this list in sync with
//  the canonical form options in product/list.php's productForm()
//  (`<select id="f-form">` options) and with assets/form-icons.js.
// ============================================================

const FORM_ICON_MAP = [
    'TABLET'      => '🌗',
    'CAPSULE'     => '💊',
    'SYRUP'       => '🥄',
    'INJECTION'   => '💉',
    'CREAM'       => '🧴',
    'DROPS'       => '💧',
    'INHALER'     => '💨',
    'SUPPOSITORY' => '🔺',
    'POWDER'      => '🧂',
    'SUSPENSION'  => '🌀',
    'GEL'         => '🫧',
    'OINTMENT'    => '🧈',
    'PATCH'       => '🩹',
    'OTHER'       => '❔',
];

/**
 * Return the emoji icon for a medicine form type (case-insensitive,
 * whitespace-tolerant). Returns '' for blank/unknown forms so callers
 * never render a misleading icon for a product that has none set.
 */
function form_icon(?string $form): string {
    $key = strtoupper(trim($form ?? ''));
    return FORM_ICON_MAP[$key] ?? '';
}

/**
 * Convenience helper: icon + escaped product name, ready to echo.
 * Falls back gracefully when $form is empty (no icon, just the name).
 */
function form_icon_name(?string $form, string $name): string {
    $icon = form_icon($form);
    return ($icon !== '' ? $icon . ' ' : '') . htmlspecialchars($name);
}
