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 classNames from 'classnames';
import React, { createElement, forwardRef, Fragment } from "react";
import { Text } from "@alifd/meet-react-component-one";
import { stopPropagation } from '../utils';
import View from '../view';

var Item = function Item(props, ref) {
  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 renderSeparator() {
    return separator ? /*#__PURE__*/React.createElement(View, {
      className: classNames(["".concat(prefix, "breadcrumb-item-icon-custom"), "".concat(prefix, "breadcrumb-item--font-").concat(size, "-size"), "".concat(prefix, "breadcrumb-item--margin-").concat(size, "-size"), _defineProperty({}, "".concat(prefix, "breadcrumb-item--arrow-disabled"), disabledAll)])
    }, separator) : /*#__PURE__*/React.createElement(View, {
      className: classNames(["".concat(prefix, "breadcrumb-item-icon"), "".concat(prefix, "breadcrumb-item--arrow-").concat(size, "-size"), "".concat(prefix, "breadcrumb-item--margin-").concat(size, "-size"), _defineProperty({}, "".concat(prefix, "breadcrumb-item--arrow-disabled"), disabledAll)])
    });
  };

  var renderFull = function renderFull() {
    var _classNames;

    return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Text, {
      className: classNames("".concat(prefix, "breadcrumb-item--action"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "breadcrumb-item--action-disabled"), disabled || disabledAll), _defineProperty(_classNames, "".concat(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;
  }

  var renderItem = function renderItem() {
    if (shouldHide && index === 1) {
      return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Text, null, '...'), last ? '' : renderSeparator());
    }

    return renderFull();
  };

  return /*#__PURE__*/React.createElement(View, {
    ref: ref,
    className: classNames(["".concat(prefix, "breadcrumb-item"), "".concat(prefix, "breadcrumb-item--font-").concat(size, "-size"), "".concat(prefix, "breadcrumb-item--space-").concat(size, "-size"), _defineProperty({}, "".concat(prefix, "breadcrumb-item--disabled"), disabled || disabledAll)]),
    onClick: function onClick(e) {
      if (disabled || disabledAll) {
        stopPropagation(e);
      } else {
        _onClick(index);
      }
    }
  }, renderItem());
};

Item.displayName = 'BreadCrumb.Item';
export default /*#__PURE__*/forwardRef(Item);