import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React, { useContext } from 'react';
import { ConfigContext } from '../config-provider/context';
import Dropdown from '../dropdown';
import Icon from '../icon'; // import classNames from 'classnames';

var DownLine = Icon.DownLine;

var BreadcrumbItem = function BreadcrumbItem(_ref) {
  var _ref$separator = _ref.separator,
      separator = _ref$separator === void 0 ? '/' : _ref$separator,
      children = _ref.children,
      overlay = _ref.overlay,
      dropdownProps = _ref.dropdownProps,
      restProps = _objectWithoutProperties(_ref, ["separator", "children", "overlay", "dropdownProps"]);

  var _useContext = useContext(ConfigContext),
      getPrefixClassName = _useContext.getPrefixClassName;

  var prefixCls = getPrefixClassName('bread-crumb');

  var renderBreadcrumbNode = function renderBreadcrumbNode(breadcrumbItem) {
    if (overlay) {
      return /*#__PURE__*/React.createElement(Dropdown, Object.assign({
        overlay: overlay,
        placement: "bottomCenter"
      }, dropdownProps), /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-overlay-link")
      }, breadcrumbItem, /*#__PURE__*/React.createElement(DownLine, {
        style: {
          marginLeft: 4
        }
      })));
    }

    return breadcrumbItem;
  };

  var link;

  if ('href' in restProps) {
    link = /*#__PURE__*/React.createElement("a", Object.assign({
      className: "".concat(prefixCls, "-link")
    }, restProps), children);
  } else {
    link = /*#__PURE__*/React.createElement("span", Object.assign({
      className: "".concat(prefixCls, "-link")
    }, restProps), children);
  } // wrap to dropDown


  link = renderBreadcrumbNode(link);

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

  return null;
}; // BreadcrumbItem._klein_BREADCRUMB_ITEM = true;


export default BreadcrumbItem;