import createResizeImageOptions from '../built-in/lib/create-resize-image-options';

export default async function dispatchResizeImageCF(context: Element | Document) {
  const elements = context.querySelectorAll(ACMS.Config.resizeImageTargetMarkCF);
  if (elements.length === 0) {
    return;
  }

  const { default: ResizeImageController } = await import(
    /* webpackChunkName: "resize-image" */ '@ablogcms/resize-image/controller'
  );
  const options = createResizeImageOptions();
  elements.forEach((element) => {
    if (!element.closest('.item-template')) {
      const resizeImg = new ResizeImageController(element, options);
      resizeImg.resize();
    }
  });
}
