import { GoogleTranslateIcon } from '@/components/icons'
import { AuthMode, type BlockConfig, IntegrationType } from '@/blocks/types'

const SUPPORTED_LANGUAGES = [
  { label: 'Afrikaans', id: 'af' },
  { label: 'Albanian', id: 'sq' },
  { label: 'Amharic', id: 'am' },
  { label: 'Arabic', id: 'ar' },
  { label: 'Armenian', id: 'hy' },
  { label: 'Assamese', id: 'as' },
  { label: 'Aymara', id: 'ay' },
  { label: 'Azerbaijani', id: 'az' },
  { label: 'Bambara', id: 'bm' },
  { label: 'Basque', id: 'eu' },
  { label: 'Belarusian', id: 'be' },
  { label: 'Bengali', id: 'bn' },
  { label: 'Bhojpuri', id: 'bho' },
  { label: 'Bosnian', id: 'bs' },
  { label: 'Bulgarian', id: 'bg' },
  { label: 'Catalan', id: 'ca' },
  { label: 'Cebuano', id: 'ceb' },
  { label: 'Chinese (Simplified)', id: 'zh-CN' },
  { label: 'Chinese (Traditional)', id: 'zh-TW' },
  { label: 'Corsican', id: 'co' },
  { label: 'Croatian', id: 'hr' },
  { label: 'Czech', id: 'cs' },
  { label: 'Danish', id: 'da' },
  { label: 'Dhivehi', id: 'dv' },
  { label: 'Dogri', id: 'doi' },
  { label: 'Dutch', id: 'nl' },
  { label: 'English', id: 'en' },
  { label: 'Esperanto', id: 'eo' },
  { label: 'Estonian', id: 'et' },
  { label: 'Ewe', id: 'ee' },
  { label: 'Filipino', id: 'tl' },
  { label: 'Finnish', id: 'fi' },
  { label: 'French', id: 'fr' },
  { label: 'Frisian', id: 'fy' },
  { label: 'Galician', id: 'gl' },
  { label: 'Georgian', id: 'ka' },
  { label: 'German', id: 'de' },
  { label: 'Greek', id: 'el' },
  { label: 'Guarani', id: 'gn' },
  { label: 'Gujarati', id: 'gu' },
  { label: 'Haitian Creole', id: 'ht' },
  { label: 'Hausa', id: 'ha' },
  { label: 'Hawaiian', id: 'haw' },
  { label: 'Hebrew', id: 'he' },
  { label: 'Hindi', id: 'hi' },
  { label: 'Hmong', id: 'hmn' },
  { label: 'Hungarian', id: 'hu' },
  { label: 'Icelandic', id: 'is' },
  { label: 'Igbo', id: 'ig' },
  { label: 'Ilocano', id: 'ilo' },
  { label: 'Indonesian', id: 'id' },
  { label: 'Irish', id: 'ga' },
  { label: 'Italian', id: 'it' },
  { label: 'Japanese', id: 'ja' },
  { label: 'Javanese', id: 'jv' },
  { label: 'Kannada', id: 'kn' },
  { label: 'Kazakh', id: 'kk' },
  { label: 'Khmer', id: 'km' },
  { label: 'Kinyarwanda', id: 'rw' },
  { label: 'Konkani', id: 'gom' },
  { label: 'Korean', id: 'ko' },
  { label: 'Krio', id: 'kri' },
  { label: 'Kurdish', id: 'ku' },
  { label: 'Kurdish (Sorani)', id: 'ckb' },
  { label: 'Kyrgyz', id: 'ky' },
  { label: 'Lao', id: 'lo' },
  { label: 'Latin', id: 'la' },
  { label: 'Latvian', id: 'lv' },
  { label: 'Lingala', id: 'ln' },
  { label: 'Lithuanian', id: 'lt' },
  { label: 'Luganda', id: 'lg' },
  { label: 'Luxembourgish', id: 'lb' },
  { label: 'Macedonian', id: 'mk' },
  { label: 'Maithili', id: 'mai' },
  { label: 'Malagasy', id: 'mg' },
  { label: 'Malay', id: 'ms' },
  { label: 'Malayalam', id: 'ml' },
  { label: 'Maltese', id: 'mt' },
  { label: 'Maori', id: 'mi' },
  { label: 'Marathi', id: 'mr' },
  { label: 'Meiteilon (Manipuri)', id: 'mni-Mtei' },
  { label: 'Mizo', id: 'lus' },
  { label: 'Mongolian', id: 'mn' },
  { label: 'Myanmar (Burmese)', id: 'my' },
  { label: 'Nepali', id: 'ne' },
  { label: 'Norwegian', id: 'no' },
  { label: 'Nyanja (Chichewa)', id: 'ny' },
  { label: 'Odia (Oriya)', id: 'or' },
  { label: 'Oromo', id: 'om' },
  { label: 'Pashto', id: 'ps' },
  { label: 'Persian', id: 'fa' },
  { label: 'Polish', id: 'pl' },
  { label: 'Portuguese', id: 'pt' },
  { label: 'Punjabi', id: 'pa' },
  { label: 'Quechua', id: 'qu' },
  { label: 'Romanian', id: 'ro' },
  { label: 'Russian', id: 'ru' },
  { label: 'Samoan', id: 'sm' },
  { label: 'Sanskrit', id: 'sa' },
  { label: 'Scots Gaelic', id: 'gd' },
  { label: 'Sepedi', id: 'nso' },
  { label: 'Serbian', id: 'sr' },
  { label: 'Sesotho', id: 'st' },
  { label: 'Shona', id: 'sn' },
  { label: 'Sindhi', id: 'sd' },
  { label: 'Sinhala', id: 'si' },
  { label: 'Slovak', id: 'sk' },
  { label: 'Slovenian', id: 'sl' },
  { label: 'Somali', id: 'so' },
  { label: 'Spanish', id: 'es' },
  { label: 'Sundanese', id: 'su' },
  { label: 'Swahili', id: 'sw' },
  { label: 'Swedish', id: 'sv' },
  { label: 'Tajik', id: 'tg' },
  { label: 'Tamil', id: 'ta' },
  { label: 'Tatar', id: 'tt' },
  { label: 'Telugu', id: 'te' },
  { label: 'Thai', id: 'th' },
  { label: 'Tigrinya', id: 'ti' },
  { label: 'Tsonga', id: 'ts' },
  { label: 'Turkish', id: 'tr' },
  { label: 'Turkmen', id: 'tk' },
  { label: 'Twi (Akan)', id: 'ak' },
  { label: 'Ukrainian', id: 'uk' },
  { label: 'Urdu', id: 'ur' },
  { label: 'Uyghur', id: 'ug' },
  { label: 'Uzbek', id: 'uz' },
  { label: 'Vietnamese', id: 'vi' },
  { label: 'Welsh', id: 'cy' },
  { label: 'Xhosa', id: 'xh' },
  { label: 'Yiddish', id: 'yi' },
  { label: 'Yoruba', id: 'yo' },
  { label: 'Zulu', id: 'zu' },
] satisfies { label: string; id: string }[]

export const GoogleTranslateBlock: BlockConfig = {
  type: 'google_translate',
  name: 'Google Translate',
  description: 'Translate text using Google Cloud Translation',
  longDescription:
    'Translate and detect languages using the Google Cloud Translation API. Supports auto-detection of the source language.',
  docsLink: 'https://docs.sim.ai/tools/google_translate',
  category: 'tools',
  integrationType: IntegrationType.AI,
  tags: ['google-workspace', 'content-management', 'automation'],
  bgColor: '#E0E0E0',
  icon: GoogleTranslateIcon,
  authMode: AuthMode.ApiKey,
  subBlocks: [
    {
      id: 'operation',
      title: 'Operation',
      type: 'dropdown',
      options: [
        { label: 'Translate Text', id: 'text' },
        { label: 'Detect Language', id: 'detect' },
      ],
      value: () => 'text',
    },
    {
      id: 'text',
      title: 'Text',
      type: 'long-input',
      placeholder: 'Enter text...',
      required: true,
    },
    {
      id: 'target',
      title: 'Target Language',
      type: 'dropdown',
      condition: { field: 'operation', value: 'text' },
      searchable: true,
      options: SUPPORTED_LANGUAGES,
      value: () => 'es',
      required: { field: 'operation', value: 'text' },
    },
    {
      id: 'source',
      title: 'Source Language',
      type: 'dropdown',
      condition: { field: 'operation', value: 'text' },
      searchable: true,
      options: [{ label: 'Auto-detect', id: '' }, ...SUPPORTED_LANGUAGES],
      value: () => '',
    },
    {
      id: 'apiKey',
      title: 'API Key',
      type: 'short-input',
      placeholder: 'Enter your Google Cloud API key',
      password: true,
      required: true,
      hideWhenHosted: true,
    },
  ],
  tools: {
    access: ['google_translate_text', 'google_translate_detect'],
    config: {
      tool: (params) => `google_translate_${params.operation}`,
    },
  },
  inputs: {
    text: { type: 'string', description: 'Text to translate or detect language of' },
    target: { type: 'string', description: 'Target language code' },
    source: { type: 'string', description: 'Source language code (optional, auto-detected)' },
    apiKey: { type: 'string', description: 'Google Cloud API key' },
  },
  outputs: {
    translatedText: { type: 'string', description: 'Translated text' },
    detectedSourceLanguage: { type: 'string', description: 'Detected source language code' },
    language: { type: 'string', description: 'Detected language code' },
    confidence: { type: 'number', description: 'Detection confidence score' },
  },
}
