import { Link_Target } from "./../ricos-schema/next-schema/index.js";
import { Decoration_Type } from "./../ricos-types/index.js";
import { createRicosFunctionalExtension } from "./../tiptap-extensions/index.js";
import { RicosLink } from "./../tiptap-extensions/link/models.js";
import { autolink } from "./autolink.js";
const autolinkExtension = createRicosFunctionalExtension({
  type: "extension",
  groups: [],
  name: "autolink",
  reconfigure(config, _extensions, props, settings) {
    const { rel, relValue, anchorTarget = Link_Target.BLANK } = props;
    const actualRel = {
      noreferrer: rel?.noreferrer ?? true,
      ...[rel?.nofollow ? { nofollow: true } : {}],
      ...[rel?.sponsored ? { sponsored: true } : {}]
    };
    const autolinkEnabled = settings.autoLink ?? true;
    return {
      ...config,
      addOptions() {
        return {
          defaultLink: RicosLink.of("", anchorTarget, relValue, actualRel),
          autolinkEnabled
        };
      }
    };
  },
  createExtensionConfig() {
    return {
      name: this.name,
      addProseMirrorPlugins() {
        if (!this.options.autolinkEnabled) {
          return [];
        }
        const linkMarkType = this.editor.schema.marks[Decoration_Type.LINK];
        if (!linkMarkType) {
          return [];
        }
        return [
          autolink({
            type: linkMarkType,
            defaultLink: this.options.defaultLink
          })
        ];
      }
    };
  }
});
export {
  autolinkExtension
};
//# sourceMappingURL=autolink-extension.js.map
