export interface KeyStroke {
  modifier: number;
  keys: number[];
}

export interface KeyInfo {
  key: string | number;
  shift?: boolean;
  altRight?: boolean;
}

export interface KeyCombo extends KeyInfo {
  deadKey?: boolean;
  accentKey?: KeyInfo;
}

export interface KeyboardLayout {
  isoCode: string;
  name: string;
  chars: Record<string, KeyCombo>;
  modifierDisplayMap: Record<string, string>;
  keyDisplayMap: Record<string, string>;
  virtualKeyboard: {
    main: { default: string[]; shift: string[] };
    control?: { default: string[]; shift?: string[] };
    arrows?: { default: string[] };
    numpad?: {
      numlocked: string[];
      default: string[];
    };
  };
}

// Import all layouts
import { cs_CZ } from "./keyboardLayouts/cs_CZ";
import { da_DK } from "./keyboardLayouts/da_DK";
import { de_CH } from "./keyboardLayouts/de_CH";
import { de_DE } from "./keyboardLayouts/de_DE";
import { en_US } from "./keyboardLayouts/en_US";
import { en_UK } from "./keyboardLayouts/en_UK";
import { es_ES } from "./keyboardLayouts/es_ES";
import { fr_BE } from "./keyboardLayouts/fr_BE";
import { fr_CH } from "./keyboardLayouts/fr_CH";
import { fr_FR } from "./keyboardLayouts/fr_FR";
import { hu_HU } from "./keyboardLayouts/hu_HU";
import { it_IT } from "./keyboardLayouts/it_IT";
import { ja_JP } from "./keyboardLayouts/ja_JP";
import { nb_NO } from "./keyboardLayouts/nb_NO";
import { pl_PL } from "./keyboardLayouts/pl_PL";
import { pt_PT } from "./keyboardLayouts/pt_PT";
import { sv_SE } from "./keyboardLayouts/sv_SE";
import { sl_SI } from "./keyboardLayouts/sl_SI";
import { ru_RU } from "./keyboardLayouts/ru_RU";

export const keyboards: KeyboardLayout[] = [
  cs_CZ,
  da_DK,
  de_CH,
  de_DE,
  en_UK,
  en_US,
  es_ES,
  fr_BE,
  fr_CH,
  fr_FR,
  hu_HU,
  it_IT,
  ja_JP,
  nb_NO,
  pl_PL,
  pt_PT,
  sv_SE,
  sl_SI,
  ru_RU,
];

// Backward-compatible maps
export const layouts: Record<string, string> = {};
export const chars: Record<string, Record<string, KeyCombo>> = {};

keyboards.forEach(kb => {
  const oldCode = kb.isoCode.replace("-", "_");
  layouts[oldCode] = kb.name;
  chars[oldCode] = kb.chars;
});
