import _extends from "@babel/runtime/helpers/extends";
import React from "react";
import PropTypes from "prop-types";
import Grid from "../../Grid";
import Icon from "../../Icon";
import IconButton from "../../IconButton";
import Badge from "../../Badge";
import Tooltip from "../../Tooltip";
import getClasses from "./styles";

var noop = function noop() {};

var Item = function Item(props) {
  var _props$name = props.name,
      name = _props$name === void 0 ? "" : _props$name,
      icon = props.icon,
      isSelected = props.isSelected,
      badgeActive = props.badgeActive,
      _props$onClick = props.onClick,
      onClick = _props$onClick === void 0 ? noop : _props$onClick,
      _props$tooltip = props.tooltip,
      tooltip = _props$tooltip === void 0 ? true : _props$tooltip,
      color = props.color;
  var iconNormalized = typeof icon === "string" ? /*#__PURE__*/React.createElement(Icon, {
    icon: icon
  }) : icon;
  var iconWithBadge = badgeActive ? /*#__PURE__*/React.createElement(Badge, {
    variant: "dot",
    invisible: false,
    color: "danger"
  }, " ", iconNormalized, " ") : iconNormalized;

  if (tooltip) {
    return /*#__PURE__*/React.createElement(Tooltip, {
      title: name
    }, /*#__PURE__*/React.createElement(IconButton, {
      onClick: onClick,
      color: color,
      active: isSelected,
      icon: iconWithBadge
    }));
  }

  return /*#__PURE__*/React.createElement(IconButton, {
    onClick: onClick,
    color: color,
    active: isSelected,
    icon: iconWithBadge
  });
};

var FooterActions = function FooterActions(props) {
  var items = props.items,
      color = props.color,
      isSidebarCollapsed = props.isSidebarCollapsed;
  var classes = getClasses();
  return /*#__PURE__*/React.createElement(React.Fragment, null, items.length > 0 && /*#__PURE__*/React.createElement("div", {
    id: "footer-actions",
    className: classes.root
  }, /*#__PURE__*/React.createElement(Grid, {
    container: true,
    className: isSidebarCollapsed ? classes.actionsList : ""
  }, items.map(function (action) {
    return /*#__PURE__*/React.createElement(Grid, {
      item: true,
      className: isSidebarCollapsed ? classes.iconButtonVertical : "",
      key: action.name
    }, /*#__PURE__*/React.createElement(Item, _extends({
      color: color
    }, action)));
  }))));
};

FooterActions.propTypes = {
  items: PropTypes.arrayOf(PropTypes.shape({
    name: PropTypes.string,
    icon: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
    isSelected: PropTypes.bool,
    badgeActive: PropTypes.bool,
    onClick: PropTypes.func,
    tooltip: PropTypes.bool,
    color: PropTypes.string
  })),
  color: PropTypes.string,
  isSidebarCollapsed: PropTypes.bool
};
FooterActions.defaultProps = {
  items: [],
  color: "primary",
  isSidebarCollapsed: false
};
export default FooterActions;