import {DpValue, I18N, TYSdk} from 'tuya-panel-kit'
import Strings from './strings'

type Key = keyof typeof Strings.en
// @ts-ignore
const I18NInstance = new I18N(Strings)

function getLang(key: Key, defaultString?: string): string {
  return I18NInstance.getLang(key, defaultString)
}

function getDpLang(code: string, value?: DpValue): string {
  return I18NInstance.getDpLang(code, value)
}

function formatString(key: string, values: string[]): string {
  return I18NInstance.formatString(key, ...values)
}

function formatValue(key: Key, ...values: string[]): string {
  return I18NInstance.formatValue(key, ...values)
}

function getDpName(code: string, defaultName?: string): string {
  return I18NInstance.getDpName(code, defaultName)
}

const I18n = {
  getLang,
  getDpLang,
  formatString,
  formatValue,
  getDpName,
}

const lang = TYSdk.mobile.mobileInfo.lang

export default I18n
export { Key as I18nKey, lang }
