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

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

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