"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var link_viewer_wrapper_exports = {};
__export(link_viewer_wrapper_exports, {
  LinkViewerWrapper: () => LinkViewerWrapper
});
module.exports = __toCommonJS(link_viewer_wrapper_exports);
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../../../../ricos-context/index.js");
var import_v1 = require("./../../../../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_get_link_href_url = require("./../../../../../_shared/link/get-link-href-url.js");
var import_wix_rich_content_common = require("./../../../../../wix-rich-content-common/index.js");
var import_link_viewer_wrapper_scss = __toESM(require("./link-viewer-wrapper-scss.js"));
const LinkViewerWrapper = ({
  children,
  nodeType,
  link
}) => {
  const { anchorTarget, baseUrl, customAnchorScroll } = (0, import_react.useContext)(import_ricos_context.RicosViewerContext);
  const { tabIndex } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  if (!(link && nodeType !== import_v1.Node_Type.BUTTON)) {
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
  }
  return /* @__PURE__ */ import_react.default.createElement(
    "a",
    {
      className: (0, import_classnames.default)(import_link_viewer_wrapper_scss.default.link, "has-custom-focus", {
        [import_link_viewer_wrapper_scss.default.anchor]: link
      }),
      tabIndex,
      href: link ? (0, import_get_link_href_url.getLinkHrefUrl)(link, baseUrl) : void 0,
      target: link.target ? `_${link.target.toLowerCase()}` : anchorTarget,
      rel: link.rel && (0, import_wix_rich_content_common.convertRelObjectToString)(link.rel),
      onClick: link?.anchor ? (e) => {
        if (customAnchorScroll) {
          return customAnchorScroll(e, link?.anchor);
        }
        const anchorRefId = `viewer-${link?.anchor}`;
        const element = document.getElementById(anchorRefId);
        if (!element) {
          return;
        }
        (0, import_wix_rich_content_common.addAnchorTagToUrl)(anchorRefId);
        (0, import_wix_rich_content_common.anchorScroll)(element);
      } : void 0
    },
    children
  );
};
//# sourceMappingURL=link-viewer-wrapper.js.map
