"use strict";

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

var _tslib = require("tslib");

var _consoleComponents = require("@alicloud/console-components");

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

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

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

;

function mapBreadcrumbItem(item, index, push) {
  var link = item.link,
      name = item.name,
      disabled = item.disabled,
      className = item.className,
      rest = (0, _tslib.__rest)(item, ["link", "name", "disabled", "className"]);
  var className_ = className ? (0, _classnames["default"])(className, "lp-breadcrumb-item") : "lp-breadcrumb-item";

  if (push && typeof push === 'function') {
    return /*#__PURE__*/_react["default"].createElement(_consoleComponents.Breadcrumb.Item, (0, _tslib.__assign)({
      key: index,
      className: className_,
      onClick: function onClick() {
        link && push(link);
      }
    }, rest), name);
  } else {
    return /*#__PURE__*/_react["default"].createElement(_consoleComponents.Breadcrumb.Item, (0, _tslib.__assign)({
      key: index,
      link: link,
      className: className_
    }, rest), name);
  }
}

var IotBreadcrumb = function IotBreadcrumb(props) {
  var hasLine = props.hasLine,
      className = props.className,
      dataSource = props.dataSource,
      extra = props.extra,
      push = props.push,
      children = props.children,
      rest = (0, _tslib.__rest)(props, ["hasLine", "className", "dataSource", "extra", "push", "children"]);
  var wrapperClass = (0, _classnames["default"])('lp-breadcrumb', {
    'lp-breadcrumb-line': hasLine
  });
  var breadcrumbClass = (0, _classnames["default"])(className, {
    'lp-breadcrumb-single': dataSource && dataSource.length === 1
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: wrapperClass,
    style: props.style
  }, /*#__PURE__*/_react["default"].createElement(_consoleComponents.Breadcrumb, (0, _tslib.__assign)({
    className: breadcrumbClass
  }, rest), children ? _react["default"].Children.map(children, function (child) {
    var className_ = child.props.className ? (0, _classnames["default"])(child.props.className, "lp-breadcrumb-item") : "lp-breadcrumb-item";
    return /*#__PURE__*/_react["default"].cloneElement(child, {
      className: className_
    });
  }) : dataSource && dataSource.map(function (item, index) {
    return mapBreadcrumbItem(item, index, push);
  })), extra);
};

IotBreadcrumb.defaultProps = {
  separator: /*#__PURE__*/_react["default"].createElement(_consoleComponents.Icon, {
    size: "xs",
    type: "arrow-right"
  })
};
IotBreadcrumb.Item = _consoleComponents.Breadcrumb.Item;
var _default = IotBreadcrumb;
exports["default"] = _default;