import React, { useEffect, useState } from "react";
import { Decoration_Type } from "./../ricos-schema/legacy/wix/rich_content/v1/index.js";
let sketchDecorator = null;
let sketchDecoratorPromise = null;
const loadSketchDecorator = () => {
  if (sketchDecorator) {
    return Promise.resolve(sketchDecorator);
  }
  sketchDecoratorPromise ??= import(
    /* webpackChunkName: "ricos_plugin_sketch_viewer_decorator" */
    "./sketch/node-view-decorator.js"
  ).then((mod) => {
    sketchDecorator = mod.SketchDecorator;
    return sketchDecorator;
  });
  return sketchDecoratorPromise;
};
const hasSketchDecoration = (node) => !!node.textData?.decorations?.some(({ type }) => type === Decoration_Type.SKETCH);
const SketchDecoratorLoader = (args) => {
  const [decorator, setDecorator] = useState(sketchDecorator);
  useEffect(() => {
    let mounted = true;
    void loadSketchDecorator().then((loadedDecorator) => {
      if (mounted) {
        setDecorator(loadedDecorator);
      }
    });
    return () => {
      mounted = false;
    };
  }, []);
  if (!decorator) {
    return /* @__PURE__ */ React.createElement(React.Fragment, null, args.element);
  }
  return decorator.decorate(args);
};
const sketchNodeViewDecorator = {
  rule: hasSketchDecoration,
  decorate: (args) => /* @__PURE__ */ React.createElement(SketchDecoratorLoader, { ...args })
};
export {
  sketchNodeViewDecorator
};
//# sourceMappingURL=sketch-viewer-decorator.js.map
