/* eslint-disable react/jsx-no-bind */
import { observer } from 'mobx-react-lite';
import type { FC } from 'react';
import { useStatus } from 'stores/calculation/statuses/hooks';
import type { Elements } from '../config/map-actions';
import type { ElementsProps } from '../types/elements-props';

type BuilderProps = {
  elementName: Elements;
  actionName: string;
};

export default function buildAction(Component: FC<any>, { elementName, actionName }: BuilderProps) {
  return observer<ElementsProps[typeof elementName]>((props) => {
    const status = useStatus(elementName);

    return (
      <Component
        status={status}
        action={() => import(`process/${actionName}`).then((m) => m.default())}
        {...props}
      />
    );
  });
}
