"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.default = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var _react = _interopRequireDefault(require("react")); var _isRequiredForA11y = _interopRequireDefault(require("prop-types-extra/lib/isRequiredForA11y")); var _uncontrollable = require("uncontrollable"); var _Nav = _interopRequireDefault(require("./Nav")); var _NavLink = _interopRequireDefault(require("./NavLink")); var _NavItem = _interopRequireDefault(require("./NavItem")); var _TabContainer = _interopRequireDefault(require("./TabContainer")); var _TabContent = _interopRequireDefault(require("./TabContent")); var _TabPane = _interopRequireDefault(require("./TabPane")); var _ElementChildren = require("./ElementChildren"); var _excluded = ["id", "onSelect", "transition", "mountOnEnter", "unmountOnExit", "children", "activeKey"]; var defaultProps = { variant: 'tabs', mountOnEnter: false, unmountOnExit: false }; function getDefaultActiveKey(children) { var defaultActiveKey; (0, _ElementChildren.forEach)(children, function (child) { if (defaultActiveKey == null) { defaultActiveKey = child.props.eventKey; } }); return defaultActiveKey; } function renderTab(child) { var _child$props = child.props, title = _child$props.title, eventKey = _child$props.eventKey, disabled = _child$props.disabled, tabClassName = _child$props.tabClassName, id = _child$props.id; if (title == null) { return null; } return /*#__PURE__*/_react.default.createElement(_NavItem.default, { as: _NavLink.default, eventKey: eventKey, disabled: disabled, id: id, className: tabClassName }, title); } var Tabs = function Tabs(props) { var _useUncontrolled = (0, _uncontrollable.useUncontrolled)(props, { activeKey: 'onSelect' }), id = _useUncontrolled.id, onSelect = _useUncontrolled.onSelect, transition = _useUncontrolled.transition, mountOnEnter = _useUncontrolled.mountOnEnter, unmountOnExit = _useUncontrolled.unmountOnExit, children = _useUncontrolled.children, _useUncontrolled$acti = _useUncontrolled.activeKey, activeKey = _useUncontrolled$acti === void 0 ? getDefaultActiveKey(children) : _useUncontrolled$acti, controlledProps = (0, _objectWithoutPropertiesLoose2.default)(_useUncontrolled, _excluded); return /*#__PURE__*/_react.default.createElement(_TabContainer.default, { id: id, activeKey: activeKey, onSelect: onSelect, transition: transition, mountOnEnter: mountOnEnter, unmountOnExit: unmountOnExit }, /*#__PURE__*/_react.default.createElement(_Nav.default, (0, _extends2.default)({}, controlledProps, { role: "tablist", as: "nav" }), (0, _ElementChildren.map)(children, renderTab)), /*#__PURE__*/_react.default.createElement(_TabContent.default, null, (0, _ElementChildren.map)(children, function (child) { var childProps = (0, _extends2.default)({}, child.props); delete childProps.title; delete childProps.disabled; delete childProps.tabClassName; return /*#__PURE__*/_react.default.createElement(_TabPane.default, childProps); }))); }; Tabs.defaultProps = defaultProps; Tabs.displayName = 'Tabs'; var _default = Tabs; exports.default = _default; module.exports = exports["default"];