"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var autolink_extension_exports = {};
__export(autolink_extension_exports, {
  autolinkExtension: () => autolinkExtension
});
module.exports = __toCommonJS(autolink_extension_exports);
var import_next_schema = require("./../ricos-schema/next-schema/index.js");
var import_ricos_types = require("./../ricos-types/index.js");
var import_tiptap_extensions = require("./../tiptap-extensions/index.js");
var import_models = require("./../tiptap-extensions/link/models.js");
var import_autolink = require("./autolink.js");
const autolinkExtension = (0, import_tiptap_extensions.createRicosFunctionalExtension)({
  type: "extension",
  groups: [],
  name: "autolink",
  reconfigure(config, _extensions, props, settings) {
    const { rel, relValue, anchorTarget = import_next_schema.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: import_models.RicosLink.of("", anchorTarget, relValue, actualRel),
          autolinkEnabled
        };
      }
    };
  },
  createExtensionConfig() {
    return {
      name: this.name,
      addProseMirrorPlugins() {
        if (!this.options.autolinkEnabled) {
          return [];
        }
        const linkMarkType = this.editor.schema.marks[import_ricos_types.Decoration_Type.LINK];
        if (!linkMarkType) {
          return [];
        }
        return [
          (0, import_autolink.autolink)({
            type: linkMarkType,
            defaultLink: this.options.defaultLink
          })
        ];
      }
    };
  }
});
//# sourceMappingURL=autolink-extension.js.map
