"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 wait_message_exports = {};
__export(wait_message_exports, {
  WaitMessage: () => WaitMessage
});
module.exports = __toCommonJS(wait_message_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_styled_components = __toESM(require("styled-components"));
var import_ds_backdrop = require("@elliemae/ds-backdrop");
var import_ds_circular_progress_indicator = require("@elliemae/ds-circular-progress-indicator");
var import_react2 = require("../../data/react.js");
var import_use_html_wait_message = require("./use-html-wait-message.js");
var import_user_wait_event = require("../../analytics/user-wait-event.js");
var import_logrocket = require("../../utils/logrocket.js");
const StyledCircularIndicator = (0, import_styled_components.default)(import_ds_circular_progress_indicator.DSCircularIndeterminateIndicator)`
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
`;
const WaitMessage = (0, import_react.memo)(
  ({
    size = "xl",
    color = "light",
    showText = true,
    withTooltip = false,
    tooltipStartPlacementPreference = "center",
    ...rest
  }) => {
    const theme = (0, import_react.useContext)(import_styled_components.ThemeContext);
    const ref = (0, import_react.useRef)(false);
    const [show, setShow] = (0, import_react.useState)(false);
    const isOpen = (0, import_react2.useAppSelector)((state) => state.waitMessage?.isOpen);
    const delay = (0, import_react2.useAppSelector)((state) => state.waitMessage?.delay);
    ref.current = isOpen ?? false;
    const message = (0, import_react2.useAppSelector)((state) => state.waitMessage?.message);
    (0, import_react.useEffect)(() => {
      setTimeout(
        () => {
          if (isOpen && ref.current) {
            setShow(true);
            (0, import_user_wait_event.waitStartEvent)();
            (0, import_logrocket.lrTrack)("wait-spinner-start");
          }
        },
        delay ? 1e3 : 0
      );
      if (!isOpen) {
        setShow(false);
        (0, import_user_wait_event.waitEndEvent)();
        (0, import_logrocket.lrTrack)("wait-spinner-end");
      }
    }, [delay, isOpen]);
    (0, import_use_html_wait_message.useHTMLWaitMessage)(isOpen !== null);
    return show ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ds_backdrop.DSBackdrop, { zIndex: theme.zIndex.loader }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        StyledCircularIndicator,
        {
          id: "em-loading",
          size,
          color,
          showText,
          withTooltip,
          tooltipStartPlacementPreference,
          ...rest,
          text: message
        }
      )
    ] }) : null;
  }
);
