import { createI18n } from 'vue-i18n';
import { adminMessages, type AdminLocale } from './admin-messages';

export const ADMIN_LOCALE_STORAGE_KEY = 'admin_locale';

const saved = (localStorage.getItem(ADMIN_LOCALE_STORAGE_KEY) as AdminLocale) || 'zh-CN';

export const i18n = createI18n({
  legacy: false,
  locale: saved,
  fallbackLocale: ['en-US', 'zh-CN'],
  messages: adminMessages,
});

export function getAdminLocale(): AdminLocale {
  return i18n.global.locale.value as AdminLocale;
}

export default i18n;
