"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Alert = void 0;
var react_1 = __importStar(require("react"));
var react_fontawesome_1 = require("@fortawesome/react-fontawesome");
var Button_1 = require("../Button");
var CloseBtn_1 = require("../CloseBtn");
var Modal_1 = require("../Modal");
var Alert_obs_1 = require("./Alert.obs");
exports.Alert = function Alert() {
    var _a = (0, react_1.useState)(false), opened = _a[0], setOpened = _a[1];
    var _b = (0, react_1.useState)({}), items = _b[0], setItems = _b[1];
    function close() {
        setOpened(false);
        if (items.onClose)
            items.onClose();
    }
    (0, react_1.useEffect)(function () {
        var obs = Alert_obs_1.AlertObs.observable.subscribe(function (value) {
            setItems(value);
            setOpened(true);
        });
        return function () { return obs.unsubscribe(); };
    }, []);
    function onPress(btn) {
        if (btn.onPress)
            btn.onPress();
        close();
    }
    return (react_1.default.createElement(Modal_1.Modal, { show: opened, onRequestClose: close },
        react_1.default.createElement(Modal_1.Modal.Body, { className: "alert-container p-4" },
            react_1.default.createElement("div", { className: "float-right absolute" },
                react_1.default.createElement(CloseBtn_1.CloseBtn, { onClick: function () { return close(); }, size: 22 })),
            react_1.default.createElement("div", { className: "text-center" },
                react_1.default.createElement("h1", { className: "m-0 p-0" }, items.icon && react_1.default.createElement(react_fontawesome_1.FontAwesomeIcon, { icon: items.icon, color: items.iconColor })),
                react_1.default.createElement("div", { className: "p-4" },
                    items.title &&
                        (typeof items.title === 'string' ? (react_1.default.createElement("h4", null,
                            react_1.default.createElement("div", { style: { color: items.titleColor || 'black' } }, items.title))) : (items.title)),
                    react_1.default.createElement("div", { className: "description" }, items.message)),
                react_1.default.createElement("div", { className: "d-flex justify-center justify-content-center" }, items.buttons &&
                    items.buttons.map(function (btn, index) { return (react_1.default.createElement("div", { className: "pr-2", key: "btn-".concat(index) },
                        react_1.default.createElement(Button_1.Button, { onClick: function () { return onPress(btn); }, bgColor: btn.bgColor, "data-testid": "alert-btn-".concat(index) }, btn.text))); }))))));
};
exports.Alert.show = function (options) {
    Alert_obs_1.AlertObs.set(options);
};
//# sourceMappingURL=Alert.js.map