import ELT from '../../Components/ELT';
import finGAP from '../../Components/FinGAP';
import { CustomComponents, NonValueElementsNames } from '../../types/elements';
import { TableNames } from '../../types/tables';
import components from '../components';
import tables from '../tables';
import buildAction from './buildAction';
import buildComputed from './buildComputed';
import buildLink from './buildLink';
import buildTable from './buildTable';
import buildValue from './buildValue';

const valueElementsBuilders = Object.keys(components).reduce(
  (acc, elementName) => {
    acc[elementName] = buildValue;
    return acc;
  },
  {},
);

const overrideBuilders: Record<
  NonValueElementsNames | TableNames | CustomComponents,
  any
> = {
  labelLeaseObjectRisk: buildComputed,
  tbxInsKaskoPriceLeasePeriod: buildComputed,
  labelIrrInfo: buildComputed,
  labelRegistrationDescription: buildComputed,
  btnCreateKP: buildAction,
  btnCalculate: buildAction,
  linkDownloadKp: buildLink,
  labelImportProgramSum: buildComputed,
  componentElt: () => ELT,
  componentfinGAP: () => finGAP,
  tablePayments: ({ name, Component }) =>
    buildTable({ name, Component, ...tables[name] }),
  tableInsurance: ({ name, Component }) =>
    buildTable({ name, Component, ...tables[name] }),
  tableResults: ({ name, Component }) =>
    buildTable({ name, Component, ...tables[name] }),
};

export default Object.assign(valueElementsBuilders, overrideBuilders);
