import _extends from"babel-runtime/helpers/extends";import _defineProperty from"babel-runtime/helpers/defineProperty";import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";var __rest=this&&this.__rest||function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(o=Object.getOwnPropertySymbols(e);s<o.length;s++)t.indexOf(o[s])<0&&(r[o[s]]=e[o[s]])}return r};import*as React from"react";import*as ReactDOM from"react-dom";import Animate from"rc-animate";import classNames from"classnames";import omit from"omit.js";import Icon from"../icon";import CheckableTag from"./CheckableTag";var Tag=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.close=function(e){var t=r.props.onClose;if(t&&t(e),!e.defaultPrevented){var o=ReactDOM.findDOMNode(r);o.style.width=o.getBoundingClientRect().width+"px",o.style.width=o.getBoundingClientRect().width+"px",r.setState({closing:!0})}},r.animationEnd=function(e,t){if(!t&&!r.state.closed){r.setState({closed:!0,closing:!1});var o=r.props.afterClose;o&&o()}},r.state={closing:!1,closed:!1},r}return _inherits(t,e),_createClass(t,[{key:"isPresetColor",value:function(e){return!!e&&/^(pink|red|yellow|orange|cyan|green|blue|purple|geekblue|magenta|volcano|gold|lime)(-inverse)?$/.test(e)}},{key:"render",value:function(){var e,t=this.props,r=t.prefixCls,o=t.closable,s=t.color,l=t.className,a=t.children,n=t.style,i=t.angle,c=__rest(t,["prefixCls","closable","color","className","children","style","angle"]),m=o?React.createElement(Icon,{type:"close",onClick:this.close}):"",p=this.isPresetColor(s),f=classNames(r,(_defineProperty(e={},r+"-"+s,p),_defineProperty(e,r+"-has-color",s&&!p),_defineProperty(e,r+"-close",this.state.closing),_defineProperty(e,r+"-with-angle",i&&s),e),l),d=omit(c,["onClose","afterClose"]),h=p?{}:{borderLeftColor:s,borderTopColor:s},u=_extends({backgroundColor:s&&!p?s:null},n),b=this.state.closed?null:React.createElement("div",_extends({"data-show":!this.state.closing},d,{className:f,style:u}),a,m,i&&s?React.createElement("div",{className:r+"-angle",style:h}):null);return React.createElement(Animate,{component:"",showProp:"data-show",transitionName:r+"-zoom",transitionAppear:!0,onEnd:this.animationEnd},b)}}]),t}(React.Component);export default Tag;Tag.CheckableTag=CheckableTag,Tag.defaultProps={prefixCls:"dt-tag",closable:!1};