"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.FiltersContainer = void 0;
var react_1 = __importStar(require("react"));
var react_native_1 = require("react-native");
var react_native_responsive_fontsize_1 = require("react-native-responsive-fontsize");
var free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
var react_native_fontawesome_1 = require("@fortawesome/react-native-fontawesome");
var use_immer_1 = require("use-immer");
var native_1 = require("../../../Button/native");
var Pressable_1 = require("../../../Pressable");
var FiltersContainer_style_1 = require("./FiltersContainer.style");
function FiltersContainer(props) {
    var FiltersComponent = props.FiltersComponent, filterMobileOpen = props.filterMobileOpen, closeFilters = props.closeFilters, setFilterMobileOpen = props.setFilterMobileOpen, viewList = props.viewList;
    var filters = viewList.filters, setFilters = viewList.setFilters;
    var _a = use_immer_1.useImmer(filters), filtersTemp = _a[0], setFiltersTemp = _a[1];
    var _b = react_1.useState(true), hideScreen = _b[0], setHideScreen = _b[1];
    var scrollRef = react_1.useRef();
    var formRef = react_1.useRef();
    var animatedToggleFilter = react_1.useRef(new react_native_1.Animated.Value(1)).current;
    var handleFilters = react_1.useCallback(function handleFilters(data) {
        setFilters(function () { return data; });
        closeFilters();
        react_native_1.Keyboard.dismiss();
    }, []);
    var applyFilters = react_1.useCallback(function applyFilters() {
        formRef.current.submitForm();
    }, [filtersTemp]);
    react_1.useLayoutEffect(function () {
        if (filterMobileOpen) {
            setHideScreen(false);
            animatedToggleFilter.setValue(0);
        }
        else {
            react_native_1.Animated.timing(animatedToggleFilter, {
                toValue: 0,
                duration: 200,
                useNativeDriver: true,
            }).start(function () {
                setHideScreen(true);
            });
        }
    }, [filterMobileOpen]);
    var clearFilters = react_1.useCallback(function clearFilters() {
        closeFilters();
        setFilters(function () { return ({}); });
    }, []);
    var onRequestClose = react_1.useCallback(function onRequestClose() {
        react_native_1.Keyboard.dismiss();
        formRef.current.reset();
        formRef.current.setData(filters);
        closeFilters();
    }, []);
    function onShow() {
        react_native_1.Animated.timing(animatedToggleFilter, {
            toValue: 1,
            duration: 200,
            useNativeDriver: true,
        }).start();
    }
    return (react_1.default.createElement(react_native_1.Modal, { visible: !hideScreen, onRequestClose: onRequestClose, transparent: true, onShow: onShow },
        react_1.default.createElement(FiltersContainer_style_1.Container, { style: {
                opacity: animatedToggleFilter,
                transform: [
                    {
                        translateX: animatedToggleFilter.interpolate({
                            inputRange: [0, 1],
                            outputRange: [200, 0],
                        }),
                    },
                    {
                        translateY: hideScreen ? react_native_1.Dimensions.get('window').height : 0,
                    },
                ],
            }, testID: "filters-container" },
            react_1.default.createElement(react_native_1.View, { style: { flex: 1 } },
                react_1.default.createElement(react_native_1.ScrollView, { ref: scrollRef, testID: "filters-scroll", keyboardShouldPersistTaps: "handled", keyboardDismissMode: "on-drag", onScrollBeginDrag: react_native_1.Keyboard.dismiss, onTouchStart: react_native_1.Keyboard.dismiss },
                    react_1.default.createElement(HeaderFilter, { clearFilters: clearFilters, onRequestClose: onRequestClose }),
                    react_1.default.createElement(FiltersComponent, { handleFilters: handleFilters, filters: filters, formRef: formRef })),
                react_1.default.createElement(FiltersContainer_style_1.FilterBtn, null,
                    react_1.default.createElement(native_1.Button, { onPress: applyFilters, variant: "primary", rounded: true }, "FILTRAR"))))));
}
exports.FiltersContainer = FiltersContainer;
var HeaderFilter = react_1.default.memo(function HeaderFilter(_a) {
    var clearFilters = _a.clearFilters, onRequestClose = _a.onRequestClose;
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(FiltersContainer_style_1.BackBtn, { onPress: function () { return onRequestClose(); }, ripple: true },
            react_1.default.createElement(react_native_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faArrowLeft, color: "black", size: react_native_responsive_fontsize_1.RFValue(20) })),
        react_1.default.createElement(FiltersContainer_style_1.HeaderFilters, null,
            react_1.default.createElement(FiltersContainer_style_1.FilterTitle, null, "Filtros"),
            react_1.default.createElement(Pressable_1.Pressable, { onPress: clearFilters, testID: "clear-filters", style: { padding: 10 } },
                react_1.default.createElement(FiltersContainer_style_1.ClearBtn, null, "LIMPAR FILTROS")))));
});
//# sourceMappingURL=FiltersContainer.js.map