import { t } from '#cli/i18n'

export function getToolSettingsDialogStrings() {
  return {
    title: t('toolSettingsDialog.title'),
    hint: t('toolSettingsDialog.hint'),
    inputClearTip: t('common.inputClearTip'),
    apply: t('common.apply'),
    cancel: t('common.cancel'),
    websearchTitle: t('toolSettingsDialog.websearchTitle'),
    apiKeyCurrentPrefix: t('toolSettingsDialog.apiKeyCurrentPrefix'),
    apiKeyNotSet: t('toolSettingsDialog.apiKeyNotSet'),
    apiKeyPlaceholder: t('toolSettingsDialog.apiKeyPlaceholder'),
  } as const
}

export type ToolSettingsDialogLayout = Readonly<{
  dialogW: number
  dialogH: number
  innerW: number
  innerH: number
  contentH: number
  showHint: boolean
  fieldBoxH: number
  inputH: number
  canShowCurrentLine: boolean
  apiKeyHintY: number
  apiKeyY: number
}>

export function computeToolSettingsDialogLayout(
  input: Readonly<{ w: number; h: number; apiKeyMasked: string }>,
): ToolSettingsDialogLayout {
  const dialogW = Math.max(48, input.w)
  const dialogH = Math.max(14, input.h)
  const innerW = dialogW - 4
  const innerH = dialogH - 2
  const showHint = dialogH >= 16
  const contentH = innerH - (showHint ? 2 : 0)
  const fieldBoxH = Math.max(3, Math.min(6, contentH - 2))
  const inputH = Math.max(1, fieldBoxH - 2)
  const canShowCurrentLine = fieldBoxH >= 3
  const apiKeyHintY = 1
  const apiKeyY = canShowCurrentLine ? 2 : 1

  return {
    dialogW,
    dialogH,
    innerW,
    innerH,
    contentH,
    showHint,
    fieldBoxH,
    inputH,
    canShowCurrentLine,
    apiKeyHintY,
    apiKeyY,
  }
}
