"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 use_immer_1 = require("use-immer");
var useEventListener_1 = require("../../../../hooks/useEventListener");
var CloseBtn_1 = require("../../../CloseBtn");
var Modal_1 = require("../../../Modal");
var ScreenMedia_1 = require("../../../ScreenMedia");
var FiltersContainer_style_1 = require("./FiltersContainer.style");
function FiltersContainer(props) {
    var FiltersComponent = props.FiltersComponent, filterMobileOpen = props.filterMobileOpen, openFilters = props.openFilters, 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 handleFilters = react_1.useCallback(function handleFilters(data) {
        setFilters(function () { return data; });
    }, []);
    var handleFiltersMobile = react_1.useCallback(function handleFiltersMobile(data) {
        setFiltersTemp(function () { return data; });
    }, []);
    var applyFilters = react_1.useCallback(function applyFilters() {
        setFilters(function () { return filtersTemp; }, { replaceUrl: true });
        setFilterMobileOpen(false);
    }, [filtersTemp]);
    var clearFilters = react_1.useCallback(function clearFilters() {
        setFilters(function () { return ({}); });
    }, []);
    var clearFiltersMobile = react_1.useCallback(function clearFiltersMobile() {
        closeFilters();
        setFilters(function () { return ({}); });
    }, []);
    useEventListener_1.useEventListener('hashchange', function hashchange() {
        if (window.location.hash === '#filter') {
            setFilterMobileOpen(true);
        }
        else {
            setFilterMobileOpen(false);
        }
    });
    react_1.useEffect(function () {
        if (window.location.hash === '#filter') {
            window.location.replace('');
        }
    }, []);
    return (react_1.default.createElement(FiltersContainer_style_1.FiltersContainerStyle, null,
        react_1.default.createElement(FilterDesktop, { clearFilters: clearFilters, FiltersComponent: FiltersComponent, handleFilters: handleFilters, filters: filters }),
        react_1.default.createElement(FilterMobile, { clearFilters: clearFiltersMobile, FiltersComponent: FiltersComponent, filterMobileOpen: filterMobileOpen, applyFilters: applyFilters, closeFilters: closeFilters, handleFilters: handleFiltersMobile, filters: filters })));
}
exports.FiltersContainer = FiltersContainer;
function FilterDesktop(_a) {
    var clearFilters = _a.clearFilters, FiltersComponent = _a.FiltersComponent, handleFilters = _a.handleFilters, filters = _a.filters;
    return (react_1.default.createElement(ScreenMedia_1.ScreenMedia, { size: "desktop" },
        react_1.default.createElement("div", { className: "filters" },
            react_1.default.createElement("div", { className: "filters-title" },
                "Filtrar",
                react_1.default.createElement("div", { className: "clear-filters", onClick: clearFilters, "data-cy": "clear-desktop-filters" }, "LIMPAR")),
            react_1.default.createElement("div", { className: "filters-content", "data-cy": "desktop-filters" },
                react_1.default.createElement(FiltersComponent, { handleFilters: handleFilters, filters: filters })))));
}
function FilterMobile(_a) {
    var clearFilters = _a.clearFilters, filterMobileOpen = _a.filterMobileOpen, FiltersComponent = _a.FiltersComponent, closeFilters = _a.closeFilters, applyFilters = _a.applyFilters, handleFilters = _a.handleFilters, filters = _a.filters;
    return (react_1.default.createElement(ScreenMedia_1.ScreenMedia, { size: "mobile" },
        react_1.default.createElement(Modal_1.Modal, { show: filterMobileOpen },
            react_1.default.createElement("div", { className: "filters-mobile", "data-cy": "mobile-filters" },
                react_1.default.createElement("div", { className: "filters-title" },
                    "Filtrar",
                    react_1.default.createElement("div", { className: "clear-filters text-primary", onClick: clearFilters, "data-cy": "clear-mobile-filters" }, "LIMPAR FILTROS"),
                    react_1.default.createElement("div", { className: "close-btn", onClick: closeFilters },
                        react_1.default.createElement(CloseBtn_1.CloseBtn, null))),
                react_1.default.createElement("div", { className: "filters-body" },
                    react_1.default.createElement(FiltersComponent, { handleFilters: handleFilters, filters: filters })),
                react_1.default.createElement("div", { className: "filters-btn", "data-cy": "btn-mobile-filters" },
                    react_1.default.createElement("button", { className: "btn btn-primary", onClick: applyFilters, type: "button" }, "Filtrar"))))));
}
//# sourceMappingURL=FiltersContainer.js.map