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 _jsxFileName = 'src/msgbox/Notice.jsx';
/**
 * notice.jsx
 *
 * @Author: Aubrey
 * @Date: 17/8/29 14:33
 */

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

var Notice = function (_React$Component) {
    _inherits(Notice, _React$Component);

    function Notice(props) {
        _classCallCheck(this, Notice);

        var _this2 = _possibleConstructorReturn(this, (Notice.__proto__ || Object.getPrototypeOf(Notice)).call(this, props));

        _this2.state = {
            shouldClose: false
        };
        return _this2;
    }

    _createClass(Notice, [{
        key: 'componentDidMount',
        value: function componentDidMount() {
            var _props = this.props,
                yesCallback = _props.yesCallback,
                noCallback = _props.noCallback,
                onClose = _props.onClose;

            if (this.props.duration > 0) {
                this.closeTimer = setTimeout(function () {}, this.props.duration - 300);
            }
            var yesBtn = document.querySelector('.yesBtn');
            var noBtn = document.querySelector('.noBtn');
            if (yesBtn) {
                yesBtn.addEventListener('click', function () {
                    onClose();
                    yesCallback && yesCallback();
                });
            }
            if (noBtn) {
                noBtn.addEventListener('click', function () {
                    //_this.hide()
                    onClose();
                    noCallback && noCallback();
                });
            }
        }
    }, {
        key: 'componentWillUnmount',
        value: function componentWillUnmount() {
            this.clearCloseTimer();
        }
    }, {
        key: 'clearCloseTimer',
        value: function clearCloseTimer() {
            if (this.closeTimer) {
                clearTimeout(this.closeTimer);
                this.closeTimer = null;
            }
        }
    }, {
        key: 'close',
        value: function close() {
            var _this3 = this;

            this.clearCloseTimer();
            var _this = this;
            _this.setState({ shouldClose: true });
            this.timer = setTimeout(function () {
                if (_this3.props.onClose) {
                    _this3.props.onClose();
                }
                clearTimeout(_this.timer);
            }, 300);
        }
    }, {
        key: 'render',
        value: function render() {
            var prefixCls = this.props.prefixCls;
            var shouldClose = this.state.shouldClose;

            return React.createElement(
                'div',
                { className: prefixCls + '-mask', __source: {
                        fileName: _jsxFileName,
                        lineNumber: 72
                    },
                    __self: this
                },
                React.createElement(
                    'div',
                    { className: classNames([prefixCls + '-notice-box', { leave: shouldClose }]), ref: 'msgbox', __source: {
                            fileName: _jsxFileName,
                            lineNumber: 73
                        },
                        __self: this
                    },
                    this.props.content
                )
            );
        }
    }]);

    return Notice;
}(React.Component);

Notice.propTypes = {
    duration: PropTypes.number,
    content: PropTypes.any
};
Notice.defaultProps = {
    duration: 3000
};


export default Notice;