import { UserInterface } from "@sankhyalabs/core";
import { buildCheckBox, buildSwitch } from "./templates/CheckBox.tpl";
import { buildComboBox } from "./templates/ComboBox.tpl";
import { buildDate, buildTime, buildDateTime, buildTimeSeconds } from "./templates/DateInput.tpl";
import { buildFile } from "./templates/FileInput.tpl";
import { buildDecimal, buildInteger } from "./templates/NumberInput.tpl";
import { buildTextArea } from "./templates/TextArea.tpl";
import { buildTextInput } from "./templates/TextInput.tpl";
import { buildSearchPlus } from "./templates/SearchInputPlus.tpl";
import { buildSearch } from "./templates/SearchInput.tpl";
import { buildRichText } from "./templates/RichText.tpl";
import { getI18n } from "../../../utils/i18n";
const uiBuilders = new Map();
uiBuilders.set(UserInterface.CHECKBOX, buildCheckBox);
uiBuilders.set(UserInterface.SWITCH, buildSwitch);
uiBuilders.set(UserInterface.OPTIONSELECTOR, buildComboBox);
uiBuilders.set(UserInterface.DATE, buildDate);
uiBuilders.set(UserInterface.TIME, buildTime);
uiBuilders.set(UserInterface.ELAPSEDTIME, buildTimeSeconds);
uiBuilders.set(UserInterface.DATETIME, buildDateTime);
uiBuilders.set(UserInterface.FILE, buildFile);
uiBuilders.set(UserInterface.DECIMALNUMBER, buildDecimal);
uiBuilders.set(UserInterface.INTEGERNUMBER, buildInteger);
uiBuilders.set(UserInterface.SEARCH, buildSearch);
uiBuilders.set(UserInterface.SEARCHPLUS, buildSearchPlus);
uiBuilders.set(UserInterface.LONGTEXT, buildTextArea);
uiBuilders.set(UserInterface.HTML, buildRichText);
export const fieldBuilder = (field) => {
  const i18n = getI18n();
  const builder = uiBuilders.get(field.userInterface) || buildTextInput;
  const label = field.required ? `${field.label}${i18n("app.requiredInfo")}` : field.label;
  const builtElement = builder(Object.assign(Object.assign({}, field), { label }));
  //@ts-ignore
  builtElement.$attrs$['data-form-item'] = field.name;
  return builtElement;
};
