"use strict";
const objectWithoutPropertiesLoose = require("../../../../@babel_runtime@7.19.0/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js");
const _extends = require("../../../../@babel_runtime@7.19.0/node_modules/@babel/runtime/helpers/esm/extends.js");
const assertThisInitialized = require("../../../../@babel_runtime@7.19.0/node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js");
const inheritsLoose = require("../../../../@babel_runtime@7.19.0/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js");
const PropTypes = require("prop-types");
const React = require("react");
const TransitionGroupContext = require("./TransitionGroupContext.js");
const ChildMapping = require("./utils/ChildMapping.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const PropTypes__default = /* @__PURE__ */ _interopDefaultLegacy(PropTypes);
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
var values = Object.values || function(obj) {
  return Object.keys(obj).map(function(k) {
    return obj[k];
  });
};
var defaultProps = {
  component: "div",
  childFactory: function childFactory(child) {
    return child;
  }
};
var TransitionGroup = /* @__PURE__ */ function(_React$Component) {
  inheritsLoose(TransitionGroup2, _React$Component);
  function TransitionGroup2(props, context) {
    var _this;
    _this = _React$Component.call(this, props, context) || this;
    var handleExited = _this.handleExited.bind(assertThisInitialized(_this));
    _this.state = {
      contextValue: {
        isMounting: true
      },
      handleExited,
      firstRender: true
    };
    return _this;
  }
  var _proto = TransitionGroup2.prototype;
  _proto.componentDidMount = function componentDidMount() {
    this.mounted = true;
    this.setState({
      contextValue: {
        isMounting: false
      }
    });
  };
  _proto.componentWillUnmount = function componentWillUnmount() {
    this.mounted = false;
  };
  TransitionGroup2.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, _ref) {
    var prevChildMapping = _ref.children, handleExited = _ref.handleExited, firstRender = _ref.firstRender;
    return {
      children: firstRender ? ChildMapping.getInitialChildMapping(nextProps, handleExited) : ChildMapping.getNextChildMapping(nextProps, prevChildMapping, handleExited),
      firstRender: false
    };
  };
  _proto.handleExited = function handleExited(child, node) {
    var currentChildMapping = ChildMapping.getChildMapping(this.props.children);
    if (child.key in currentChildMapping)
      return;
    if (child.props.onExited) {
      child.props.onExited(node);
    }
    if (this.mounted) {
      this.setState(function(state) {
        var children = _extends({}, state.children);
        delete children[child.key];
        return {
          children
        };
      });
    }
  };
  _proto.render = function render() {
    var _this$props = this.props, Component = _this$props.component, childFactory2 = _this$props.childFactory, props = objectWithoutPropertiesLoose(_this$props, ["component", "childFactory"]);
    var contextValue = this.state.contextValue;
    var children = values(this.state.children).map(childFactory2);
    delete props.appear;
    delete props.enter;
    delete props.exit;
    if (Component === null) {
      return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(TransitionGroupContext.Provider, {
        value: contextValue,
        children
      });
    }
    return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(TransitionGroupContext.Provider, {
      value: contextValue,
      children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(Component, {
        ...props,
        children
      })
    });
  };
  return TransitionGroup2;
}(React__default.default.Component);
TransitionGroup.propTypes = process.env.NODE_ENV !== "production" ? {
  component: PropTypes__default.default.any,
  children: PropTypes__default.default.node,
  appear: PropTypes__default.default.bool,
  enter: PropTypes__default.default.bool,
  exit: PropTypes__default.default.bool,
  childFactory: PropTypes__default.default.func
} : {};
TransitionGroup.defaultProps = defaultProps;
const TransitionGroup$1 = TransitionGroup;
module.exports = TransitionGroup$1;
//# sourceMappingURL=TransitionGroup.js.map
