import { ElementsNames } from 'client/Containers/Calculation/types/elements';
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
import { ElementStatus } from 'types/elements';

const elementsNames: ElementsNames[] = [
  'selectModel',
  'selectConfiguration',
  'selectGPSModel',
  // 'selectTownRegistration',
  'selectDealerPerson',
];

export default elementsNames.map(elementName => calculationStore => ({
  expression: () => {
    const elementOptions = calculationStore.getOptions(elementName);
    return elementOptions?.length;
  },
  effect: length => {
    calculationStore.setStatus(
      elementName,
      length ? ElementStatus.Default : ElementStatus.Disabled,
    );
  },
  options: {
    fireImmediately: true,
  },
})) as IReactionEffect[];
