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

export default ([
  { elementName: 'selectLead', urlName: 'leadUrl' },
  { elementName: 'selectOpportunity', urlName: 'opportunityUrl' },
  { elementName: 'selectQuote', urlName: 'quoteUrl' },
] as {
  elementName: ElementsNames;
  urlName: LinksNames;
}[]).map(({ elementName, urlName }) => calculationStore => ({
  expression: () => {
    return calculationStore.getOption(elementName);
  },
  effect: targetEntity => {
    const { calculationUrls } = calculationStore.stores;
    const link = targetEntity?.link ?? undefined;
    calculationUrls.setUrl({ name: urlName, url: link });
  },
})) as IReactionEffect[];
