"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);

// src/bundled-dependencies/pro-gallery-layout-fixer.ts
var pro_gallery_layout_fixer_exports = {};
__export(pro_gallery_layout_fixer_exports, {
  LayoutFixer: () => LayoutFixer
});
module.exports = __toCommonJS(pro_gallery_layout_fixer_exports);

// ../../node_modules/@wix/pro-gallery-layout-fixer/dist/esm/layoutFixer.js
var import_react = __toESM(require("react"));
var import_prop_types = __toESM(require("prop-types"));

// ../../node_modules/pro-gallery-lib/dist/esm/core/helpers/optionsUtils.js
function flattenObject(ob) {
  var toReturn = {};
  for (var i in ob) {
    if (!ob.hasOwnProperty(i))
      continue;
    if (typeof ob[i] == "object" && !(ob[i] instanceof Array) && ob[i] !== null && Object.keys(ob[i]).length > 0) {
      var flatObject = flattenObject(ob[i]);
      for (var x in flatObject) {
        if (!flatObject.hasOwnProperty(x))
          continue;
        toReturn[i + "_" + x] = flatObject[x];
      }
    } else {
      toReturn[i] = ob[i];
    }
  }
  return toReturn;
}

// ../../node_modules/@wix/pro-gallery-layout-fixer/dist/esm/extreact-style-params.js
function nativePGCreateGetOptionsFunc(options) {
  var baseOptions = flattenObject(options);
  var mainFunc = "(galleryEle) => {\n        const computedStyle = window.getComputedStyle(galleryEle);\n        const computedStyles = {};\n        // search css variables to query\n        const cssVariables = [];\n        const stylesheets = document.styleSheets;\n        for (let i = 0; i < stylesheets.length; i++) {\n            try {\n                const rules = stylesheets[i].rules || stylesheets[i].cssRules;\n                for (let j = 0; j < rules.length; j++) {\n                    const rule = rules[j];\n                    const style = rule.style;\n                    if (style) {\n                        for (let k = 0; k < style.length; k++) {\n                            const prop = style[k];\n                            if (prop.startsWith('--')) {\n                                if (prop.includes('ProGallery-')) {\n                                    cssVariables.push(prop);\n                                }\n                            }\n                        }\n                    }\n                }\n            } catch (e) {\n            }\n        }\n        const cssVariablesMap = cssVariables.map((item) => {\n            return {\n                name: item,\n                value: computedStyle.getPropertyValue(item),\n            }\n        }).filter((item) => item.value);\n        // get computed styles\n        for (let i = 0; i < cssVariablesMap.length; i++) {\n            computedStyles[cssVariablesMap[i].name] = cssVariablesMap[i].value;\n        }\n        const options = Object.entries(computedStyles).reduce((res, [key, value]) => {\n            const keyNameStart = key.indexOf('ProGallery-') + 'ProGallery-'.length;\n            const keyName = key.substring(keyNameStart);\n            res[keyName] = JSON.parse(value);\n            return res;\n        }, {});\n        const optionsStr = Object.entries({...".concat(JSON.stringify(baseOptions), `,...options})
        .map(([key, value]) => ([key, JSON.stringify(value)]))
        .filter(([key, value]) => key.includes('layoutParams_'))
        .map((keyval) => keyval.join(":")).join('|');
        return optionsStr;
    }`);
  return "(ele) => {\n        const mainFunc = ".concat(mainFunc, ";\n        return mainFunc(ele);\n    }");
}

// ../../node_modules/@wix/pro-gallery-layout-fixer/dist/esm/v4layoutRelevantOptions.js
var requiredOptions = [
  "isRTL",
  "cubeType",
  "cubeImages",
  "arrowsSize",
  "arrowsPosition",
  "cubeRatio",
  "cropRatio",
  "layoutParams_cropRatio",
  "collageAmount",
  "collageDensity",
  "columnsWidth",
  "cropOnlyFill",
  "chooseBestGroup",
  "externalInfoHeight",
  "externalInfoWidth",
  "fixedColumns",
  "groupsPerStrip",
  "galleryMargin",
  "layoutParams_gallerySpacing",
  "groupTypes",
  "groupSize",
  "isVertical",
  "imageMargin",
  "minItemSize",
  "scrollDirection",
  "placeGroupsLtr",
  "rotatingGroupTypes",
  "layoutParams_repeatingGroupTypes",
  "rotatingCropRatios",
  "smartCrop",
  "scatter",
  "smartCrop",
  "targetItemSize",
  "hasThumbnails",
  "thumbnailSize",
  "thumbnailSpacings",
  "galleryThumbnailsAlignment",
  "isSlideshow",
  "galleryLayout",
  "slideshowInfoSize",
  "layoutParams_structure_galleryRatio_value",
  "gallerySizeType",
  "gallerySizePx",
  "gallerySize",
  "enableInfiniteScroll",
  "imageInfoType",
  "textsHorizontalPadding",
  "gridStyle",
  "numberOfImagesPerRow",
  "calculateTextBoxHeightMode",
  "textBoxHeight",
  "textsVerticalPadding",
  "titlePlacement",
  "textBoxWidthPercent",
  "calculateTextBoxWidthMode"
];

// ../../node_modules/@wix/pro-gallery-layout-fixer/dist/esm/utils.js
var filterOptions = function(styleParams, requiredOptionsSubset) {
  return Object.keys(styleParams).filter(function(key) {
    return requiredOptionsSubset.indexOf(key) >= 0;
  }).reduce(function(res, key) {
    res[key] = styleParams[key];
    return res;
  }, {});
};
var hashToInt = function(str) {
  if (str === void 0) {
    str = "";
  }
  var int = 0;
  for (var i = 0; i < str.length; i++) {
    int += str.charCodeAt(i);
  }
  return int;
};

// ../../node_modules/@wix/pro-gallery-layout-fixer/dist/esm/layoutFixerEmbededJs.js
function getServerParams(props) {
  var items = props.items, _a = props.rawOptions, rawOptions = _a === void 0 ? props.options : _a, useNativeLayoutFixer = props.useNativeLayoutFixer, customCreateGetOptionsFunc = props.customCreateGetOptionsFunc;
  var itemsStr = items.slice(0, 20).map(function(item) {
    return "".concat(hashToInt(item.mediaUrl), "_").concat(item.width || item.metaData.width, "_").concat(item.height || item.metaData.height);
  }).join("|");
  if (useNativeLayoutFixer) {
    var getOptions = typeof customCreateGetOptionsFunc === "function" ? customCreateGetOptionsFunc(rawOptions) : nativePGCreateGetOptionsFunc(rawOptions);
    var hrefStr = "/_serverless/pro-gallery-native-layout-fixer/layoutCssNative?id=".concat(props.id, "&items=").concat(itemsStr, "&container=");
    return { hrefStr, getOptions };
  } else {
    var options = Object.entries(filterOptions(rawOptions, requiredOptions)).map(function(keyVal) {
      return keyVal.join(":");
    }).join("|");
    var hrefStr = "/_serverless/pro-gallery-css-v4-server/layoutCss?ver=2&id=".concat(props.id, "&items=").concat(itemsStr, "&container=");
    return { hrefStr, getOptions: "() => ".concat(JSON.stringify(options)) };
  }
}
function createSsrJs(props) {
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
  var useNativeLayoutFixer = props.useNativeLayoutFixer;
  var _12 = getServerParams(props), hrefStr = _12.hrefStr, getOptions = _12.getOptions;
  var containerId = props.measureContainerId || "pro-gallery-" + props.id;
  var embed = function(content) {
    return "\n  ".concat(content, `
  var isVertical = options.includes('layoutParams_structure_scrollDirection:"VERTICAL"');
  var layoutFixerUrl =  '`).concat(hrefStr, "' + pgMeasures.top + '_' + pgMeasures.width + '_' + pgMeasures.height + '_' + window.innerHeight + '&options=' + options;\n  document.getElementById('").concat("layout-fixer-style-" + props.id, "').setAttribute('href', encodeURI(layoutFixerUrl));\n});\n\n  ");
  };
  if (useNativeLayoutFixer) {
    return embed('\n      var ele = document.getElementById("'.concat(props.id, '"), nativeRect = ele.getBoundingClientRect();\n      var pgMeasures = {top: nativeRect.top, width: nativeRect.width, height: Number(getComputedStyle(ele).getPropertyValue("height").replace("px", ""))};\n      var options = (').concat(getOptions, ")(ele);\n    "));
  } else {
    return embed("\n      var ele = document.getElementById('".concat(containerId, "');\n      var pgMeasures = ele.getBoundingClientRect();\n      var options = (").concat(getOptions, ")(ele);\n      var width = pgMeasures.width;\n      var height = pgMeasures.height;\n\n      var isIOS = /iPad|iPhone|iPod/.test(navigator?.userAgent);\n      if(isIOS) {\n        width = ").concat(((_c = (_b = (_a = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _a === void 0 ? void 0 : _a.ios) === null || _b === void 0 ? void 0 : _b.width) === null || _c === void 0 ? void 0 : _c.percentage) ? "width * ".concat((_e = (_d = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _d === void 0 ? void 0 : _d.ios) === null || _e === void 0 ? void 0 : _e.width.percentage) : "width", ";\n        width = ").concat(((_h = (_g = (_f = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _f === void 0 ? void 0 : _f.ios) === null || _g === void 0 ? void 0 : _g.width) === null || _h === void 0 ? void 0 : _h.addition) ? "width + (".concat((_k = (_j = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _j === void 0 ? void 0 : _j.ios) === null || _k === void 0 ? void 0 : _k.width.addition, ")") : "width", ";\n        height = ").concat(((_o = (_m = (_l = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _l === void 0 ? void 0 : _l.ios) === null || _m === void 0 ? void 0 : _m.height) === null || _o === void 0 ? void 0 : _o.percentage) ? "height * ".concat((_r = (_q = (_p = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _p === void 0 ? void 0 : _p.ios) === null || _q === void 0 ? void 0 : _q.height) === null || _r === void 0 ? void 0 : _r.percentage) : "height", ";\n        height = ").concat(((_u = (_t = (_s = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _s === void 0 ? void 0 : _s.ios) === null || _t === void 0 ? void 0 : _t.height) === null || _u === void 0 ? void 0 : _u.addition) ? "height + (".concat((_x = (_w = (_v = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _v === void 0 ? void 0 : _v.ios) === null || _w === void 0 ? void 0 : _w.height) === null || _x === void 0 ? void 0 : _x.addition, ")") : "height", ";\n      } else {\n        width = ").concat(((_z = (_y = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _y === void 0 ? void 0 : _y.width) === null || _z === void 0 ? void 0 : _z.percentage) ? "width * ".concat((_0 = props.containerPostProcess) === null || _0 === void 0 ? void 0 : _0.width.percentage) : "width", ";\n        width = ").concat(((_2 = (_1 = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _1 === void 0 ? void 0 : _1.width) === null || _2 === void 0 ? void 0 : _2.addition) ? "width + (".concat((_3 = props.containerPostProcess) === null || _3 === void 0 ? void 0 : _3.width.addition, ")") : "width", ";\n        height = ").concat(((_5 = (_4 = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _4 === void 0 ? void 0 : _4.height) === null || _5 === void 0 ? void 0 : _5.percentage) ? "height * ".concat((_7 = (_6 = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _6 === void 0 ? void 0 : _6.height) === null || _7 === void 0 ? void 0 : _7.percentage) : "height", ";\n        height = ").concat(((_9 = (_8 = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _8 === void 0 ? void 0 : _8.height) === null || _9 === void 0 ? void 0 : _9.addition) ? "height + (".concat((_11 = (_10 = props === null || props === void 0 ? void 0 : props.containerPostProcess) === null || _10 === void 0 ? void 0 : _10.height) === null || _11 === void 0 ? void 0 : _11.addition, ")") : "height", ";\n      }\n\n      pgMeasures = { top: pgMeasures.top, width, height };\n"));
  }
}

// ../../node_modules/@wix/pro-gallery-layout-fixer/dist/esm/layoutFixer.js
var LayoutFixer = function(props) {
  var _a;
  try {
    var existingLinkUrl = typeof window !== "undefined" ? (((_a = window.document.getElementById("layout-fixer-style-" + props.id)) === null || _a === void 0 ? void 0 : _a.href) || "").replace(/^.*\/\/[^/]+/, "") : "";
    return import_react.default.createElement(
      "div",
      { id: "layout-fixer-" + props.id + props.isPrerenderMode, key: "layout-fixer-" + props.id + props.isPrerenderMode, style: { display: "none" } },
      props.isPrerenderMode && import_react.default.createElement("link", { href: existingLinkUrl, rel: "stylesheet", id: "layout-fixer-style-" + props.id }),
      import_react.default.createElement("script", { dangerouslySetInnerHTML: {
        __html: "try {\n            window.requestAnimationFrame(function() {\n              ".concat(createSsrJs(props), "\n        } catch (e) {\n          console.warn('Cannot set layoutFixer css', e);\n        }")
      } })
    );
  } catch (e) {
    return import_react.default.createElement("div", { id: "layoutFixerErrors", style: { display: "none" } }, e.toString());
  }
};
LayoutFixer.defaultProps = {
  measureContainerId: ""
};
LayoutFixer.propTypes = {
  isPrerenderMode: import_prop_types.default.bool,
  id: import_prop_types.default.string,
  items: import_prop_types.default.array,
  options: import_prop_types.default.object,
  useNativeLayoutFixer: import_prop_types.default.bool,
  containerPostProcess: import_prop_types.default.shape({
    width: import_prop_types.default.shape({
      percentage: import_prop_types.default.number,
      addition: import_prop_types.default.number
    }),
    height: import_prop_types.default.shape({
      percentage: import_prop_types.default.number,
      addition: import_prop_types.default.number
    }),
    ios: import_prop_types.default.shape({
      width: import_prop_types.default.shape({
        percentage: import_prop_types.default.number,
        addition: import_prop_types.default.number
      }),
      height: import_prop_types.default.shape({
        percentage: import_prop_types.default.number,
        addition: import_prop_types.default.number
      })
    })
  }),
  measureContainerId: import_prop_types.default.string
};
//# sourceMappingURL=pro-gallery-layout-fixer.js.map
