"use strict";

exports.__esModule = true;
exports.default = void 0;

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

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

var _meetReactComponentOne = require("@alifd/meet-react-component-one");

var _utils = require("../utils");

var _view = _interopRequireDefault(require("../view"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Item = function (props, ref) {
  var _ref3;

  var _props$disabled = props.disabled,
      disabled = _props$disabled === void 0 ? false : _props$disabled,
      _props$prefix = props.prefix,
      prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix,
      size = props.size,
      last = props.last,
      disabledAll = props.disabledAll,
      _onClick = props.onClick,
      index = props.index,
      count = props.count,
      maxNode = props.maxNode,
      separator = props.separator;

  var renderSeparator = function () {
    var _ref, _ref2;

    return separator ? /*#__PURE__*/(0, _react.createElement)(_view.default, {
      className: (0, _classnames.default)([prefix + "breadcrumb-item-icon-custom", prefix + "breadcrumb-item--font-" + size + "-size", prefix + "breadcrumb-item--margin-" + size + "-size", (_ref = {}, _ref[prefix + "breadcrumb-item--arrow-disabled"] = disabledAll, _ref)])
    }, separator) : /*#__PURE__*/(0, _react.createElement)(_view.default, {
      className: (0, _classnames.default)([prefix + "breadcrumb-item-icon", prefix + "breadcrumb-item--arrow-" + size + "-size", prefix + "breadcrumb-item--margin-" + size + "-size", (_ref2 = {}, _ref2[prefix + "breadcrumb-item--arrow-disabled"] = disabledAll, _ref2)])
    });
  };

  var renderFull = function () {
    var _classNames;

    return /*#__PURE__*/(0, _react.createElement)(_react.Fragment, null, /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.Text, {
      className: (0, _classnames.default)(prefix + "breadcrumb-item--action", (_classNames = {}, _classNames[prefix + "breadcrumb-item--action-disabled"] = disabled || disabledAll, _classNames[prefix + "breadcrumb-item--action-active"] = last, _classNames))
    }, props.children), last ? '' : renderSeparator());
  };

  var shouldHide = count > maxNode && index !== 0 && count - index >= maxNode - 1;

  if (shouldHide && index !== 1) {
    return null;
  }

  return /*#__PURE__*/(0, _react.createElement)(_view.default, {
    ref: ref,
    className: (0, _classnames.default)([prefix + "breadcrumb-item", prefix + "breadcrumb-item--font-" + size + "-size", prefix + "breadcrumb-item--space-" + size + "-size", (_ref3 = {}, _ref3[prefix + "breadcrumb-item--disabled"] = disabled || disabledAll, _ref3)]),
    onClick: function onClick(e) {
      if (disabled || disabledAll) {
        (0, _utils.stopPropagation)(e);
      } else {
        _onClick(index);
      }
    }
  }, function renderItem() {
    if (shouldHide && index === 1) {
      return /*#__PURE__*/(0, _react.createElement)(_react.Fragment, null, /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.Text, null, '...'), last ? '' : renderSeparator());
    }

    return renderFull();
  }());
};

Item.displayName = 'BreadCrumb.Item';

var _default = /*#__PURE__*/(0, _react.forwardRef)(Item);

exports.default = _default;