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 _jsxFileName = 'src/alert/Alert.jsx';
/**
 * Alert.jsx
 *
 * @Author: jruif
 * @Date: 2018/3/10 下午2:24
 */

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Icon from '../icon';
import Button from '../button';
import { iconTypeObj } from '../modal';

var Alert = function (_React$PureComponent) {
    _inherits(Alert, _React$PureComponent);

    function Alert() {
        _classCallCheck(this, Alert);

        return _possibleConstructorReturn(this, (Alert.__proto__ || Object.getPrototypeOf(Alert)).apply(this, arguments));
    }

    _createClass(Alert, [{
        key: 'render',
        value: function render() {
            var _classNames,
                _this2 = this;

            var _props = this.props,
                prefixCls = _props.prefixCls,
                className = _props.className,
                content = _props.content,
                iconType = _props.iconType,
                type = _props.type,
                btnTxt = _props.btnTxt,
                btnOnClick = _props.btnOnClick,
                actionBtn = _props.actionBtn,
                mini = _props.mini,
                style = _props.style,
                children = _props.children;

            var classes = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-' + type, type), _defineProperty(_classNames, prefixCls + '-mini', mini), _classNames), className);
            var icon = void 0;
            if (type && type !== 'none') {
                icon = iconType || iconTypeObj[type];
            }
            return React.createElement(
                'div',
                {
                    className: classes,
                    onMouseEnter: this.handleMouseEnter,
                    onMouseLeave: this.handleMouseLeave,
                    style: style, __source: {
                        fileName: _jsxFileName,
                        lineNumber: 90
                    },
                    __self: this
                },
                React.createElement(
                    'div',
                    { className: prefixCls + '-content', __source: {
                            fileName: _jsxFileName,
                            lineNumber: 95
                        },
                        __self: this
                    },
                    icon && React.createElement(Icon, { type: icon, className: prefixCls + '-icon', __source: {
                            fileName: _jsxFileName,
                            lineNumber: 96
                        },
                        __self: this
                    }),
                    React.createElement(
                        'div',
                        { className: prefixCls + '-body', __source: {
                                fileName: _jsxFileName,
                                lineNumber: 97
                            },
                            __self: this
                        },
                        React.isValidElement(content) ? content : React.createElement(
                            'p',
                            {
                                __source: {
                                    fileName: _jsxFileName,
                                    lineNumber: 98
                                },
                                __self: this
                            },
                            content
                        ),
                        children
                    ),
                    React.createElement(
                        'div',
                        { className: prefixCls + '-action', __source: {
                                fileName: _jsxFileName,
                                lineNumber: 101
                            },
                            __self: this
                        },
                        actionBtn ? React.cloneElement(actionBtn, {
                            className: classNames(prefixCls + '-btn', actionBtn.classNames),
                            size: 'small',
                            shape: 'none'
                        }) : btnTxt ? React.createElement(
                            Button,
                            {
                                className: classNames(prefixCls + '-btn'),
                                size: 'small',
                                shape: 'none',
                                onClick: btnOnClick, __source: {
                                    fileName: _jsxFileName,
                                    lineNumber: 109
                                },
                                __self: this
                            },
                            btnTxt
                        ) : null,
                        React.createElement(
                            'span',
                            { className: prefixCls + '-separate', __source: {
                                    fileName: _jsxFileName,
                                    lineNumber: 117
                                },
                                __self: this
                            },
                            '|'
                        ),
                        React.createElement(Button, {
                            className: classNames(prefixCls + '-cancel'),
                            icon: 'cancel-1',
                            size: 'small',
                            shape: 'none',
                            onClick: function onClick() {
                                return _this2.triggerClose(true);
                            },
                            __source: {
                                fileName: _jsxFileName,
                                lineNumber: 118
                            },
                            __self: this
                        })
                    )
                )
            );
        }
    }]);

    return Alert;
}(React.PureComponent);

Alert.displayName = 'NeatUI.Alert';
Alert.propTypes = {
    /**
     * 显示内容
     * */
    content: PropTypes.node,
    /**
     * 自定义行为按钮，必须为react元素
     * */
    actionBtn: PropTypes.element,
    /**
     * 自定义按钮内容
     * */
    btnTxt: PropTypes.node,
    /**
     * 自定义按钮点击事件
     * */
    btnOnClick: PropTypes.func,
    /**
     * 关闭时回调
     * */
    onClose: PropTypes.func,
    /**
     * 类型
     * */
    type: PropTypes.oneOf(['info', 'error', 'warning', 'success', 'none']),
    /**
     * 简约风格
     * */
    mini: PropTypes.bool,
    /**
     * icon类型, 同Icon
     * */
    iconType: PropTypes.string
};
Alert.defaultProps = {
    prefixCls: 'ne-alert',
    type: 'info',
    mini: false
};


export default Alert;