"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 utils_exports = {};
__export(utils_exports, {
  hasFullscreen: () => hasFullscreen,
  mergeViewerProps: () => mergeViewerProps
});
module.exports = __toCommonJS(utils_exports);
var import_function = require("fp-ts-esm/function");
var import_lodash = __toESM(require("lodash"));
var import_ricos_content = require("./../ricos-content/index.js");
var import_link_converters = require("./../wix-rich-content-common/lib/link-converters.js");
var import_biUtils = require("./biUtils/index.js");
var import_is_viewer_plugin = require("./is-viewer-plugin.js");
var import_plugins_strategy = require("./plugins-strategy.js");
const combineMappers = (mappers, ...args) => {
  if (!mappers || mappers.some((resolver) => typeof resolver !== "function")) {
    console.warn(`${mappers} is expected to be a function array`);
    return {};
  }
  return mappers.reduce((map, mapper) => Object.assign(map, mapper(...args)), {});
};
function mergeViewerProps({
  pluginConfig,
  helpers,
  isMobile,
  addAnchors,
  onError,
  mediaSettings = {},
  linkSettings = {},
  generalLinkSettings,
  textAlignment,
  experiments,
  iframeSandboxDomain,
  theme,
  plugins = [],
  content,
  viewerProps,
  onNodeClick,
  debugMode,
  jsdomMode,
  baseUrl
}) {
  const rcvPluginProps = (0, import_plugins_strategy.pluginsStrategy)({
    plugins: plugins?.filter(import_is_viewer_plugin.isViewerPlugin),
    viewerProps
  });
  const { pauseMedia, disableRightClick } = mediaSettings;
  const { customAnchorScroll } = linkSettings;
  let { anchorTarget = "_blank", relValue, rel } = linkSettings;
  if (relValue) {
    console.warn(
      // oxlint-disable-next-line max-len
      `relValue is deprecated, Please use rel prop instead.`
    );
    rel = (0, import_link_converters.convertRelStringToObject)(relValue) || rel;
  }
  const { target, ...relAttributes } = generalLinkSettings?.initialLinkOptions || {};
  anchorTarget = target || anchorTarget;
  rel = { ...rel, ...relAttributes };
  relValue = (0, import_link_converters.convertRelObjectToString)(rel);
  const disableDownload = mediaSettings?.disableDownload || disableRightClick;
  const ricosPropsToMerge = {
    addAnchors,
    isMobile,
    config: {
      uiSettings: { disableDownload }
    },
    content,
    onError,
    helpers: {},
    disabled: pauseMedia,
    anchorTarget,
    relValue,
    customAnchorScroll,
    textAlignment,
    experiments,
    iframeSandboxDomain,
    theme,
    onNodeClick,
    jsdomMode,
    baseUrl
  };
  const mergedRCProps = (0, import_function.pipe)(
    import_lodash.default.merge(
      { locale: "en", config: {} },
      rcvPluginProps,
      { config: pluginConfig, helpers },
      ricosPropsToMerge,
      viewerProps
    ),
    (0, import_biUtils.applyBIGenerics)(() => content?.metadata?.id)
  );
  return {
    ...mergedRCProps,
    debugMode,
    plugins,
    typeMappers: combineMappers(mergedRCProps.typeMappers || [])
  };
}
function hasFullscreen(config) {
  const { [import_ricos_content.IMAGE_TYPE]: imageConfig, [import_ricos_content.GALLERY_TYPE]: galleryConfig } = config || {};
  const needsFullscreenProvider = !imageConfig?.onExpand || !galleryConfig?.onExpand;
  const isExpandDisabled = (!imageConfig || imageConfig.disableExpand) && (!galleryConfig || galleryConfig?.disableExpand);
  return !isExpandDisabled && needsFullscreenProvider;
}
//# sourceMappingURL=utils.js.map
