import { render } from '@ablogcms/react-utils';
import { BackgroundProcess } from '@ablogcms/background-process';

export default function dispatchCsvImport(context: Element | Document = document) {
  const element = context.querySelector<HTMLElement>('#js-background-csv-import');
  if (!element) {
    return;
  }
  const type = element.dataset.type || '';
  const successMessage = element.dataset.successMessage || '';
  const errorMessage = element.dataset.errorMessage || '';
  const showProcessList = element.dataset.showProcessList !== 'false';

  render(
    <BackgroundProcess
      type={type}
      successMessage={successMessage}
      errorMessage={errorMessage}
      showProcessList={showProcessList}
    />,
    element
  );
}
