var _jsxFileName = 'src/toast/Toast.jsx',
    _this = this;

/**
 * toast.jsx
 *
 * @Author: Aubrey
 * @Date: 17/8/28 17:29
 */

import React from 'react';
import classNames from 'classnames';
import Notification from './Notification';
import Icon from '../icon';

var prefixCls = 'ne-toast';
var notification = void 0;
var getNotification = function getNotification() {
    if (!notification) {
        notification = Notification.reWrite();
    }
    return notification;
};

var notice = function notice(content, type, icon) {
    var duration = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3000;
    var _onClose = arguments[4];

    var notificationInstance = getNotification();

    notificationInstance.notice({
        prefixCls: prefixCls,
        duration: duration,
        content: React.createElement(
            'div',
            {
                className: classNames([prefixCls, { info: type === 'info' }, { success: type === 'success' }, { warning: type === 'warning' }, { error: type === 'error' }]), __source: {
                    fileName: _jsxFileName,
                    lineNumber: 29
                },
                __self: _this
            },
            React.createElement(
                'div',
                { className: 'ne-toast-icon', __source: {
                        fileName: _jsxFileName,
                        lineNumber: 37
                    },
                    __self: _this
                },
                !!icon ? icon : React.createElement(Icon, { type: 'ok-1', __source: {
                        fileName: _jsxFileName,
                        lineNumber: 37
                    },
                    __self: _this
                })
            ),
            React.createElement(
                'div',
                { className: 'ne-toast-content', __source: {
                        fileName: _jsxFileName,
                        lineNumber: 38
                    },
                    __self: _this
                },
                content
            )
        ),
        onClose: function onClose() {
            _onClose && _onClose();
        }
    });
};

export default {
    info: function info(content, duration) {
        var icon = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : React.createElement(Icon, { type: 'file', __source: {
                fileName: _jsxFileName,
                lineNumber: 48
            },
            __self: this
        });
        var onClose = arguments[3];

        return notice(content, 'info', icon, duration, onClose);
    },
    success: function success(content, duration, icon, onClose) {
        return notice(content, 'success', icon, duration, onClose);
    },
    warning: function warning(content, duration) {
        var icon = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : React.createElement(Icon, { type: 'warn', __source: {
                fileName: _jsxFileName,
                lineNumber: 54
            },
            __self: this
        });
        var onClose = arguments[3];

        return notice(content, 'warning', icon, duration, onClose);
    },
    error: function error(content, duration) {
        var icon = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : React.createElement(Icon, { type: 'cancel-1', __source: {
                fileName: _jsxFileName,
                lineNumber: 57
            },
            __self: this
        });
        var onClose = arguments[3];

        return notice(content, 'error', icon, duration, onClose);
    },
    hide: function hide() {
        if (notification) {
            notification.destroy();
            notification = null;
        }
    }
};