export const ValidationConstraints = {
  codeMinLength: 2,
  codeMaxLength: 64,
  nameMaxLength: 128,
  keyMaxLength: 128,
  descriptionMaxLength: 512
}

export function extractI18nText(
  value: Record<string, string> | undefined,
  locale?: string
): string {
  if (!value) return ''

  const normalizedLocale = locale?.trim()
  if (normalizedLocale && value[normalizedLocale]) {
    return value[normalizedLocale]
  }

  if (value['zh-CN']) return value['zh-CN']
  if (value.en) return value.en

  const first = Object.values(value)[0]
  return first ?? ''
}
