"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.CardsListingContainer = void 0;
var react_1 = __importStar(require("react"));
var web_1 = require("../../../PageListingError/web");
var web_2 = require("../../../PageListingNotFound/web");
var Pagination_1 = require("../../../Pagination");
var CardsListingContainer_style_1 = require("./CardsListingContainer.style");
function CardsListingContainer(props) {
    var _a;
    var renderResource = props.renderResource, renderResourceSkeleton = props.renderResourceSkeleton, viewList = props.viewList;
    var resourcesTotal = viewList.resourcesTotal, skeletonResources = viewList.skeletonResources, setPage = viewList.setPage, filters = viewList.filters, starting = viewList.starting, searching = viewList.searching, resources = viewList.resources, reloadPage = viewList.reloadPage, errorLoadData = viewList.errorLoadData, limit = viewList.limit;
    var changePage = react_1.useCallback(function (page) {
        setPage(page);
    }, []);
    var currentPage = ((_a = filters.offset) !== null && _a !== void 0 ? _a : 0) / limit + 1;
    var showCards = !starting && !searching && resources;
    var showCardsSkeleton = (starting || searching) && skeletonResources;
    var showPageError = errorLoadData;
    return (react_1.default.createElement(CardsListingContainer_style_1.CardsListingContainerStyle, null,
        showPageError && (react_1.default.createElement("span", { "data-testid": "error-page-listing" },
            react_1.default.createElement(web_1.PageErrorLoad, { retry: reloadPage }))),
        react_1.default.createElement("div", { className: "cards-listing" }, showCards &&
            resources.map(function (resource, i) { return (react_1.default.createElement("span", { key: "card-" + resource.id, "data-testid": "card-" + resource.id }, renderResource(resource, i))); })),
        react_1.default.createElement("div", { className: "cards-listing cards-listing-skeleton" }, showCardsSkeleton &&
            skeletonResources.map(function (resource, i) { return (react_1.default.createElement("span", { key: "card-skeleton-" + i, "data-testid": "skeleton-card" }, renderResourceSkeleton(resource, i))); })),
        showCards && resources.length === 0 && (react_1.default.createElement("span", { "data-testid": "not-found-page" },
            react_1.default.createElement(web_2.PageListingNotFound, null))),
        react_1.default.createElement("div", { className: "pagination-listing" },
            react_1.default.createElement(Pagination_1.Pagination, { total: resourcesTotal, perPage: 20, currentPage: currentPage, changePage: changePage }))));
}
exports.CardsListingContainer = CardsListingContainer;
//# sourceMappingURL=CardsListingContainer.js.map