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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

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

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

import React, { Component, Children } from 'react';
import PropTypes from 'prop-types';
import Icon from '../icon';
import Menu from '../menu';
import ConfigProvider from '../config-provider';
import Item from './item';
import Overlay from '../overlay';
var Popup = Overlay.Popup;
/**
 * Breadcrumb
 */

var Breadcrumb =
/*#__PURE__*/
function (_Component) {
  _inherits(Breadcrumb, _Component);

  function Breadcrumb() {
    _classCallCheck(this, Breadcrumb);

    return _possibleConstructorReturn(this, _getPrototypeOf(Breadcrumb).apply(this, arguments));
  }

  _createClass(Breadcrumb, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          prefix = _this$props.prefix,
          rtl = _this$props.rtl,
          className = _this$props.className,
          maxNode = _this$props.maxNode,
          children = _this$props.children,
          separator = _this$props.separator,
          component = _this$props.component,
          others = _objectWithoutProperties(_this$props, ["prefix", "rtl", "className", "maxNode", "children", "separator", "component"]); // const clazz = classNames(``, className);


      var items;
      var menuItems = [];
      var length = Children.count(children);

      if (maxNode > 1 && length > maxNode) {
        var breakpointer = length - 3;
        items = []; // 用 for 循环替代 forEach，可以用 continue

        for (var i = 0; i < length; i++) {
          var ariaProps = {};
          var item = children[i];

          if (i === length - 1) {
            // push 最后一项，不带 separator
            ariaProps['aria-current'] = 'page';
            items.push(React.cloneElement(item, _objectSpread({
              prefix: prefix,
              key: i
            }, ariaProps, {
              className: "".concat(prefix, "breadcrumb-menu-item"),
              activated: i === length - 1
            })));
          }

          if (i === 0) {
            items.push( // push 第一项
            React.cloneElement(item, _objectSpread({
              prefix: prefix,
              separator: separator,
              key: i
            }, ariaProps)));
            continue;
          }

          if (i === breakpointer) {
            // 把当前项存进去
            menuItems.push(React.cloneElement(item, _objectSpread({
              key: i
            }, ariaProps))); // push ...

            /* eslint no-script-url: 1 */

            items.push(React.cloneElement(item, _objectSpread({
              separator: separator,
              prefix: prefix,
              key: i,
              href: 'javascript:;',
              // 不跳转
              activated: i === length - 1
            }, ariaProps, {
              className: "".concat(prefix, "breadcrumb-show-more")
            }), React.createElement(Popup, {
              trigger: React.createElement(Icon, {
                type: "more"
              }),
              triggerType: "click",
              align: "tc bl",
              offset: [0, 4]
            }, React.createElement(Menu, null, menuItems.map(function (menuItem, key) {
              if (menuItem.props.link) {
                return React.createElement(Menu.Item, _extends({
                  key: key
                }, menuItem.props), React.createElement("a", {
                  href: menuItem.props.link
                }, menuItem.props.children));
              } else {
                return React.createElement(Menu.Item, _extends({
                  key: key
                }, menuItem.props), menuItem.props.children);
              }
            })))));
          } else if (i === length - 2) {
            // push 倒数第二项
            items.push(React.cloneElement(item, _objectSpread({
              separator: separator,
              prefix: prefix,
              key: i
            }, ariaProps)));
          } else {
            // push 到 menuItems 里面
            menuItems.push(React.cloneElement(item, _objectSpread({
              key: i
            }, ariaProps)));
          }
        }
      } else {
        items = Children.map(children, function (item, i) {
          var ariaProps = {};

          if (i === length - 1) {
            ariaProps['aria-current'] = 'page';
          }

          return React.cloneElement(item, _objectSpread({
            separator: separator,
            prefix: prefix,
            activated: i === length - 1
          }, ariaProps, {
            key: i
          }));
        });
      }

      if (rtl) {
        others.dir = 'rtl';
      }

      var BreadcrumbComponent = component;
      return React.createElement(BreadcrumbComponent, _extends({
        "aria-label": "Breadcrumb",
        className: className
      }, others), React.createElement("ul", {
        className: "".concat(prefix, "breadcrumb")
      }, items));
    }
  }]);

  return Breadcrumb;
}(Component);

_defineProperty(Breadcrumb, "Item", Item);

_defineProperty(Breadcrumb, "propTypes", {
  /**
   * 样式类名的品牌前缀
   */
  prefix: PropTypes.string,
  rtl: PropTypes.bool,

  /*eslint-disable*/

  /**
   * 面包屑子节点，需传入 Breadcrumb.Item
   */
  children: function children(props, propName) {
    Children.forEach(props[propName], function (child) {
      if (!(child && typeof child.type === 'function' && child.type._typeMark === 'breadcrumb_item')) {
        throw new Error("Breadcrumb's children must be Breadcrumb.Item!");
      }
    });
  },

  /* eslint-enable */

  /**
   * 面包屑最多显示个数，超出部分会被隐藏
   */
  maxNode: PropTypes.number,

  /**
   * 分隔符，可以是文本或 Icon
   */
  separator: PropTypes.node,

  /**
   * 设置标签类型
   */
  component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
  className: PropTypes.any
});

_defineProperty(Breadcrumb, "defaultProps", {
  prefix: 'next-',
  maxNode: 4,
  separator: React.createElement(Icon, {
    type: "chevron-right-s"
  }),
  component: 'nav'
});

export default ConfigProvider.config(Breadcrumb);