// https://github.com/ai/convert-layout/blob/main/convert.js
function convert(keys: string, values: string) {
    const reverse = {};
    const full = {};

    for (let keyIndex = keys.length; keyIndex--; ) {
        full[keys[keyIndex].toUpperCase()] = values[keyIndex].toUpperCase();
        full[keys[keyIndex]] = values[keyIndex];
    }

    for (const key in full) {
        reverse[full[key]] = key;
    }

    return {
        fromEn: function (str) {
            return str.replace(/./g, function (ch) {
                return full[ch] || ch;
            });
        },
        toEn: function (str) {
            return str.replace(/./g, function (ch) {
                return reverse[ch] || ch;
            });
        },
    };
}

// copied from build of convert-layout
export const ruKeyboardLayout = convert(
    '.exportsfunc"#$&\',/:;<>?@[]^`abdghijklmqvwyz{|}~',
    'юучзщкеыагтсЭ№;?эб.ЖжБЮ,"хъ:ёфивпршолдьймцняХ/ЪЁ',
);
