"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.name = void 0;

var React = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _styles = require("@fluent-ui/styles");

var _Tabs = require("./Tabs.styled");

var _Tabs2 = require("./Tabs.type");

var _Panel = _interopRequireDefault(require("./components/Panel"));

var _Navigation = _interopRequireDefault(require("../Navigation"));

var _Item = _interopRequireDefault(require("../Item"));

var _Box = _interopRequireDefault(require("../Box"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var name = 'Tabs';
exports.name = name;
var useStyles = (0, _styles.createUseStyles)(_Tabs.styles, {
  name: name
});
var Tabs = React.forwardRef(function (props, ref) {
  var _props$as = props.as,
      as = _props$as === void 0 ? 'div' : _props$as,
      classNameProp = props.className,
      value = props.value,
      onChange = props.onChange,
      children = props.children,
      rest = _objectWithoutProperties(props, ["as", "className", "value", "onChange", "children"]);

  var values = React.useMemo(function () {
    return React.Children.map(children, function (child) {
      return {
        value: child.props.value,
        title: child.props.title
      };
    });
  }, [children]);
  var theChildren = React.useMemo(function () {
    return React.Children.map(children, function (child) {
      return React.cloneElement(child, {
        hidden: child.props.value !== value
      });
    });
  }, [children, value]);
  var classes = useStyles(props);
  var className = (0, _classnames["default"])(classes.root, classNameProp);
  return React.createElement(_Box["default"], _extends({
    className: className,
    ref: ref
  }, rest), React.createElement(_Navigation["default"], _extends({
    horizontal: true,
    value: value,
    onChange: onChange,
    boxShadow: "2"
  }, rest), values.map(function (_ref) {
    var value = _ref.value,
        title = _ref.title;
    return React.createElement(_Item["default"], {
      value: value,
      key: value
    }, title);
  })), React.createElement(_Box["default"], {
    className: classes.panel
  }, theChildren));
});
Object.defineProperty(Tabs, 'Panel', {
  get: function get() {
    return _Panel["default"];
  }
});
Tabs.displayName = "F".concat(name);
Tabs.propTypes = _Tabs2.TabsPropTypes;
var _default = Tabs;
exports["default"] = _default;