var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
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(
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
var stdin_exports = {};
__export(stdin_exports, {
  default: () => stdin_default
});
module.exports = __toCommonJS(stdin_exports);
var import_react = __toESM(require("react"));
var import_react_dom = __toESM(require("react-dom"));
var import_utils = require("../utils");
var import_ImagePreview = __toESM(require("./ImagePreview"));
var import_getContainer = require("../utils/dom/getContainer");
function _extends() {
  _extends = Object.assign ? Object.assign.bind() : function(target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];
      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }
    return target;
  };
  return _extends.apply(this, arguments);
}
const ImagePreview = import_ImagePreview.default;
const defaultConfig = {
  loop: true,
  images: [],
  className: "",
  showIndex: true,
  closeable: false,
  closeIcon: "clear",
  startPosition: 0,
  swipeDuration: 300,
  closeOnPopstate: true,
  closeIconPosition: "top-right"
};
ImagePreview.open = (props) => {
  const _a = props, {
    onClose = import_utils.noop,
    beforeClose
  } = _a, restProps = __objRest(_a, [
    "onClose",
    "beforeClose"
  ]);
  const userContainer = (0, import_getContainer.resolveContainer)(props.teleport);
  const container = document.createElement("div");
  userContainer.appendChild(container);
  let destroy = import_utils.noop;
  const TempDialog = () => {
    const [visible, setVisible] = (0, import_react.useState)(false);
    (0, import_react.useEffect)(() => {
      setVisible(true);
    }, []);
    destroy = (p) => {
      setVisible(false);
      if (onClose)
        onClose(p);
    };
    const _afterClose = (p) => __async(void 0, null, function* () {
      if ((yield beforeClose == null ? void 0 : beforeClose(0)) !== false) {
        destroy(p);
        const unmountResult = import_react_dom.default.unmountComponentAtNode(container);
        if (unmountResult && container.parentNode) {
          container.parentNode.removeChild(container);
        }
        return true;
      }
      return false;
    });
    return /* @__PURE__ */ import_react.default.createElement(import_ImagePreview.default, _extends({}, defaultConfig, restProps, {
      visible,
      teleport: () => container,
      onClose: destroy,
      beforeClose: _afterClose
    }));
  };
  import_react_dom.default.render(/* @__PURE__ */ import_react.default.createElement(TempDialog, null), container);
  return {
    close: destroy
  };
};
var stdin_default = ImagePreview;
