import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["className", "size", "label", "color", "onDelete", "loading", "variant", "icon"];
import React from "react";
import PropTypes from "prop-types";
import classnames from "classnames";
import { getColorsLabels } from "../styles/colors";
import Typography from "../Typography";
import Flex from "../CssFlex";
import Loading from "../Loading";
import IconButton from "./ChipIconButton";
import Icon from "../Icon";
import CircleTimes from "../Icon/CircleTimes";
import getClasses from "./styles";
var colorsList = getColorsLabels(true);

var ChipIcon = function ChipIcon(_ref) {
  var onClick = _ref.onClick,
      icon = _ref.icon,
      color = _ref.color;
  if (!onClick) return null;
  return /*#__PURE__*/React.createElement(IconButton, {
    onClick: onClick,
    color: color,
    icon: typeof icon === "string" ? /*#__PURE__*/React.createElement(Icon, {
      icon: icon
    }) : icon
  });
};

var Chip = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var _classnames;

  var className = props.className,
      size = props.size,
      label = props.label,
      color = props.color,
      onDelete = props.onDelete,
      loading = props.loading,
      variant = props.variant,
      icon = props.icon,
      htmlProps = _objectWithoutProperties(props, _excluded);

  var classes = getClasses({
    color: color
  });
  var rootClassName = classnames(classes.root, className, (_classnames = {}, _defineProperty(_classnames, classes.outlined, variant === "outlined"), _defineProperty(_classnames, classes.extraSmall, size === "extraSmall"), _classnames));
  return /*#__PURE__*/React.createElement(Flex, _extends({
    ref: ref,
    alignItems: "center",
    gap: "sm",
    className: rootClassName
  }, htmlProps), /*#__PURE__*/React.createElement(Typography, {
    variant: "small",
    color: color
  }, label), loading ? /*#__PURE__*/React.createElement(Loading, {
    className: classes.loading
  }) : /*#__PURE__*/React.createElement(ChipIcon, {
    onClick: onDelete,
    className: classes.deleteIcon,
    color: color,
    icon: icon
  }));
});
Chip.propTypes = {
  variant: PropTypes.oneOf(["contained", "outlined"]),
  className: PropTypes.string,
  label: PropTypes.string.isRequired,
  color: PropTypes.oneOf(colorsList),
  size: PropTypes.oneOf(["extraSmall", "small", "medium"]),
  onDelete: PropTypes.func,
  loading: PropTypes.bool,
  icon: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
};
Chip.defaultProps = {
  className: "",
  variant: "contained",
  color: "primary",
  size: "medium",
  loading: false,
  icon: /*#__PURE__*/React.createElement(CircleTimes, null)
};
export default Chip;