"use strict";

exports.__esModule = true;
exports.Tabs = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styled = require("./styled");
var _tabsHooks = require("./tabs-hooks");
var _excluded = ["className", "onChange", "selected", "children", "TabsHeader", "TabContent", "noDefaultBorder", "tabsProps", "tabContentProps", "ref"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
var Tabs = exports.Tabs = function Tabs(_ref) {
  var className = _ref.className,
    onChange = _ref.onChange,
    selected = _ref.selected,
    children = _ref.children,
    _ref$TabsHeader = _ref.TabsHeader,
    TabsHeader = _ref$TabsHeader === void 0 ? _react.Fragment : _ref$TabsHeader,
    _ref$TabContent = _ref.TabContent,
    TabContent = _ref$TabContent === void 0 ? _react.Fragment : _ref$TabContent,
    noDefaultBorder = _ref.noDefaultBorder,
    tabsProps = _ref.tabsProps,
    tabContentProps = _ref.tabContentProps,
    ref = _ref.ref,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _useSetActive = (0, _tabsHooks.useSetActive)(selected, onChange),
    activeIndex = _useSetActive[0],
    setActiveIndex = _useSetActive[1];
  var _useBuildTabs = (0, _tabsHooks.useBuildTabs)(children, activeIndex, setActiveIndex),
    nav = _useBuildTabs[0],
    content = _useBuildTabs[1],
    firstActiveIndex = _useBuildTabs[2],
    activeIsDisabled = _useBuildTabs[3];
  (0, _react.useEffect)(function () {
    if (activeIsDisabled && activeIndex !== firstActiveIndex) setActiveIndex(firstActiveIndex);
  }, [activeIndex, firstActiveIndex, activeIsDisabled, setActiveIndex]);
  return /*#__PURE__*/_react["default"].createElement(_styled.StyledTabsWrapper, _extends({
    className: className
  }, rest, {
    ref: ref
  }), /*#__PURE__*/_react["default"].createElement(TabsHeader, null, /*#__PURE__*/_react["default"].createElement(_styled.StyledTabs, _extends({
    className: "tabs",
    noDefaultBorder: noDefaultBorder
  }, tabsProps), nav)), /*#__PURE__*/_react["default"].createElement(TabContent, tabContentProps, content));
};