"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 use_options_exports = {};
__export(use_options_exports, {
  useOptions: () => useOptions
});
module.exports = __toCommonJS(use_options_exports);
var import_pro_gallery = require("pro-gallery");
var import_pro_gallery_lib = require("pro-gallery-lib");
var import_react = 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_defaults = require("../defaults.js");
var import_utils = require("./utils.js");
const convertToGalleryOptions = (options) => {
  const galleryOptions = {};
  const { layout, thumbnails, item } = options;
  if (layout) {
    const { type, horizontalScroll, orientation, numberOfColumns, mobileNumberOfColumns } = layout;
    type && (galleryOptions.galleryLayout = parseInt(import_utils.GALLERY_LAYOUT_TO_NUMBER[type].toString()));
    horizontalScroll && (galleryOptions.scrollDirection = import_utils.SCROLL_DIRECTION_TO_NUMBER[import_pro_gallery.GALLERY_CONSTS.layoutParams_structure_scrollDirection.HORIZONTAL]);
    orientation && (galleryOptions.isVertical = orientation === "COLUMNS");
    typeof numberOfColumns === "number" && (galleryOptions.numberOfImagesPerRow = numberOfColumns);
    typeof mobileNumberOfColumns === "number" && (galleryOptions.m_numberOfImagesPerRow = mobileNumberOfColumns);
  }
  const { targetSize, ratio, crop, spacing } = item || {};
  if (typeof targetSize === "number") {
    galleryOptions.gallerySizePx = targetSize;
  } else {
    galleryOptions.gallerySizePx = 300;
  }
  typeof ratio === "number" && (galleryOptions.cubeRatio = ratio);
  crop && (galleryOptions.cubeType = crop.toLowerCase());
  typeof spacing === "number" && (galleryOptions.imageMargin = spacing);
  if (thumbnails) {
    const { placement, spacing: spacing2 } = thumbnails;
    placement && (galleryOptions.galleryThumbnailsAlignment = placement.toLowerCase());
    typeof spacing2 === "number" && (galleryOptions.thumbnailSpacings = spacing2 / 2);
  }
  return galleryOptions;
};
function useOptions(ricosOptions, disableDownload, items) {
  const { isMobile } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const galleryOptions = (0, import_react.useMemo)(() => {
    const isHorizontal = (0, import_utils.isHorizontalLayout)(ricosOptions);
    const calculatedOptions = {
      ...(0, import_defaults.getFixedStyles)(ricosOptions.layout?.type || import_v1.GalleryOptions_Layout_Type.GRID),
      allowContextMenu: !disableDownload,
      showArrows: isHorizontal,
      responsive: true,
      ...convertToGalleryOptions(ricosOptions)
    };
    if (isMobile) {
      if (calculatedOptions.m_numberOfImagesPerRow) {
        calculatedOptions.numberOfImagesPerRow = calculatedOptions.m_numberOfImagesPerRow;
      }
      if (isHorizontal) {
        calculatedOptions.arrowsSize = 20;
        !calculatedOptions.imageMargin && (calculatedOptions.imageMargin = 0);
        if (calculatedOptions.galleryLayout === import_utils.GALLERY_LAYOUT_TO_NUMBER[import_v1.GalleryOptions_Layout_Type.THUMBNAIL]) {
          calculatedOptions.thumbnailSize = 90;
        }
      }
    }
    const options = (0, import_pro_gallery_lib.migrateOptions)(calculatedOptions);
    if (options.layoutParams_structure_galleryLayout === import_utils.GALLERY_LAYOUT_TO_NUMBER[import_v1.GalleryOptions_Layout_Type.SLIDER]) {
      const galleryRatio = calculatedOptions.cubeRatio ? 1 / calculatedOptions.cubeRatio : null;
      const minItemRatio = Math.min(
        ...items.map((item) => item.metaData.height / item.metaData.width)
      );
      options.layoutParams_structure_galleryRatio_value = // Keep itemRatio within range [16:9 ... 1:1]:
      galleryRatio || Math.max(9 / 16, Math.min(1, minItemRatio));
    }
    return { options, calculatedOptions };
  }, [items, ricosOptions]);
  return galleryOptions;
}
//# sourceMappingURL=use-options.js.map
