import _extends from "@babel/runtime/helpers/extends";
import "core-js/modules/es.array.map.js";
import "core-js/modules/es.string.link.js";
import * as React from 'react';
import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
import useResolutions from "../../hooks/useResolutions";
import BreadcrumbsItem from "./components/BreadcrumbsItem";
import "./Breadcrumbs.css";
var isObjectElement = function isObjectElement(item) {
  return ! /*#__PURE__*/React.isValidElement(item);
};
var cn = cnCreate('mfui-breadcrumbs');
var Breadcrumbs = function Breadcrumbs(_ref) {
  var items = _ref.items,
    _ref$color = _ref.color,
    color = _ref$color === void 0 ? 'default' : _ref$color,
    className = _ref.className,
    _ref$classes = _ref.classes,
    classes = _ref$classes === void 0 ? {} : _ref$classes,
    dataAttrs = _ref.dataAttrs,
    _ref$hasMicrodata = _ref.hasMicrodata,
    hasMicrodata = _ref$hasMicrodata === void 0 ? false : _ref$hasMicrodata,
    _ref$hasMicrodataForL = _ref.hasMicrodataForLastItem,
    hasMicrodataForLastItem = _ref$hasMicrodataForL === void 0 ? false : _ref$hasMicrodataForL,
    _ref$disabledOnMobile = _ref.disabledOnMobile,
    disabledOnMobile = _ref$disabledOnMobile === void 0 ? false : _ref$disabledOnMobile,
    _ref$hasMarginTop = _ref.hasMarginTop,
    hasMarginTop = _ref$hasMarginTop === void 0 ? false : _ref$hasMarginTop;
  var _useResolutions = useResolutions(),
    isMobile = _useResolutions.isMobile;
  if (isMobile && disabledOnMobile) {
    return null;
  }
  return /*#__PURE__*/React.createElement("div", _extends({
    className: cn({
      color: color,
      'margin-top': hasMarginTop
    }, className)
  }, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), hasMicrodata && {
    itemScope: true,
    itemType: 'https://schema.org/BreadcrumbList'
  }), items.map(function (item, i) {
    return /*#__PURE__*/React.createElement("div", _extends({
      className: cn('item', classes.item)
    }, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.item, i + 1), {
      key: i
    }), isObjectElement(item) ? /*#__PURE__*/React.createElement(BreadcrumbsItem, {
      title: item.title,
      href: item.href,
      color: color,
      index: i,
      isLastItem: i === items.length - 1,
      hasMicrodata: hasMicrodata,
      hasMicrodataForLastItem: hasMicrodataForLastItem,
      dataAttrs: {
        root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.itemInner,
        link: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.link,
        itemTitle: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.itemTitle,
        meta: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.itemMeta
      },
      classes: {
        link: classes === null || classes === void 0 ? void 0 : classes.link,
        itemTitle: classes === null || classes === void 0 ? void 0 : classes.itemTitle,
        lastItemTitle: classes === null || classes === void 0 ? void 0 : classes.lastItemTitle
      }
    }) : item);
  }));
};
export default Breadcrumbs;