import type { Lang, Dict } from '@pdfme/common';
import { DEFAULT_LANG } from './constants.js';

const dictEn: { [key in keyof Dict]: string } = {
  cancel: 'Cancel',
  field: 'field',
  fieldName: 'Name',
  align: 'Align',
  width: 'Width',
  height: 'Height',
  opacity: 'Opacity',
  rotate: 'Rotate',
  edit: 'Edit',
  plsInputName: 'Please input name',
  fieldMustUniq: 'Name of field is not unique',
  notUniq: '(Not unique name)',
  noKeyName: 'No name',
  fieldsList: 'Field List',
  addNewField: 'Add new field',
  editField: 'Edit Field',
  type: 'Type',
  errorOccurred: 'An error occurred',
  errorBulkUpdateFieldName:
    'Cannot commit the change because the number of items has been changed.',
  commitBulkUpdateFieldName: 'Commit Changes',
  bulkUpdateFieldName: 'Bulk update field names',
  hexColorPrompt: 'Please enter a valid hex color code.',
  'schemas.color': 'Color',
  'schemas.borderWidth': 'Border Width',
  'schemas.borderColor': 'Border Color',
  'schemas.textColor': 'Text Color',
  'schemas.bgColor': 'Background Color',
  'schemas.horizontal': 'Horizontal',
  'schemas.vertical': 'Vertical',
  'schemas.left': 'Left',
  'schemas.center': 'Center',
  'schemas.right': 'Right',
  'schemas.top': 'Top',
  'schemas.middle': 'Middle',
  'schemas.bottom': 'Bottom',
  'schemas.text.fontName': 'Font Name',
  'schemas.text.size': 'Size',
  'schemas.text.spacing': 'Spacing',
  'schemas.text.textAlign': 'Text Align',
  'schemas.text.verticalAlign': 'Vertical Align',
  'schemas.text.lineHeight': 'Line Height',
  'schemas.text.min': 'Min',
  'schemas.text.max': 'Max',
  'schemas.text.fit': 'Fit',
  'schemas.text.dynamicFontSize': 'Dynamic Font Size',
  'schemas.barcodes.barColor': 'Bar Color',
  'schemas.barcodes.includetext': 'Include Text',
};

const dictJa: { [key in keyof Dict]: string } = {
  cancel: 'キャンセル',
  field: '入力項目',
  fieldName: '項目名',
  align: '整列',
  width: '幅',
  height: '高さ',
  opacity: '不透明度',
  rotate: '回転',
  edit: '編集する',
  plsInputName: '項目名を入力してください',
  fieldMustUniq: '他の入力項目名と被っています',
  notUniq: '(他の項目名と重複しています)',
  noKeyName: '項目名なし',
  fieldsList: '入力項目一覧',
  addNewField: '入力項目を追加',
  editField: '入力項目を編集',
  type: 'タイプ',
  errorOccurred: 'エラーが発生しました',
  errorBulkUpdateFieldName: '項目数が変更されているため変更をコミットできません。',
  commitBulkUpdateFieldName: '変更を反映',
  bulkUpdateFieldName: '項目名を一括変更',
  hexColorPrompt: '有効な16進数のカラーコードを入力してください。',
  'schemas.color': '色',
  'schemas.borderWidth': '枠線の太さ',
  'schemas.borderColor': '枠線の色',
  'schemas.textColor': 'テキストの色',
  'schemas.bgColor': '背景色',
  'schemas.horizontal': '水平',
  'schemas.vertical': '垂直',
  'schemas.left': '左',
  'schemas.center': '中央',
  'schemas.right': '右',
  'schemas.top': '上',
  'schemas.middle': '中間',
  'schemas.bottom': '下',
  'schemas.text.fontName': 'フォント名',
  'schemas.text.size': 'サイズ',
  'schemas.text.spacing': '間隔',
  'schemas.text.textAlign': 'テキストの揃え',
  'schemas.text.verticalAlign': '垂直方向の揃え',
  'schemas.text.lineHeight': '行の高さ',
  'schemas.text.min': '最小',
  'schemas.text.max': '最大',
  'schemas.text.fit': 'フィット',
  'schemas.text.dynamicFontSize': '動的フォントサイズ',
  'schemas.barcodes.barColor': 'バーの色',
  'schemas.barcodes.includetext': 'テキストを含める',
};

const dictAr: { [key in keyof Dict]: string } = {
  cancel: 'إلغاء',
  field: 'الحقل',
  fieldName: 'اسم الحقل',
  align: 'محاذاة',
  width: 'العرض',
  height: 'الارتفاع',
  opacity: 'الشفافية',
  rotate: 'تدوير',
  edit: 'تعديل',
  plsInputName: 'الرجاء إدخال الاسم',
  fieldMustUniq: 'يجب أن يكون الحقل فريداً',
  notUniq: '(غير فريد)',
  noKeyName: 'لا يوجد اسم للحقل',
  fieldsList: 'قائمة الحقول',
  addNewField: 'إضافة حقل جديد',
  editField: 'تعديل الحقل',
  type: 'النوع',
  errorOccurred: 'حدث خطأ',
  errorBulkUpdateFieldName: 'لا يمكن تنفيذ التغيير لأنه تم تغيير عدد العناصر.',
  commitBulkUpdateFieldName: 'تنفيذ التغييرات',
  bulkUpdateFieldName: 'تغيير الأسماء',
  hexColorPrompt: 'الرجاء إدخال رمز لون سداسي عشري صالح.',
  'schemas.color': 'اللون',
  'schemas.borderWidth': 'عرض الحدود',
  'schemas.borderColor': 'لون الحدود',
  'schemas.textColor': 'لون الخط',
  'schemas.bgColor': 'لون الخلفية',
  'schemas.horizontal': 'أفقي',
  'schemas.vertical': 'عمودي',
  'schemas.left': 'يسار',
  'schemas.center': 'مركز',
  'schemas.right': 'يمين',
  'schemas.top': 'أعلى',
  'schemas.middle': 'وسط',
  'schemas.bottom': 'أسفل',
  'schemas.text.fontName': 'اسم الخط',
  'schemas.text.size': 'الحجم',
  'schemas.text.spacing': 'التباعد',
  'schemas.text.textAlign': 'محاذاة النص',
  'schemas.text.verticalAlign': 'محاذاة عمودية',
  'schemas.text.lineHeight': 'ارتفاع السطر',
  'schemas.text.min': 'الحد الأدنى',
  'schemas.text.max': 'الحد الأقصى',
  'schemas.text.fit': 'ملاءمة',
  'schemas.text.dynamicFontSize': 'حجم الخط الديناميكي',
  'schemas.barcodes.barColor': 'لون الشريط',
  'schemas.barcodes.includetext': 'تضمين النص',
};

const dictTh: { [key in keyof Dict]: string } = {
  cancel: 'ยกเลิก',
  field: 'ฟิลด์',
  fieldName: 'ชื่อฟิลด์',
  align: 'จัดเรียง',
  width: 'ความกว้าง',
  height: 'ความสูง',
  opacity: 'ความทึบ',
  rotate: 'หมุน',
  edit: 'แก้ไข',
  plsInputName: 'กรุณาใส่ชื่อ',
  fieldMustUniq: 'ชื่อฟิลด์ต้องไม่ซ้ำกัน',
  notUniq: '(ชื่อฟิลด์ซ้ำกัน)',
  noKeyName: 'ไม่มีชื่อ',
  fieldsList: 'รายการฟิลด์ทั้งหมด',
  addNewField: 'เพิ่มฟิลด์ใหม่',
  editField: 'แก้ไขฟิลด์',
  type: 'ประเภท',
  errorOccurred: 'เกิดข้อผิดพลาด',
  errorBulkUpdateFieldName: 'ไม่สามารถยืนยันการแก้ไขได้เนื่องจากจำนวนรายการมีการเปลี่ยนแปลง',
  commitBulkUpdateFieldName: 'ยืนยันการแก้ไข',
  bulkUpdateFieldName: 'แก้ไขชื่อฟิลด์เป็นชุด',
  hexColorPrompt: 'กรุณาใส่รหัสสีแบบฐานสิบหกที่ถูกต้อง',
  'schemas.color': 'สี',
  'schemas.borderWidth': 'ความกว้างของเส้นขอบ',
  'schemas.borderColor': 'สีขอบ',
  'schemas.textColor': 'สีข้อความ',
  'schemas.bgColor': 'สีพื้นหลัง',
  'schemas.horizontal': 'แนวนอน',
  'schemas.vertical': 'แนวตั้ง',
  'schemas.left': 'ซ้าย',
  'schemas.center': 'ตรงกลาง',
  'schemas.right': 'ขวา',
  'schemas.top': 'ด้านบน',
  'schemas.middle': 'ตรงกลาง',
  'schemas.bottom': 'ด้านล่าง',
  'schemas.text.fontName': 'ชื่อแบบอักษร',
  'schemas.text.size': 'ขนาด',
  'schemas.text.spacing': 'ระยะห่าง',
  'schemas.text.textAlign': 'จัดแนวข้อความ',
  'schemas.text.verticalAlign': 'จัดแนวแนวตั้ง',
  'schemas.text.lineHeight': 'ความสูงของบรรทัด',
  'schemas.text.min': 'ต่ำสุด',
  'schemas.text.max': 'สูงสุด',
  'schemas.text.fit': 'พอดี',
  'schemas.text.dynamicFontSize': 'ขนาดตัวอักษรแบบไดนามิก',
  'schemas.barcodes.barColor': 'สีบาร์',
  'schemas.barcodes.includetext': 'รวมข้อความ',
};

const dictIt: { [key in keyof Dict]: string } = {
  cancel: 'Annulla',
  field: 'Campo',
  fieldName: 'Nome',
  align: 'Allinea',
  width: 'Larghezza',
  height: 'Altezza',
  opacity: 'Opacità',
  rotate: 'Ruota',
  edit: 'Modifica',
  plsInputName: 'Inserisci il nome per favore',
  fieldMustUniq: 'Il nome del campo non è univoco',
  notUniq: '(Nome non univoco)',
  noKeyName: 'Nessun nome',
  fieldsList: 'Lista campi',
  addNewField: 'Aggiungi un campo',
  editField: 'Modifica campo',
  type: 'Tipo',
  errorOccurred: 'Riscontrato errore',
  errorBulkUpdateFieldName:
    'Non è possibile salvare le modifiche perché il numero di elementi è cambiato.',
  commitBulkUpdateFieldName: 'Salva cambiamenti',
  bulkUpdateFieldName: 'Modifica nomi campi in blocco',
  hexColorPrompt: 'Inserisci un codice colore esadecimale valido.',
  'schemas.color': 'Colore',
  'schemas.borderWidth': 'Spessore bordo',
  'schemas.borderColor': 'Colore bordo',
  'schemas.textColor': 'Colore testo',
  'schemas.bgColor': 'Colore sfondo',
  'schemas.horizontal': 'Orizzontale',
  'schemas.vertical': 'Verticale',
  'schemas.left': 'Sinistra',
  'schemas.center': 'Centro',
  'schemas.right': 'Destra',
  'schemas.top': 'Sopra',
  'schemas.middle': 'Medio',
  'schemas.bottom': 'Sotto',
  'schemas.text.fontName': 'Nome del font',
  'schemas.text.size': 'Dimensione',
  'schemas.text.spacing': 'Spaziatura',
  'schemas.text.textAlign': 'Allineamento testo',
  'schemas.text.verticalAlign': 'Allineamento verticale',
  'schemas.text.lineHeight': 'Altezza della linea',
  'schemas.text.min': 'Minimo',
  'schemas.text.max': 'Massimo',
  'schemas.text.fit': 'Adatta',
  'schemas.text.dynamicFontSize': 'Dimensione font dinamica',
  'schemas.barcodes.barColor': 'Colore barra',
  'schemas.barcodes.includetext': 'Includi testo',
};

const dictPl: { [key in keyof Dict]: string } = {
  cancel: 'Anuluj',
  field: 'pole',
  fieldName: 'Klucz pola',
  align: 'Wyrównanie',
  width: 'Szerokość',
  height: 'Wysokość',
  opacity: 'przezroczystość',
  rotate: 'Obrót',
  edit: 'Edytuj',
  plsInputName: 'Wymagane wprowadzenie klucza pola',
  fieldMustUniq: 'Klucz pola nie jest unikalny',
  notUniq: '(Klucz pola nie jest unikalny)',
  noKeyName: 'Brak nazwy klucza pola',
  fieldsList: 'Lista pól',
  addNewField: 'Dodaj nowe pole',
  editField: 'Edytuj pole',
  type: 'Typ pola',
  errorOccurred: 'Wystąpił błąd',
  errorBulkUpdateFieldName: 'Nie można wprowadzić zmian ponieważ liczba elementów uległa zmianie.',
  commitBulkUpdateFieldName: 'Zaakceptuj zmiany',
  bulkUpdateFieldName: 'Masowo aktualizuj klucze pól',
  hexColorPrompt: 'Wprowadź poprawny kod koloru szesnastkowego.',
  'schemas.color': 'Kolor',
  'schemas.borderWidth': 'Szerokość obramowania',
  'schemas.borderColor': 'Kolor obramowania',
  'schemas.textColor': 'Kolor tekstu',
  'schemas.bgColor': 'Kolor tła',
  'schemas.horizontal': 'Poziomo',
  'schemas.vertical': 'Pionowo',
  'schemas.left': 'Lewo',
  'schemas.center': 'Centrum',
  'schemas.right': 'Prawo',
  'schemas.top': 'Góra',
  'schemas.middle': 'Środek',
  'schemas.bottom': 'Dół',
  'schemas.text.fontName': 'Nazwa czcionki',
  'schemas.text.size': 'Rozmiar',
  'schemas.text.spacing': 'Odstępy',
  'schemas.text.textAlign': 'Wyrównanie tekstu',
  'schemas.text.verticalAlign': 'Wyrównanie pionowe',
  'schemas.text.lineHeight': 'Wysokość linii',
  'schemas.text.min': 'Minimum',
  'schemas.text.max': 'Maksimum',
  'schemas.text.fit': 'Dopasowanie',
  'schemas.text.dynamicFontSize': 'Dynamiczny rozmiar czcionki',
  'schemas.barcodes.barColor': 'Kolor paska',
  'schemas.barcodes.includetext': 'Dołącz tekst',
};

const dictDe: { [key in keyof Dict]: string } = {
  cancel: 'Abbrechen',
  field: 'Feld',
  fieldName: 'Name',
  align: 'Ausrichten',
  width: 'Breite',
  height: 'Höhe',
  opacity: 'Opazität',
  rotate: 'Drehen',
  edit: 'Bearbeiten',
  plsInputName: 'Bitte geben Sie einen Namen ein',
  fieldMustUniq: 'Feldname ist nicht eindeutig',
  notUniq: '(Nicht eindeutiger Name)',
  noKeyName: 'Kein Name',
  fieldsList: 'Feldliste',
  addNewField: 'Neues Feld hinzufügen',
  editField: 'Feld bearbeiten',
  type: 'Typ',
  errorOccurred: 'Ein Fehler ist aufgetreten',
  errorBulkUpdateFieldName:
    'Die Änderung kann nicht übernommen werden, weil die Anzahl der Elemente geändert wurde.',
  commitBulkUpdateFieldName: 'Änderungen übernehmen',
  bulkUpdateFieldName: 'Mehrfachaktualisierung der Feldnamen',
  hexColorPrompt: 'Bitte geben Sie einen gültigen Hex-Farbcode ein.',
  'schemas.color': 'Farbe',
  'schemas.borderWidth': 'Rahmenbreite',
  'schemas.borderColor': 'Rahmenfarbe',
  'schemas.textColor': 'Textfarbe',
  'schemas.bgColor': 'Hintergrundfarbe',
  'schemas.horizontal': 'Horizontal',
  'schemas.vertical': 'Vertikal',
  'schemas.left': 'Links',
  'schemas.center': 'Zentriert',
  'schemas.right': 'Rechts',
  'schemas.top': 'Oben',
  'schemas.middle': 'Mitte',
  'schemas.bottom': 'Unten',
  'schemas.text.fontName': 'Schriftart',
  'schemas.text.size': 'Größe',
  'schemas.text.spacing': 'Abstand',
  'schemas.text.textAlign': 'Ausrichtung',
  'schemas.text.verticalAlign': 'vert. Ausr.',
  'schemas.text.lineHeight': 'Zeilenhöhe',
  'schemas.text.min': 'Min',
  'schemas.text.max': 'Max',
  'schemas.text.fit': 'Anpassen',
  'schemas.text.dynamicFontSize': 'Dynamische Schriftgröße',
  'schemas.barcodes.barColor': 'Strichcodefarbe',
  'schemas.barcodes.includetext': 'Text anzeigen',
};

const dictionaries: { [key in Lang]: Dict } = {
  en: dictEn,
  ja: dictJa,
  ar: dictAr,
  th: dictTh,
  it: dictIt,
  pl: dictPl,
  de: dictDe,
};

export const getDict = (lang: Lang): Dict => dictionaries[lang] || dictionaries[DEFAULT_LANG];

export const i18n = (key: keyof Dict, dict?: Dict) => (dict || getDict(DEFAULT_LANG))[key];
