"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
var react_fontawesome_1 = require("@fortawesome/react-fontawesome");
var _ = __importStar(require("lodash"));
var Toast_style_1 = __importDefault(require("./Toast.style"));
var Toast = react_1.default.memo(function Toast(_a) {
    var item = _a.item, onDelete = _a.onDelete;
    var id = item.id, message = item.message, opened = item.opened, type = item.type, closeButton = item.closeButton;
    var _b = react_1.useState(false), opening = _b[0], setOpening = _b[1];
    var _c = react_1.useState(false), closing = _c[0], setClosing = _c[1];
    function RemoveToast() {
        setClosing(true);
        setOpening(false);
        setTimeout(function () {
            onDelete(id);
        }, 300);
    }
    react_1.useEffect(function () {
        if (opened) {
            setTimeout(function () {
                setOpening(true);
            }, 10);
        }
        else {
            RemoveToast();
        }
    }, [opened]);
    return (react_1.default.createElement(Toast_style_1.default, null,
        react_1.default.createElement("div", { className: "ds-toast-container " + (closing && 'closing') + " " + (opening && 'opening') + " " + type },
            react_1.default.createElement("div", { className: "ds-toast" },
                react_1.default.createElement("div", { className: "message" }, message),
                closeButton && (react_1.default.createElement("div", { className: "close", onClick: RemoveToast },
                    react_1.default.createElement(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faTimes })))))));
}, _.isEqual);
exports.default = Toast;
//# sourceMappingURL=Toast.js.map