"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PageListing = void 0;
var react_1 = __importStar(require("react"));
var AppContext_1 = __importDefault(require("../../AppProvider/AppContext"));
var NavActions_1 = require("../../NavActions");
var CardsListingContainer_1 = require("./CardsListingContainer");
var FiltersContainer_1 = require("./FiltersContainer");
var HeaderListingContainer_1 = require("./HeaderListingContainer");
var PageListing_style_1 = require("./PageListing.style");
var SubHeaderListingContainer_1 = require("./SubHeaderListingContainer");
exports.PageListing = function (props) {
    var FiltersComponent = props.FiltersComponent, navActions = props.navActions, viewList = props.viewList;
    var registerOnSearch = viewList.registerOnSearch, starting = viewList.starting;
    var history = react_1.useContext(AppContext_1.default).history;
    react_1.useEffect(function () {
        registerOnSearch(function () {
            if (navActions) {
                navActions.onUnselectAll();
            }
        });
    }, []);
    var tabsRef = react_1.useRef();
    var formSortRef = react_1.useRef();
    var tagsFiltersRef = react_1.useRef();
    var scrollListingRef = react_1.useRef();
    var FiltersContainerComponent = react_1.useMemo(function () { return FiltersContainer_1.FiltersContainer; }, [props.FiltersContainerComponent]);
    var HeaderListingContainerComponent = react_1.useMemo(function () { return HeaderListingContainer_1.HeaderListingContainer; }, [
        props.HeaderListingContainerComponent,
    ]);
    var _a = react_1.useState(false), filterMobileOpen = _a[0], setFilterMobileOpen = _a[1];
    var openFilters = react_1.useCallback(function () {
        setFilterMobileOpen(true);
        if (history) {
            history.push({
                search: window.location.search,
                hash: 'filter',
            });
        }
        else {
            window.location.hash = 'filter';
        }
    }, []);
    var closeFilters = react_1.useCallback(function () {
        setFilterMobileOpen(false);
        if (history) {
            history.goBack();
        }
        else {
            window.history.back();
        }
    }, []);
    var propsChildren = __assign(__assign({}, props), { tabsRef: tabsRef,
        scrollListingRef: scrollListingRef,
        formSortRef: formSortRef,
        tagsFiltersRef: tagsFiltersRef,
        filterMobileOpen: filterMobileOpen,
        setFilterMobileOpen: setFilterMobileOpen,
        openFilters: openFilters,
        closeFilters: closeFilters });
    return (react_1.default.createElement(PageListing_style_1.PageListingStyle, null,
        !starting && react_1.default.createElement("span", { "data-testid": "started" }),
        react_1.default.createElement("div", { className: "col-filters" },
            react_1.default.createElement(FiltersContainerComponent, __assign({}, propsChildren))),
        react_1.default.createElement("div", { className: "col-listing" },
            navActions && !!navActions.selected && (react_1.default.createElement("span", { "data-testid": "nav-actions-container" },
                react_1.default.createElement(NavActions_1.NavActions, __assign({}, navActions)))),
            react_1.default.createElement("div", { className: "col-listing--inner" },
                react_1.default.createElement(HeaderListingContainer_1.HeaderListingContainer, __assign({}, propsChildren)),
                react_1.default.createElement(SubHeaderListingContainer_1.SubHeaderListingContainer, __assign({}, propsChildren)),
                react_1.default.createElement(CardsListingContainer_1.CardsListingContainer, __assign({}, propsChildren))))));
};
//# sourceMappingURL=PageListing.js.map