import { t } from '#cli/i18n'

export function getLanguageDialogStrings() {
  return {
    title: t('languageDialog.title'),
    hint: t('languageDialog.hint'),
    apply: t('common.apply'),
    cancel: t('common.cancel'),
    languageTitle: t('languageDialog.languageTitle'),
    languageEnglish: t('languageDialog.languageEnglish'),
    languageChinese: t('languageDialog.languageChinese'),
  } as const
}

export type LanguageDialogLayout = Readonly<{
  dialogW: number
  dialogH: number
  innerW: number
  innerH: number
  contentH: number
  showHint: boolean
  fieldBoxH: number
  inputH: number
  languageY: number
}>

export function computeLanguageDialogLayout(
  input: Readonly<{ w: number; h: number }>,
): LanguageDialogLayout {
  const dialogW = Math.max(34, Math.floor(input.w))
  const dialogH = Math.max(10, Math.floor(input.h))
  const innerW = Math.max(0, dialogW - 4)
  const innerH = Math.max(0, dialogH - 4)
  const contentH = Math.max(0, innerH - 1)

  const maxFieldBoxH = 4
  const minFieldBoxH = 3
  const fieldCount = 1
  const fieldBoxH =
    contentH >= maxFieldBoxH * fieldCount + 1 ? maxFieldBoxH : minFieldBoxH
  const inputH = Math.max(1, fieldBoxH - 2)

  const showHint = contentH >= fieldBoxH * fieldCount + 1

  const languageY = showHint ? 1 : 0

  return {
    dialogW,
    dialogH,
    innerW,
    innerH,
    contentH,
    showHint,
    fieldBoxH,
    inputH,
    languageY,
  }
}
