"use strict";

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _configProvider = _interopRequireDefault(require("../config-provider"));

var _menu = _interopRequireDefault(require("../menu"));

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; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; 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 _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

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; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * Nav
 * @description 继承自 `Menu` 的能力请查看 `Menu` 文档
 */
var Nav =
/*#__PURE__*/
function (_Component) {
  _inherits(Nav, _Component);

  function Nav() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, Nav);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Nav)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_this), "getMenuRef", function (ref) {
      _this.menu = ref;
    });

    return _this;
  }

  _createClass(Nav, [{
    key: "getChildContext",
    value: function getChildContext() {
      var _this$props = this.props,
          prefix = _this$props.prefix,
          direction = _this$props.direction,
          mode = _this$props.mode,
          iconOnly = _this$props.iconOnly,
          hasTooltip = _this$props.hasTooltip,
          hasArrow = _this$props.hasArrow;
      return {
        prefix: prefix,
        mode: direction === 'hoz' ? 'popup' : mode,
        iconOnly: iconOnly,
        hasTooltip: hasTooltip,
        hasArrow: hasArrow
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _classNames, _classNames2;

      // eslint-disable-next-line
      var _this$props2 = this.props,
          prefix = _this$props2.prefix,
          className = _this$props2.className,
          style = _this$props2.style,
          children = _this$props2.children,
          type = _this$props2.type,
          direction = _this$props2.direction,
          activeDirection = _this$props2.activeDirection,
          mode = _this$props2.mode,
          triggerType = _this$props2.triggerType,
          inlineIndent = _this$props2.inlineIndent,
          openMode = _this$props2.openMode,
          popupAlign = _this$props2.popupAlign,
          popupClassName = _this$props2.popupClassName,
          iconOnly = _this$props2.iconOnly,
          hasArrow = _this$props2.hasArrow,
          noBg = _this$props2.noBg,
          hasTooltip = _this$props2.hasTooltip,
          embeddable = _this$props2.embeddable,
          _popupProps = _this$props2.popupProps,
          rtl = _this$props2.rtl,
          others = _objectWithoutProperties(_this$props2, ["prefix", "className", "style", "children", "type", "direction", "activeDirection", "mode", "triggerType", "inlineIndent", "openMode", "popupAlign", "popupClassName", "iconOnly", "hasArrow", "noBg", "hasTooltip", "embeddable", "popupProps", "rtl"]);

      var realActiveDirection = activeDirection;

      if (realActiveDirection && (direction === 'hoz' && (realActiveDirection === 'left' || realActiveDirection === 'right') || direction === 'ver' && (realActiveDirection === 'top' || realActiveDirection === 'bottom'))) {
        realActiveDirection = null;
      }

      if (!iconOnly && realActiveDirection === undefined) {
        realActiveDirection = direction === 'hoz' ? 'bottom' : type === 'line' ? 'right' : 'left';
      }

      var cls = (0, _classnames["default"])((_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "nav"), true), _defineProperty(_classNames, "".concat(prefix).concat(type), type), _defineProperty(_classNames, "".concat(prefix, "active"), realActiveDirection), _defineProperty(_classNames, "".concat(prefix).concat(realActiveDirection), realActiveDirection), _defineProperty(_classNames, "".concat(prefix, "icon-only"), iconOnly), _defineProperty(_classNames, "".concat(prefix, "no-arrow"), !hasArrow), _defineProperty(_classNames, "".concat(prefix, "no-bg"), noBg), _defineProperty(_classNames, "".concat(prefix, "nav-embeddable"), embeddable), _defineProperty(_classNames, className, !!className), _classNames));
      var newStyle = iconOnly ? _objectSpread({}, style, {
        width: '60px'
      }) : style;
      var props = {
        prefix: prefix,
        direction: direction,
        openMode: openMode,
        triggerType: triggerType,
        mode: direction === 'hoz' ? 'popup' : mode,
        popupAlign: direction === 'hoz' ? 'follow' : popupAlign,
        inlineIndent: iconOnly ? 0 : inlineIndent,
        hasSelectedIcon: false,
        popupAutoWidth: true,
        selectMode: 'single',
        itemClassName: "".concat(prefix, "nav-item"),
        popupClassName: (0, _classnames["default"])((_classNames2 = {}, _defineProperty(_classNames2, cls.replace("".concat(prefix, "icon-only"), '').replace("".concat(prefix, "nav-embeddable"), ''), mode === 'popup'), _defineProperty(_classNames2, "".concat(prefix, "icon-only"), iconOnly && mode === 'inline'), _defineProperty(_classNames2, popupClassName, !!popupClassName), _classNames2)),
        popupProps: function popupProps(popupItemProps) {
          return _objectSpread({
            offset: direction === 'hoz' && popupItemProps.level === 1 ? [0, 2] : [-2, 0]
          }, _popupProps);
        }
      };
      return _react["default"].createElement(_menu["default"], _extends({
        className: cls,
        style: newStyle
      }, props, others, {
        ref: this.getMenuRef
      }), children);
    }
  }]);

  return Nav;
}(_react.Component);

_defineProperty(Nav, "propTypes", {
  prefix: _propTypes["default"].string,
  pure: _propTypes["default"].bool,
  rtl: _propTypes["default"].bool,
  className: _propTypes["default"].string,
  style: _propTypes["default"].object,

  /**
   * 导航项和子导航
   */
  children: _propTypes["default"].node,

  /**
   * 导航类型
   * @enumdesc 普通, 主要, 次要, 线形
   */
  type: _propTypes["default"].oneOf(['normal', 'primary', 'secondary', 'line']),

  /**
   * 导航布局
   * @enumdesc 水平, 垂直
   */
  direction: _propTypes["default"].oneOf(['hoz', 'ver']),

  /**
   * 横向导航条 items 和 footer 的对齐方向，在 direction 设置为 'hoz' 并且 header 存在时生效
   */
  hozAlign: _propTypes["default"].oneOf(['left', 'right']),

  /**
   * 设置组件选中状态的 active 边方向
   * @enumdesc 无, 上, 下, 左, 右
   * @default 当 direction 为 'hoz' 时，默认值为 'bottom'，当 direction 为 'ver' 时，默认值为 'left'
   */
  activeDirection: _propTypes["default"].oneOf([null, 'top', 'bottom', 'left', 'right']),

  /**
   * 子导航打开的模式（水平导航只支持弹出）
   * @eumdesc 行内, 弹出
   */
  mode: _propTypes["default"].oneOf(['inline', 'popup']),

  /**
   * 子导航打开的触发方式
   */
  triggerType: _propTypes["default"].oneOf(['click', 'hover']),

  /**
   * 内联子导航缩进距离
   */
  inlineIndent: _propTypes["default"].number,

  /**
   * 初始展开所有的子导航，只在 mode 设置为 'inline' 以及 openMode 设置为 'multiple' 下生效
   */
  defaultOpenAll: _propTypes["default"].bool,

  /**
   * 内联子导航的展开模式，同时可以展开一个同级子导航还是多个同级子导航，该属性仅在 mode 为 inline 时生效
   * @eumdesc 一个, 多个
   */
  openMode: _propTypes["default"].oneOf(['single', 'multiple']),

  /**
   * 当前选中导航项的 key 值
   */
  selectedKeys: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].array]),

  /**
   * 初始选中导航项的 key 值
   */
  defaultSelectedKeys: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].array]),

  /**
   * 选中或取消选中导航项触发的回调函数
   * @param {Array} selectedKeys 选中的所有导航项的 key
   * @param {Object} item 选中或取消选中的导航项
   * @param {Object} extra 额外参数
   * @param {Boolean} extra.select 是否是选中
   * @param {Array} extra.key 导航项的 key
   * @param {Object} extra.label 导航项的文本
   * @param {Array} extra.keyPath 导航项 key 的路径
   */
  onSelect: _propTypes["default"].func,

  /**
   * 弹出子导航的对齐方式（水平导航只支持 follow ）
   * @eumdesc Item 顶端对齐, Nav 顶端对齐
   */
  popupAlign: _propTypes["default"].oneOf(['follow', 'outside']),

  /**
   * 弹出子导航的自定义类名
   */
  popupClassName: _propTypes["default"].string,

  /**
   * 是否只显示图标
   */
  iconOnly: _propTypes["default"].bool,

  /**
   * 是否显示右侧的箭头（仅在 iconOnly=true 时生效）
   */
  hasArrow: _propTypes["default"].bool,

  /**
   * 选中是否显示背景色
   */
  noBg: _propTypes["default"].bool,

  /**
   * 是否有 ToolTips （仅在 iconOnly=true 时生效）
   */
  hasTooltip: _propTypes["default"].bool,

  /**
   * 自定义导航头部
   */
  header: _propTypes["default"].node,

  /**
   * 自定义导航尾部
   */
  footer: _propTypes["default"].node,

  /**
   * 是否开启嵌入式模式，一般用于Layout的布局中，开启后没有默认背景、外层border、box-shadow，可以配合`<Nav style={{lineHeight: '100px'}}>` 自定义高度
   */
  embeddable: _propTypes["default"].bool,
  popupProps: _propTypes["default"].object
});

_defineProperty(Nav, "defaultProps", {
  prefix: 'next-',
  pure: false,
  type: 'normal',
  direction: 'ver',
  hozAlign: 'left',
  mode: 'inline',
  triggerType: 'click',
  inlineIndent: 20,
  defaultOpenAll: false,
  openMode: 'multiple',
  defaultSelectedKeys: [],
  popupAlign: 'follow',
  hasTooltip: false,
  embeddable: false,
  hasArrow: true,
  noBg: false,
  popupProps: {}
});

_defineProperty(Nav, "childContextTypes", {
  prefix: _propTypes["default"].string,
  mode: _propTypes["default"].string,
  iconOnly: _propTypes["default"].bool,
  hasTooltip: _propTypes["default"].bool,
  hasArrow: _propTypes["default"].bool,
  noBg: _propTypes["default"].bool
});

var _default = _configProvider["default"].config(Nav);

exports["default"] = _default;