import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["className", "icon", "color", "component"];
import React from "react";
import cx from "classnames";
import createComponent from "../../system/createComponent";
import PropTypes from "prop-types";
import { Color } from "./IconButtonProps";
import ButtonBase from "./../ButtonBase";
import getClasses from "./styles";
var IconButton = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var _buttonClasses;

  var classes = getClasses();

  var className = props.className,
      icon = props.icon,
      color = props.color,
      component = props.component,
      restProps = _objectWithoutProperties(props, _excluded);

  var buttonClasses = (_buttonClasses = {}, _defineProperty(_buttonClasses, classes.root, true), _defineProperty(_buttonClasses, classes.primaryColor, color === Color.primary), _defineProperty(_buttonClasses, classes.dangerColor, color === Color.danger), _buttonClasses);
  var ButtonRoot = component || ButtonBase;
  return /*#__PURE__*/React.createElement(ButtonRoot, _extends({
    ref: ref,
    className: cx(buttonClasses, className)
  }, restProps), /*#__PURE__*/React.cloneElement(icon, {
    color: "currentColor"
  }));
}); // @ts-ignore

IconButton.propTypes = {
  icon: PropTypes.element.isRequired,
  component: PropTypes.elementType,
  color: PropTypes.oneOf(["primary", "neutral", "danger"]),
  disabled: PropTypes.bool,
  href: PropTypes.string,
  target: PropTypes.string,
  onClick: PropTypes.func,
  type: PropTypes.oneOf(["button", "reset", "submit"]),
  sx: PropTypes.object
}; // @ts-ignore

IconButton.defaultProps = {
  type: "button"
};

if (process.env.NODE_ENV !== "production") {
  // @ts-ignore
  IconButton.displayName = "NextIconButton";
}

export default createComponent(IconButton);