"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_react=require("react"),React=_interopRequireWildcard(_react),_reactDom=require("react-dom"),ReactDOM=_interopRequireWildcard(_reactDom),_button=require("../button"),_button2=_interopRequireDefault(_button);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var ActionButton=function(e){function t(e){(0,_classCallCheck3.default)(this,t);var n=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.onClick=function(){var e=n.props,t=e.actionFn,r=e.closeModal;if(t){var i=void 0;t.length?i=t(r):(i=t())||r(),i&&i.then&&(n.setState({loading:!0}),i.then(function(){r.apply(void 0,arguments)},function(){n.setState({loading:!1})}))}else r()},n.state={loading:!1},n}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"componentDidMount",value:function(){if(this.props.autoFocus){var e=ReactDOM.findDOMNode(this);this.timeoutId=setTimeout(function(){return e.focus()})}}},{key:"componentWillUnmount",value:function(){clearTimeout(this.timeoutId)}},{key:"render",value:function(){var e=this.props,t=e.type,r=e.children,i=e.disabled,n=this.state.loading;return React.createElement(_button2.default,{type:t,onClick:this.onClick,loading:n,disabled:i},r)}}]),t}(React.Component);exports.default=ActionButton,module.exports=exports.default;