/**
 * 分类 id → Ionicons 图标名映射（替换原 CategoryPicker 的 emoji 表）。
 * 纯数据模块：仅含类型导入（运行时零依赖），可在 Vitest(node) 中直接测试。
 */
import type { ComponentProps } from 'react';
import type { Ionicons } from '@expo/vector-icons';

export type IoniconName = ComponentProps<typeof Ionicons>['name'];

export const CATEGORY_ICON_NAMES: Record<string, IoniconName> = {
  food: 'fast-food-outline',
  transport: 'bus-outline',
  shopping: 'bag-handle-outline',
  housing_utility: 'water-outline',
  housing_rent: 'home-outline',
  housing_communication: 'call-outline',
  entertainment: 'game-controller-outline',
  services: 'construct-outline',
  personal_care: 'sparkles-outline',
  clothing: 'shirt-outline',
  health: 'medkit-outline',
  learning: 'book-outline',
  salary: 'wallet-outline',
  income_activity: 'gift-outline',
  income_investment: 'trending-up-outline',
  // 方向兜底（无分类交易：TransactionCard 传 expense/income/transfer）
  expense: 'cart-outline',
  income: 'cash-outline',
  transfer: 'swap-horizontal-outline',
};

const FALLBACK_ICON: IoniconName = 'pricetag-outline';

/** 取分类图标：具名映射，否则 fallback（hasOwn 防原型链穿透）。 */
export function getCategoryIcon(categoryId: string): IoniconName {
  return Object.hasOwn(CATEGORY_ICON_NAMES, categoryId)
    ? CATEGORY_ICON_NAMES[categoryId]
    : FALLBACK_ICON;
}
