import { useStores } from '../useStores';

export const useOptions = elementName => {
  const { calculationStore } = useStores();
  const options = calculationStore?.options?.[elementName] || [];
  const filter = calculationStore?.filters?.[elementName];

  return {
    options: filter ? filter(options) : options,
  };
};

export const useTableOptions = ({ tableName, rowIndex, propName }) => {
  const { calculationStore } = useStores();
  const options =
    calculationStore?.tables?.[tableName]?.options?.[propName] || [];
  const filter =
    calculationStore?.tables?.[tableName]?.rows?.[rowIndex]?.[propName]?.filter;

  return {
    options: filter ? filter(options) : options,
  };
};
