"use strict";
var _a;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const testUtils = require("react-dom/test-utils");
const React = require("react");
const ReactDOM = require("react-dom");
const ReactDOMClient = require("react-dom/client");
const dom_esm = require('./../../_node_modules/@testing-library/dom/dist/@testing-library/dom.esm.cjs');
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const testUtils__namespace = /* @__PURE__ */ _interopNamespaceDefault(testUtils);
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
const ReactDOMClient__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactDOMClient);
const domAct = testUtils__namespace.act;
function getGlobalThis() {
  if (typeof globalThis !== "undefined") {
    return globalThis;
  }
  if (typeof self !== "undefined") {
    return self;
  }
  if (typeof window !== "undefined") {
    return window;
  }
  if (typeof global !== "undefined") {
    return global;
  }
  throw new Error("unable to locate global object");
}
function setIsReactActEnvironment(isReactActEnvironment) {
  getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;
}
function getIsReactActEnvironment() {
  return getGlobalThis().IS_REACT_ACT_ENVIRONMENT;
}
function withGlobalActEnvironment(actImplementation) {
  return (callback) => {
    const previousActEnvironment = getIsReactActEnvironment();
    setIsReactActEnvironment(true);
    try {
      let callbackNeedsToBeAwaited = false;
      const actResult = actImplementation(() => {
        const result = callback();
        if (result !== null && typeof result === "object" && typeof result.then === "function") {
          callbackNeedsToBeAwaited = true;
        }
        return result;
      });
      if (callbackNeedsToBeAwaited) {
        const thenable = actResult;
        return {
          then: (resolve, reject) => {
            thenable.then((returnValue) => {
              setIsReactActEnvironment(previousActEnvironment);
              resolve(returnValue);
            }, (error) => {
              setIsReactActEnvironment(previousActEnvironment);
              reject(error);
            });
          }
        };
      } else {
        setIsReactActEnvironment(previousActEnvironment);
        return actResult;
      }
    } catch (error) {
      setIsReactActEnvironment(previousActEnvironment);
      throw error;
    }
  };
}
const act = withGlobalActEnvironment(domAct);
Object.keys(dom_esm.fireEvent).forEach((key) => {
});
function jestFakeTimersAreEnabled() {
  if (typeof jest !== "undefined" && jest !== null) {
    return (
      // legacy timers
      setTimeout._isMockFunction === true || // modern timers
      // eslint-disable-next-line prefer-object-has-own -- No Object.hasOwn in all target environments we support.
      Object.prototype.hasOwnProperty.call(setTimeout, "clock")
    );
  }
  return false;
}
dom_esm.configure({
  unstable_advanceTimersWrapper: (cb) => {
    return act(cb);
  },
  // We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
  // But that's not necessarily how `asyncWrapper` is used since it's a public method.
  // Let's just hope nobody else is using it.
  asyncWrapper: async (cb) => {
    const previousActEnvironment = getIsReactActEnvironment();
    setIsReactActEnvironment(false);
    try {
      const result = await cb();
      await new Promise((resolve) => {
        setTimeout(() => {
          resolve();
        }, 0);
        if (jestFakeTimersAreEnabled()) {
          jest.advanceTimersByTime(0);
        }
      });
      return result;
    } finally {
      setIsReactActEnvironment(previousActEnvironment);
    }
  },
  eventWrapper: (cb) => {
    let result;
    act(() => {
      result = cb();
    });
    return result;
  }
});
const mountedContainers = /* @__PURE__ */ new Set();
const mountedRootEntries = [];
function createConcurrentRoot(container, _ref) {
  let {
    hydrate,
    ui,
    wrapper: WrapperComponent
  } = _ref;
  let root;
  if (hydrate) {
    act(() => {
      root = ReactDOMClient__namespace.hydrateRoot(container, WrapperComponent ? /* @__PURE__ */ React__namespace.createElement(WrapperComponent, null, ui) : ui);
    });
  } else {
    root = ReactDOMClient__namespace.createRoot(container);
  }
  return {
    hydrate() {
      if (!hydrate) {
        throw new Error("Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.");
      }
    },
    render(element) {
      root.render(element);
    },
    unmount() {
      root.unmount();
    }
  };
}
function createLegacyRoot(container) {
  return {
    hydrate(element) {
      ReactDOM.hydrate(element, container);
    },
    render(element) {
      ReactDOM.render(element, container);
    },
    unmount() {
      ReactDOM.unmountComponentAtNode(container);
    }
  };
}
function renderRoot(ui, _ref2) {
  let {
    baseElement,
    container,
    hydrate,
    queries,
    root,
    wrapper: WrapperComponent
  } = _ref2;
  const wrapUiIfNeeded = (innerElement) => WrapperComponent ? /* @__PURE__ */ React__namespace.createElement(WrapperComponent, null, innerElement) : innerElement;
  act(() => {
    if (hydrate) {
      root.hydrate(wrapUiIfNeeded(ui), container);
    } else {
      root.render(wrapUiIfNeeded(ui), container);
    }
  });
  return {
    container,
    baseElement,
    debug: function(el, maxLength, options) {
      if (el === void 0) {
        el = baseElement;
      }
      return Array.isArray(el) ? (
        // eslint-disable-next-line no-console
        el.forEach((e) => console.log(dom_esm.prettyDOM(e, maxLength, options)))
      ) : (
        // eslint-disable-next-line no-console,
        console.log(dom_esm.prettyDOM(el, maxLength, options))
      );
    },
    unmount: () => {
      act(() => {
        root.unmount();
      });
    },
    rerender: (rerenderUi) => {
      renderRoot(wrapUiIfNeeded(rerenderUi), {
        container,
        baseElement,
        root
      });
    },
    asFragment: () => {
      if (typeof document.createRange === "function") {
        return document.createRange().createContextualFragment(container.innerHTML);
      } else {
        const template = document.createElement("template");
        template.innerHTML = container.innerHTML;
        return template.content;
      }
    },
    ...dom_esm.getQueriesForElement(baseElement, queries)
  };
}
function render(ui, _temp) {
  let {
    container,
    baseElement = container,
    legacyRoot = false,
    queries,
    hydrate = false,
    wrapper
  } = _temp === void 0 ? {} : _temp;
  if (!baseElement) {
    baseElement = document.body;
  }
  if (!container) {
    container = baseElement.appendChild(document.createElement("div"));
  }
  let root;
  if (!mountedContainers.has(container)) {
    const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot;
    root = createRootImpl(container, {
      hydrate,
      ui,
      wrapper
    });
    mountedRootEntries.push({
      container,
      root
    });
    mountedContainers.add(container);
  } else {
    mountedRootEntries.forEach((rootEntry) => {
      if (rootEntry.container === container) {
        root = rootEntry.root;
      }
    });
  }
  return renderRoot(ui, {
    container,
    baseElement,
    queries,
    hydrate,
    wrapper,
    root
  });
}
function cleanup() {
  mountedRootEntries.forEach((_ref3) => {
    let {
      root,
      container
    } = _ref3;
    act(() => {
      root.unmount();
    });
    if (container.parentNode === document.body) {
      document.body.removeChild(container);
    }
  });
  mountedRootEntries.length = 0;
  mountedContainers.clear();
}
function renderHook(renderCallback, options) {
  if (options === void 0) {
    options = {};
  }
  const {
    initialProps,
    ...renderOptions
  } = options;
  const result = /* @__PURE__ */ React__namespace.createRef();
  function TestComponent(_ref4) {
    let {
      renderCallbackProps
    } = _ref4;
    const pendingResult = renderCallback(renderCallbackProps);
    React__namespace.useEffect(() => {
      result.current = pendingResult;
    });
    return null;
  }
  const {
    rerender: baseRerender,
    unmount
  } = render(/* @__PURE__ */ React__namespace.createElement(TestComponent, {
    renderCallbackProps: initialProps
  }), renderOptions);
  function rerender(rerenderCallbackProps) {
    return baseRerender(/* @__PURE__ */ React__namespace.createElement(TestComponent, {
      renderCallbackProps: rerenderCallbackProps
    }));
  }
  return {
    result,
    rerender,
    unmount
  };
}
if (typeof process === "undefined" || !((_a = process.env) == null ? void 0 : _a.RTL_SKIP_AUTO_CLEANUP)) {
  if (typeof afterEach === "function") {
    afterEach(() => {
      cleanup();
    });
  } else if (typeof teardown === "function") {
    teardown(() => {
      cleanup();
    });
  }
  if (typeof beforeAll === "function" && typeof afterAll === "function") {
    let previousIsReactActEnvironment = getIsReactActEnvironment();
    beforeAll(() => {
      previousIsReactActEnvironment = getIsReactActEnvironment();
      setIsReactActEnvironment(true);
    });
    afterAll(() => {
      setIsReactActEnvironment(previousIsReactActEnvironment);
    });
  }
}
exports.buildQueries = dom_esm.buildQueries;
exports.configure = dom_esm.configure;
exports.createEvent = dom_esm.createEvent;
exports.findAllByAltText = dom_esm.findAllByAltText;
exports.findAllByDisplayValue = dom_esm.findAllByDisplayValue;
exports.findAllByLabelText = dom_esm.findAllByLabelText;
exports.findAllByPlaceholderText = dom_esm.findAllByPlaceholderText;
exports.findAllByRole = dom_esm.findAllByRole;
exports.findAllByTestId = dom_esm.findAllByTestId;
exports.findAllByText = dom_esm.findAllByText;
exports.findAllByTitle = dom_esm.findAllByTitle;
exports.findByAltText = dom_esm.findByAltText;
exports.findByDisplayValue = dom_esm.findByDisplayValue;
exports.findByLabelText = dom_esm.findByLabelText;
exports.findByPlaceholderText = dom_esm.findByPlaceholderText;
exports.findByRole = dom_esm.findByRole;
exports.findByTestId = dom_esm.findByTestId;
exports.findByText = dom_esm.findByText;
exports.findByTitle = dom_esm.findByTitle;
exports.getAllByAltText = dom_esm.getAllByAltText;
exports.getAllByDisplayValue = dom_esm.getAllByDisplayValue;
exports.getAllByLabelText = dom_esm.getAllByLabelText;
exports.getAllByPlaceholderText = dom_esm.getAllByPlaceholderText;
exports.getAllByRole = dom_esm.getAllByRole;
exports.getAllByTestId = dom_esm.getAllByTestId;
exports.getAllByText = dom_esm.getAllByText;
exports.getAllByTitle = dom_esm.getAllByTitle;
exports.getByAltText = dom_esm.getByAltText;
exports.getByDisplayValue = dom_esm.getByDisplayValue;
exports.getByLabelText = dom_esm.getByLabelText;
exports.getByPlaceholderText = dom_esm.getByPlaceholderText;
exports.getByRole = dom_esm.getByRole;
exports.getByTestId = dom_esm.getByTestId;
exports.getByText = dom_esm.getByText;
exports.getByTitle = dom_esm.getByTitle;
exports.getConfig = dom_esm.getConfig;
exports.getDefaultNormalizer = dom_esm.getDefaultNormalizer;
exports.getElementError = dom_esm.getElementError;
exports.getMultipleElementsFoundError = dom_esm.getMultipleElementsFoundError;
exports.getNodeText = dom_esm.getNodeText;
exports.getQueriesForElement = dom_esm.getQueriesForElement;
exports.getRoles = dom_esm.getRoles;
exports.getSuggestedQuery = dom_esm.getSuggestedQuery;
exports.isInaccessible = dom_esm.isInaccessible;
exports.logDOM = dom_esm.logDOM;
exports.makeFindQuery = dom_esm.makeFindQuery;
exports.makeGetAllQuery = dom_esm.makeGetAllQuery;
exports.makeSingleQuery = dom_esm.makeSingleQuery;
exports.prettyDOM = dom_esm.prettyDOM;
exports.queries = dom_esm.queries;
exports.queryAllByAltText = dom_esm.queryAllByAltText;
exports.queryAllByAttribute = dom_esm.queryAllByAttribute;
exports.queryAllByDisplayValue = dom_esm.queryAllByDisplayValue;
exports.queryAllByLabelText = dom_esm.queryAllByLabelText;
exports.queryAllByPlaceholderText = dom_esm.queryAllByPlaceholderText;
exports.queryAllByRole = dom_esm.queryAllByRole;
exports.queryAllByTestId = dom_esm.queryAllByTestId;
exports.queryAllByText = dom_esm.queryAllByText;
exports.queryAllByTitle = dom_esm.queryAllByTitle;
exports.queryByAltText = dom_esm.queryByAltText;
exports.queryByDisplayValue = dom_esm.queryByDisplayValue;
exports.queryByLabelText = dom_esm.queryByLabelText;
exports.queryByPlaceholderText = dom_esm.queryByPlaceholderText;
exports.queryByRole = dom_esm.queryByRole;
exports.queryByTestId = dom_esm.queryByTestId;
exports.queryByText = dom_esm.queryByText;
exports.queryByTitle = dom_esm.queryByTitle;
exports.waitFor = dom_esm.waitFor;
exports.within = dom_esm.getQueriesForElement;
exports.wrapAllByQueryWithSuggestion = dom_esm.wrapAllByQueryWithSuggestion;
exports.wrapSingleQueryWithSuggestion = dom_esm.wrapSingleQueryWithSuggestion;
exports.act = act;
exports.cleanup = cleanup;
exports.render = render;
exports.renderHook = renderHook;
//# sourceMappingURL=react.esm.cjs.map
