import { adminMessages, type AdminLocale } from './admin-messages';
import { getAdminLocale } from './index';

/** 扁平 key 翻译（避免 vue-i18n 把 audit.action.X 当成嵌套路径） */
export function resolveAdminMessage(key: string, locale?: AdminLocale): string | undefined {
  const chain: AdminLocale[] = [];
  const primary = locale ?? getAdminLocale();
  for (const loc of [primary, 'en-US', 'zh-CN'] as AdminLocale[]) {
    if (!chain.includes(loc)) chain.push(loc);
  }
  for (const loc of chain) {
    const v = adminMessages[loc]?.[key];
    if (v) return v;
  }
  return undefined;
}
