var _excluded = ["className", "onChange", "selected", "children", "TabsHeader", "TabContent", "noDefaultBorder", "tabsProps", "tabContentProps"];
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 (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
import React, { forwardRef, Fragment, useEffect } from "react";
import { StyledTabs, StyledTabsWrapper } from "./styled";
import { useBuildTabs, useSetActive } from "./tabs-hooks";
export var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var className = _ref.className,
    onChange = _ref.onChange,
    selected = _ref.selected,
    children = _ref.children,
    _ref$TabsHeader = _ref.TabsHeader,
    TabsHeader = _ref$TabsHeader === void 0 ? Fragment : _ref$TabsHeader,
    _ref$TabContent = _ref.TabContent,
    TabContent = _ref$TabContent === void 0 ? Fragment : _ref$TabContent,
    noDefaultBorder = _ref.noDefaultBorder,
    tabsProps = _ref.tabsProps,
    tabContentProps = _ref.tabContentProps,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _useSetActive = useSetActive(selected, onChange),
    activeIndex = _useSetActive[0],
    setActiveIndex = _useSetActive[1];
  var _useBuildTabs = useBuildTabs(children, activeIndex, setActiveIndex),
    nav = _useBuildTabs[0],
    content = _useBuildTabs[1],
    firstActiveIndex = _useBuildTabs[2],
    activeIsDisabled = _useBuildTabs[3];
  useEffect(function () {
    if (activeIsDisabled && activeIndex !== firstActiveIndex) setActiveIndex(firstActiveIndex);
  }, [activeIndex, firstActiveIndex, activeIsDisabled, setActiveIndex]);
  return /*#__PURE__*/React.createElement(StyledTabsWrapper, _extends({
    className: className
  }, rest, {
    ref: ref
  }), /*#__PURE__*/React.createElement(TabsHeader, null, /*#__PURE__*/React.createElement(StyledTabs, _extends({
    className: "tabs",
    noDefaultBorder: noDefaultBorder
  }, tabsProps), nav)), /*#__PURE__*/React.createElement(TabContent, tabContentProps, content));
});