import _extends from "@babel/runtime/helpers/esm/extends";
import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/esm/taggedTemplateLiteralLoose";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";

function _templateObject2() {
  var data = _taggedTemplateLiteralLoose(["icon-close"]);

  _templateObject2 = function _templateObject2() {
    return data;
  };

  return data;
}

function _templateObject() {
  var data = _taggedTemplateLiteralLoose(["text"]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

import React from 'react';
import PropTypes from 'prop-types';
import { useClassNames } from '../utils';
import CloseButton from '../CloseButton';
var Tag = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var _props$as = props.as,
      Component = _props$as === void 0 ? 'div' : _props$as,
      _props$classPrefix = props.classPrefix,
      classPrefix = _props$classPrefix === void 0 ? 'tag' : _props$classPrefix,
      _props$color = props.color,
      color = _props$color === void 0 ? 'default' : _props$color,
      children = props.children,
      closable = props.closable,
      className = props.className,
      onClose = props.onClose,
      rest = _objectWithoutPropertiesLoose(props, ["as", "classPrefix", "color", "children", "closable", "className", "onClose"]);

  var _useClassNames = useClassNames(classPrefix),
      withClassPrefix = _useClassNames.withClassPrefix,
      prefix = _useClassNames.prefix,
      merge = _useClassNames.merge;

  var classes = merge(className, withClassPrefix(color, {
    closable: closable
  }));
  return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
    ref: ref,
    className: classes
  }), /*#__PURE__*/React.createElement("span", {
    className: prefix(_templateObject())
  }, children), closable && /*#__PURE__*/React.createElement(CloseButton, {
    className: prefix(_templateObject2()),
    onClick: onClose
  }));
});
Tag.displayName = 'Tag';
Tag.propTypes = {
  closable: PropTypes.bool,
  classPrefix: PropTypes.string,
  onClose: PropTypes.func,
  children: PropTypes.node,
  className: PropTypes.string,
  as: PropTypes.elementType
};
export default Tag;