"use strict";

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

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

var _getCompliedClassName4 = _interopRequireDefault(require("../../utils/getCompliedClassName"));

var _Group = _interopRequireDefault(require("../group/Group"));

var _BreadCrumbItem = _interopRequireDefault(require("./BreadCrumbItem"));

var _BreadCrumbsModule = _interopRequireDefault(require("./BreadCrumbs.module.css"));

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

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

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; }

function BreadCrumbsSkeleton(props) {
  var _getCompliedClassName3;

  var children = props.children,
      customId = props.customId,
      seperator = props.seperator,
      items = props.items,
      onSelect = props.onSelect,
      active = props.active,
      customClassName = props.customClassName,
      visited = props.visited,
      isFrontSeperator = props.isFrontSeperator,
      size = props.size,
      isEllipsis = props.isEllipsis,
      iscollapse = props.iscollapse,
      onCollapse = props.onCollapse,
      maxItems = props.maxItems,
      direction = props.direction,
      align = props.align,
      ariaLabel = props.ariaLabel,
      role = props.role,
      tabIndex = props.tabIndex,
      tagAttributeProps = props.tagAttributeProps;
  var displayItems = [],
      dI = [];
  var classes = (0, _getCompliedClassName4["default"])(customClassName, _defineProperty({}, _BreadCrumbsModule["default"].base, true));
  var list = (0, _getCompliedClassName4["default"])(customClassName, _defineProperty({}, _BreadCrumbsModule["default"].flex, true), (_getCompliedClassName3 = {}, _defineProperty(_getCompliedClassName3, customClassName.alignment, customClassName.alignment), _defineProperty(_getCompliedClassName3, customClassName.wrap, customClassName.wrap), _getCompliedClassName3));

  if (children) {
    _react["default"].Children.toArray(children).map(function (child, index) {
      if (index <= visited) {
        if (child && child.type === _BreadCrumbItem["default"]) {
          child && displayItems.push( /*#__PURE__*/_react["default"].cloneElement(child, {
            active: index == active ? true : false,
            key: index,
            onClick: onSelect,
            itemIndex: index,
            size: size,
            isEllipsis: isEllipsis,
            customDataId: customId.item ? "".concat(customId.item, "_{id}") : ""
          }));
        } else {
          child && displayItems.push( /*#__PURE__*/_react["default"].cloneElement(child, {
            key: index
          }));
        }
      }
    });
  } else if (items.length > 0) {
    items.map(function (child, index) {
      if (index <= visited) {
        displayItems.push( /*#__PURE__*/_react["default"].createElement(_BreadCrumbItem["default"], {
          key: index,
          active: index == active ? true : false,
          onClick: onSelect,
          text: child.text,
          itemIndex: index,
          href: child.url,
          itemId: index + 1,
          dataId: customId + index,
          size: size,
          isEllipsis: isEllipsis
        }));
      }
    });
  }

  if (iscollapse) {
    dI.push(displayItems[0]);

    if (maxItems > 1 && maxItems < displayItems.length - 1) {
      for (var index = displayItems.length - 1; index > displayItems.length - maxItems; index--) {
        var element = displayItems[index];
        dI.splice(1, 0, element);
      }
    }

    dI.splice(1, 0, /*#__PURE__*/_react["default"].createElement(_BreadCrumbItem["default"], {
      text: "...",
      onClick: onCollapse,
      dataId: customId
    }));
  }

  return /*#__PURE__*/_react["default"].createElement("nav", _extends({
    "aria-label": ariaLabel,
    className: classes,
    tabIndex: tabIndex,
    role: role
  }, tagAttributeProps), /*#__PURE__*/_react["default"].createElement(_Group["default"], {
    tagName: "ol",
    seperator: seperator,
    isFrontSeperator: isFrontSeperator,
    seperatorTagName: "li",
    direction: direction,
    align: align
  }, iscollapse ? dI : displayItems));
}