import type { Elements } from '../config/map/actions';
import { useStatus } from '@/stores/calculation/statuses/hooks';
import { observer } from 'mobx-react-lite';
import type { ComponentType } from 'react';

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

export default function buildAction<T>(
  Component: ComponentType<T>,
  { elementName, valueName: actionName }: BuilderProps
) {
  return observer((props: T) => {
    const status = useStatus(elementName);

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