import KeywriteWeb from "@keywrite/web";
import EthiopicInputMethods from "@keywrite/ethiopic-input-methods";
const populateSelect = (selectId) => {
const select = document.getElementById(selectId);
if (select) {
const IMKeys = Object.keys(EthiopicInputMethods);
IMKeys.forEach(key => {
const option = document.createElement("option");
option.value = key;
option.textContent = key;
select.appendChild(option);
});
}
};
const addToggle = (instance, btnId) => {
const btn = document.getElementById(btnId);
if (btn) {
btn.addEventListener("click", () => {
instance.on = !instance.on;
btn.textContent = instance.on ? "ON" : "OFF";
});
}
};
const addLayoutSelect = (instance, selectId) => {
const select = document.getElementById(selectId);
if (select) {
select.addEventListener("change", (e) => {
const value = e.target.value;
instance.current = value;
});
}
};
const inputElem = document.getElementById("inputName");
const textareaElem = document.getElementById("inputBio");
if (inputElem && textareaElem) {
populateSelect("selectName");
populateSelect("selectBio");
const inputInstance = new KeywriteWeb(inputElem, EthiopicInputMethods);
const textareaInstance = new KeywriteWeb(textareaElem, EthiopicInputMethods);
addToggle(inputInstance, "btnName");
addToggle(textareaInstance, "btnBio");
addLayoutSelect(inputInstance, "selectName");
addLayoutSelect(textareaInstance, "selectBio");
}