var global = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {};
import {
  constants_default,
  isSEOMode,
  isSiteMode,
  utils_default,
  windowWrapper_default
} from "./chunk-D3Y2XBAR.mjs";
import {
  init_define_process_env
} from "./chunk-FOPGQED5.mjs";

// ../../node_modules/@wix/showcase-organize-media/node_modules/pro-gallery/dist/esm/components/item/itemHelper.js
init_define_process_env();
function shouldChangeActiveElement(isAccessible) {
  if (isAccessible) {
    return (isSiteMode() || isSEOMode()) && windowWrapper_default.document;
  }
  return (isSiteMode() || isSEOMode()) && !utils_default.isMobile() && windowWrapper_default.document;
}
function onAnchorFocus(_a) {
  var itemContainer = _a.itemContainer, enableExperimentalFeatures = _a.enableExperimentalFeatures, itemAnchor = _a.itemAnchor, isAccessible = _a.isAccessible;
  if (shouldChangeActiveElement(isAccessible) && enableExperimentalFeatures) {
    var activeElement = windowWrapper_default.document.activeElement;
    if (activeElement === itemAnchor) {
      itemContainer.focus();
    }
  }
}
function isThisGalleryElementInFocus(className, galleryId) {
  var activeElement = windowWrapper_default.document.activeElement;
  return String(activeElement.className).includes(className) && !!windowWrapper_default.document.querySelector("#pro-gallery-".concat(galleryId, " #").concat(String(activeElement.id)));
}
function changeActiveElementIfNeeded(_a) {
  var prevProps = _a.prevProps, currentProps = _a.currentProps, itemActionRef = _a.itemActionRef, isAccessible = _a.isAccessible;
  try {
    if (shouldChangeActiveElement(isAccessible) && windowWrapper_default.document.activeElement.className) {
      var isGalleryItemAction = isThisGalleryElementInFocus("item-action", currentProps.galleryId);
      var isShowMoreInFocus = isThisGalleryElementInFocus("show-more", currentProps.galleryId);
      if (isGalleryItemAction || isShowMoreInFocus) {
        if (currentProps.thumbnailHighlightId !== prevProps.thumbnailHighlightId && currentProps.thumbnailHighlightId === currentProps.id) {
          itemActionRef.focus();
        } else if (currentProps.activeIndex !== prevProps.activeIndex && currentProps.activeIndex === currentProps.idx) {
          itemActionRef.focus();
        }
      }
    }
  } catch (e) {
    console.error("Could not set focus to active element", e);
  }
}
function shouldCreateVideoPlaceholder(options) {
  return options.enableVideoPlaceholder && (!utils_default.isSingleItemHorizontalDisplay(options) || options.videoPlay !== constants_default.videoPlay.AUTO);
}

export {
  onAnchorFocus,
  changeActiveElementIfNeeded,
  shouldCreateVideoPlaceholder
};
//# sourceMappingURL=chunk-KK6IAXDC.mjs.map