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";import _extends from"babel-runtime/helpers/extends";import*as React from"react";import{cloneElement}from"react";import RcTooltip from"rc-tooltip";import classNames from"classnames";import _getPlacements from"./placements";var splitObject=function(e,t){var i={},o=_extends({},e);return t.forEach(function(t){e&&t in e&&(i[t]=e[t],delete o[t])}),{picked:i,omited:o}},Tooltip=function(e){function t(e){_classCallCheck(this,t);var i=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return i.onVisibleChange=function(e){var t=i.props.onVisibleChange;"visible"in i.props||i.setState({visible:!i.isNoTitle()&&e}),t&&!i.isNoTitle()&&t(e)},i.onPopupAlign=function(e,t){var o=i.getPlacements(),r=Object.keys(o).filter(function(e){return o[e].points[0]===t.points[0]&&o[e].points[1]===t.points[1]})[0];if(r){var n=e.getBoundingClientRect(),s={top:"50%",left:"50%"};r.indexOf("top")>=0||r.indexOf("Bottom")>=0?s.top=n.height-t.offset[1]+"px":(r.indexOf("Top")>=0||r.indexOf("bottom")>=0)&&(s.top=-t.offset[1]+"px"),r.indexOf("left")>=0||r.indexOf("Right")>=0?s.left=n.width-t.offset[0]+"px":(r.indexOf("right")>=0||r.indexOf("Left")>=0)&&(s.left=-t.offset[0]+"px"),e.style.transformOrigin=s.left+" "+s.top}},i.saveTooltip=function(e){i.tooltip=e},i.state={visible:!!e.visible||!!e.defaultVisible},i}return _inherits(t,e),_createClass(t,[{key:"componentWillReceiveProps",value:function(e){"visible"in e&&this.setState({visible:e.visible})}},{key:"getPopupDomNode",value:function(){return this.tooltip.getPopupDomNode()}},{key:"getPlacements",value:function(){var e=this.props,t=e.builtinPlacements,i=e.arrowPointAtCenter,o=e.autoAdjustOverflow;return t||_getPlacements({arrowPointAtCenter:i,verticalArrowShift:8,autoAdjustOverflow:o})}},{key:"isHoverTrigger",value:function(){var e=this.props.trigger;return!e||"hover"===e||!!Array.isArray(e)&&e.indexOf("hover")>=0}},{key:"getDisabledCompatibleChildren",value:function(e){if((e.type.__ANT_BUTTON||"button"===e.type)&&e.props.disabled&&this.isHoverTrigger()){var t=splitObject(e.props.style,["position","left","right","top","bottom","float","display","zIndex"]),i=t.picked,o=t.omited,r=_extends({display:"inline-block"},i,{cursor:"not-allowed"}),n=_extends({},o,{pointerEvents:"none"}),s=cloneElement(e,{style:n,className:null});return React.createElement("span",{style:r,className:e.props.className},s)}return e}},{key:"isNoTitle",value:function(){var e=this.props,t=e.title,i=e.overlay;return!t&&!i}},{key:"render",value:function(){var e=this.props,t=this.state,i=e.prefixCls,o=e.title,r=e.overlay,n=e.openClassName,s=e.getPopupContainer,l=e.getTooltipContainer,a=e.children,p=t.visible;"visible"in e||!this.isNoTitle()||(p=!1);var c=this.getDisabledCompatibleChildren(React.isValidElement(a)?a:React.createElement("span",null,a)),f=c.props,m=classNames(f.className,_defineProperty({},n||i+"-open",!0));return React.createElement(RcTooltip,_extends({},this.props,{getTooltipContainer:s||l,ref:this.saveTooltip,builtinPlacements:this.getPlacements(),overlay:r||o||"",visible:p,onVisibleChange:this.onVisibleChange,onPopupAlign:this.onPopupAlign}),p?cloneElement(c,{className:m}):c)}}]),t}(React.Component);export default Tooltip;Tooltip.defaultProps={prefixCls:"dt-tooltip",placement:"top",transitionName:"zoom-big-fast",mouseEnterDelay:.1,mouseLeaveDelay:.1,arrowPointAtCenter:!1,autoAdjustOverflow:!0};