"use strict";

exports.__esModule = true;
exports.default = void 0;
var _omit2 = _interopRequireDefault(require("lodash/fp/omit"));
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _has2 = _interopRequireDefault(require("lodash/fp/has"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _moduleBubble = _interopRequireDefault(require("../module-bubble"));
var _style = _interopRequireDefault(require("./style.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (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 _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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); }
const Tab = ({
  index,
  selected,
  onClick = _noop2.default,
  level
}) => {
  const handleClick = (0, _react.useMemo)(() => () => onClick(index), [onClick, index]);
  const isSelected = selected === index;
  const bubble = (0, _has2.default)('status', level) ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.module
  }, /*#__PURE__*/_react.default.createElement(_moduleBubble.default, _extends({}, level, {
    onClick: handleClick
  }))) : null;
  return /*#__PURE__*/_react.default.createElement("li", {
    "data-name": "scopeTab",
    "data-index": index,
    key: index,
    onClick: handleClick,
    className: (0, _classnames.default)(_style.default.defaultTab, isSelected ? _style.default.currentTab : null)
  }, bubble, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.name
  }, level.name));
};
Tab.propTypes = process.env.NODE_ENV !== "production" ? {
  selected: _propTypes.default.number,
  index: _propTypes.default.number,
  onClick: _propTypes.default.func,
  level: _propTypes.default.shape((0, _omit2.default)('onClick', _moduleBubble.default.propTypes))
} : {};
const ScopeTabs = (props, context) => {
  const {
    onClick,
    selected = 0,
    levels = []
  } = props;
  const scopeContent = /*#__PURE__*/_react.default.createElement("ul", {
    "data-name": "scopeTabs",
    className: _style.default.tabs
  }, levels.map((level, index) => /*#__PURE__*/_react.default.createElement(Tab, {
    key: index,
    index: index,
    level: level,
    onClick: onClick,
    selected: selected
  })));
  return levels.length > 1 ? /*#__PURE__*/_react.default.createElement("nav", null, scopeContent) : /*#__PURE__*/_react.default.createElement("div", null, scopeContent);
};
ScopeTabs.propTypes = process.env.NODE_ENV !== "production" ? {
  selected: _propTypes.default.number,
  onClick: _propTypes.default.func,
  levels: _propTypes.default.arrayOf(_propTypes.default.object)
} : {};
var _default = exports.default = ScopeTabs;
//# sourceMappingURL=index.js.map