import {
  IconLayoutDashboard, IconUsersGroup, IconUser, IconBriefcase,
  IconReceipt, IconFileInvoice, IconCalculator, IconCash,
  IconReportMoney, IconSettings, IconUsers, IconShieldLock,
  IconCategory, IconKey, IconClipboardList, IconFolder,
  IconHome, IconChartBar, IconDatabase, IconBuildingBank,
  IconFileSpreadsheet, IconTransform, IconAlertTriangle, IconBook2,
} from '@tabler/icons-react';
import type { ReactNode } from 'react';

/**
 * 메뉴 코드 / 경로 → Tabler 아이콘 매핑.
 * 09_UI_DESIGN.md 의 "사이드 메뉴 좌측 아이콘 16px" 규칙.
 */
const ICON_MAP: Record<string, ReactNode> = {
  // 최상위 카테고리
  DASHBOARD:    <IconLayoutDashboard size={16} />,
  ORG:          <IconUsersGroup size={16} />,
  ORG_AGENT:    <IconUser size={16} />,
  CONTRACT:     <IconBriefcase size={16} />,
  RULE:         <IconReceipt size={16} />,
  RECEIVE:      <IconDatabase size={16} />,
  LEDGER:       <IconFileInvoice size={16} />,
  LEDGER_RECRUIT:   <IconFileInvoice size={16} />,
  LEDGER_MAINTAIN:  <IconFileInvoice size={16} />,
  LEDGER_EXCEPTION: <IconAlertTriangle size={16} />,
  SETTLE:       <IconCalculator size={16} />,
  SETTLE_LIST:  <IconCalculator size={16} />,
  SETTLE_BATCH: <IconTransform size={16} />,
  PAYMENT:      <IconCash size={16} />,
  REPORT:       <IconChartBar size={16} />,
  SYSTEM:       <IconSettings size={16} />,
  SYSTEM_USER:  <IconUsers size={16} />,
  SYSTEM_ROLE:  <IconShieldLock size={16} />,
  SYSTEM_MENU:  <IconCategory size={16} />,
  SYSTEM_CODE:  <IconKey size={16} />,
  SYSTEM_LOG:   <IconClipboardList size={16} />,
  SYSTEM_FILE:  <IconFolder size={16} />,
  SYSTEM_CONFIG: <IconSettings size={16} />,
  SYSTEM_UPLOAD_TEMPLATE: <IconFileSpreadsheet size={16} />,
  SYSTEM_DATA_DOMAIN: <IconDatabase size={16} />,
  SYSTEM_DATA_DICT:   <IconBook2 size={16} />,
  COMPANY:      <IconBuildingBank size={16} />,
  PRODUCT:      <IconFileSpreadsheet size={16} />,
  RECON:        <IconReportMoney size={16} />,
};

const PATH_MAP: Record<string, ReactNode> = {
  '/':                    <IconHome size={16} />,
  '/org/agents':          <IconUser size={16} />,
  '/contracts':           <IconBriefcase size={16} />,
  '/ledger/recruit':      <IconFileInvoice size={16} />,
  '/ledger/exception':    <IconAlertTriangle size={16} />,
  '/settle':              <IconCalculator size={16} />,
  '/settle/batch':        <IconTransform size={16} />,
  '/payments':            <IconCash size={16} />,
  '/system/users':        <IconUsers size={16} />,
  '/system/roles':        <IconShieldLock size={16} />,
  '/system/codes':        <IconKey size={16} />,
};

export function getMenuIcon(code?: string, path?: string): ReactNode {
  if (path && PATH_MAP[path]) return PATH_MAP[path];
  if (code && ICON_MAP[code]) return ICON_MAP[code];
  return <IconCategory size={16} />;
}
