"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.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_native_1 = require("react-native");
var services_1 = require("../../../services");
var Pressable_1 = require("../../Pressable");
var Alert_style_1 = require("./Alert.style");
var AlertObs = new services_1.Event();
exports.Alert = function () {
    var offset = 0;
    var windowHeight = react_native_1.Dimensions.get('window').height;
    var _a = react_1.useState(false), opened = _a[0], setOpened = _a[1];
    var _b = react_1.useState({}), items = _b[0], setItems = _b[1];
    var _c = react_1.useState(0), heightItems = _c[0], setHeightItems = _c[1];
    var animation = react_1.useRef(new react_native_1.Animated.Value(1)).current;
    function close() {
        react_native_1.Animated.timing(animation, {
            toValue: 0,
            duration: 200,
            useNativeDriver: true,
        }).start(function () {
            setOpened(false);
        });
    }
    react_1.useEffect(function () {
        var obs = AlertObs.observable.subscribe(function (value) {
            setItems(value);
            setOpened(true);
            animation.setValue(0);
            react_native_1.Animated.timing(animation, {
                toValue: 1,
                duration: 200,
                useNativeDriver: true,
            }).start();
        });
        return function () { return obs.unsubscribe(); };
    }, []);
    react_1.useEffect(function () {
        var backAction = function () {
            if (opened) {
                close();
                return true;
            }
            return false;
        };
        var backHandler = react_native_1.BackHandler.addEventListener('hardwareBackPress', backAction);
        return function () { return backHandler.remove(); };
    }, [opened]);
    function onPress(btn) {
        if (btn.onPress)
            btn.onPress();
        close();
    }
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(Alert_style_1.Container, { visible: opened, animationType: "fade", transparent: true },
            react_1.default.createElement(Alert_style_1.Opacity, null),
            react_1.default.createElement(Alert_style_1.ModalContainer, null,
                react_1.default.createElement(react_native_1.TouchableWithoutFeedback, { onPress: close, testID: "background-alert" },
                    react_1.default.createElement(react_native_1.View, { style: {
                            position: 'absolute',
                            width: '100%',
                            height: '100%',
                        } })),
                react_1.default.createElement(Alert_style_1.Modal, null,
                    items.icon && react_1.default.createElement(Alert_style_1.FontAwesomeIconItem, { icon: items.icon, color: items.iconColor }),
                    items.title &&
                        (typeof items.title === 'string' ? (react_1.default.createElement(Alert_style_1.TitleText, { color: items.titleColor || 'black' }, items.title)) : (items.title)),
                    items.message &&
                        (typeof items.message === 'string' ? (react_1.default.createElement(Alert_style_1.TextContent, null, "Ap\u00F3s deletado, n\u00E3o ser\u00E1 possivel RECUPERA-LO")) : (items.message)),
                    react_1.default.createElement(Alert_style_1.BtnContainer, null, items.buttons &&
                        items.buttons.map(function (btn, index) { return (react_1.default.createElement(Pressable_1.Pressable, { key: "btn-" + index, testID: "alert-btn-" + index, onPress: function () { return onPress(btn); }, ripple: true },
                            react_1.default.createElement(Alert_style_1.BtnAction, { color: btn.color || '#444' }, btn.text))); })))))));
};
exports.Alert.show = function (options) {
    AlertObs.set(options);
};
//# sourceMappingURL=Alert.js.map