import * as tslib_1 from "tslib";
import React from 'react';
import classNames from 'classnames';
import { ModalCustom } from '..';
var alertIns = new ModalCustom();
var closedByHand = false;
var AlertDefaultProps = {
    cancelText: '取消',
    confirmText: '确认',
    btnText: '知道了',
};
var AlertType;
(function (AlertType) {
    AlertType["SUCCESS"] = "success";
    AlertType["ERROR"] = "error";
    AlertType["WARN"] = "warn";
    AlertType["CONFIRM"] = "confirm";
})(AlertType || (AlertType = {}));
var Success = function () { return (React.createElement("div", { className: "alert_icon alert_icon-success" },
    React.createElement("div", { className: "alert_icon-success_line alert_icon-success_line-long" }),
    React.createElement("div", { className: "alert_icon-success_line alert_icon-success_line-tip" }),
    React.createElement("div", { className: "alert_icon-success_ring" }),
    React.createElement("div", { className: "alert_icon-success_hide-corners" }))); };
var Warn = function () { return (React.createElement("div", { className: "alert_icon alert_icon-warning" },
    React.createElement("span", { className: "alert_icon-warning_body" },
        React.createElement("span", { className: "alert_icon-warning_dot" })))); };
var Error = function () { return (React.createElement("div", { className: "alert_icon alert_icon-error" },
    React.createElement("span", { className: "alert_icon-error_mark" },
        React.createElement("span", { className: "alert_icon-error_line alert_icon-error_line-left" }),
        React.createElement("span", { className: "alert_icon-error_line alert_icon-error_line-right" })))); };
var Alert = function (props) {
    var close = function () {
        closedByHand = true;
        var onCancel = props.onCancel;
        onCancel && onCancel();
        alertIns.destroy();
    };
    var confirm = function () {
        closedByHand = true;
        var onOk = props.onOk;
        onOk && onOk();
        alertIns.destroy();
    };
    return (React.createElement("div", { className: classNames('alert_overlay alert_overlay-show', props.className), style: props.style },
        React.createElement("div", { className: "alert_modal", style: props.containerStyle },
            !props.hideIcon && (React.createElement("div", null,
                props.alertType === AlertType.SUCCESS && React.createElement(Success, null),
                (props.alertType === AlertType.WARN ||
                    props.alertType === AlertType.CONFIRM) && React.createElement(Warn, null),
                props.alertType === AlertType.ERROR && React.createElement(Error, null))),
            React.createElement("div", { className: "alert_title" }, props.title),
            props.text && React.createElement("div", { className: "alert_text" }, props.text),
            React.createElement("div", { className: "alert_button_container" },
                props.alertType !== AlertType.CONFIRM && (React.createElement("div", { className: "alert_button", onClick: confirm }, props.btnText)),
                props.alertType === AlertType.CONFIRM && (React.createElement(React.Fragment, null,
                    React.createElement("div", { className: "alert_button-confirm", onClick: close }, props.cancelText),
                    React.createElement("div", { style: { flex: 1 } }),
                    React.createElement("div", { className: "alert_button-confirm", onClick: confirm }, props.confirmText)))))));
};
Alert.defaultProps = AlertDefaultProps;
var renderCommon = function (params, alertType) {
    if (Object.prototype.toString.call(params) === '[object String]') {
        params = { title: params };
    }
    alertIns.show(React.createElement(Alert, tslib_1.__assign({ alertType: alertType }, tslib_1.__assign({}, params))));
};
var alert = {
    success: function (params) {
        closedByHand = false;
        var DURATION = 2000;
        if (Object.prototype.toString.call(params) === '[object String]') {
            params = { title: params, duration: DURATION };
        }
        else {
            params.duration = params.hasOwnProperty('duration')
                ? params.duration
                : DURATION;
        }
        alertIns.show(React.createElement(Alert, tslib_1.__assign({ alertType: "success" }, tslib_1.__assign({}, params))));
        var duration = params.duration;
        if (duration === 0)
            return;
        var timer = setTimeout(function () {
            !closedByHand && alertIns && alertIns.destroy();
            clearTimeout(timer);
        }, duration);
    },
    error: function (params) {
        renderCommon(params, 'error');
    },
    warn: function (params) {
        renderCommon(params, 'warn');
    },
    warning: function (params) {
        renderCommon(params, 'warn');
    },
    confirm: function (params) {
        renderCommon(params, 'confirm');
    },
    destroy: function () {
        alertIns.destroy();
    },
};
export default alert;
//# sourceMappingURL=index.js.map