import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";

var __rest = this && this.__rest || function (s, e) {
  var t = {};

  for (var p in s) {
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  }

  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
    if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  }
  return t;
};

import * as React from 'react';
import DownOutlined from '@ant-design/icons/DownOutlined';
import omit from 'omit.js';
import DropDown from '../dropdown/dropdown';
import { ConfigConsumer } from '../config-provider';

var BreadcrumbItem = /*#__PURE__*/function (_React$Component) {
  _inherits(BreadcrumbItem, _React$Component);

  var _super = _createSuper(BreadcrumbItem);

  function BreadcrumbItem() {
    var _this;

    _classCallCheck(this, BreadcrumbItem);

    _this = _super.apply(this, arguments);

    _this.renderBreadcrumbItem = function (_ref) {
      var getPrefixCls = _ref.getPrefixCls;

      var _a = _this.props,
          customizePrefixCls = _a.prefixCls,
          separator = _a.separator,
          children = _a.children,
          restProps = __rest(_a, ["prefixCls", "separator", "children"]);

      var prefixCls = getPrefixCls('breadcrumb', customizePrefixCls);
      var link;

      if ('href' in _this.props) {
        link = /*#__PURE__*/React.createElement("a", _extends({
          className: "".concat(prefixCls, "-link")
        }, omit(restProps, ['overlay'])), children);
      } else {
        link = /*#__PURE__*/React.createElement("span", _extends({
          className: "".concat(prefixCls, "-link")
        }, omit(restProps, ['overlay'])), children);
      } // wrap to dropDown


      link = _this.renderBreadcrumbNode(link, prefixCls);

      if (children) {
        return /*#__PURE__*/React.createElement("span", null, link, separator && separator !== '' && /*#__PURE__*/React.createElement("span", {
          className: "".concat(prefixCls, "-separator")
        }, separator));
      }

      return null;
    };
    /**
     * if overlay is have
     * Wrap a DropDown
     */


    _this.renderBreadcrumbNode = function (breadcrumbItem, prefixCls) {
      var _this$props = _this.props,
          overlay = _this$props.overlay,
          dropdownProps = _this$props.dropdownProps;

      if (overlay) {
        return /*#__PURE__*/React.createElement(DropDown, _extends({
          overlay: overlay,
          placement: "bottomCenter"
        }, dropdownProps), /*#__PURE__*/React.createElement("span", {
          className: "".concat(prefixCls, "-overlay-link")
        }, breadcrumbItem, /*#__PURE__*/React.createElement(DownOutlined, null)));
      }

      return breadcrumbItem;
    };

    return _this;
  }

  _createClass(BreadcrumbItem, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/React.createElement(ConfigConsumer, null, this.renderBreadcrumbItem);
    }
  }]);

  return BreadcrumbItem;
}(React.Component);

export { BreadcrumbItem as default };
BreadcrumbItem.__ANT_BREADCRUMB_ITEM = true;
BreadcrumbItem.defaultProps = {
  separator: '/'
};