"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CardGridInfinite = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_virtuoso_1 = require("react-virtuoso");
const ContentState_1 = require("../ContentState");
const Card_1 = require("./Card");
const constants_1 = require("./constants");
const Footer_1 = require("./Footer");
const List_1 = require("./List");
const NoDataPlaceholder_1 = require("./NoDataPlaceholder");
const OnTopButton_1 = require("./OnTopButton");
const SkeletonGrid_1 = require("./SkeletonGrid");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const CardGridInfinite = (props) => {
    const { contentStateProps, desktopCardWidth, virtuosoProps, scrollParent, skeleton, footerProps, onTopButtonProps, list, noDataImgSrc, defineCard, classnames, isMobile, } = (0, useLogic_1.useLogic)(props);
    const VirtuosoList = (0, react_1.useMemo)(() => (0, react_1.forwardRef)((listProps, ref) => ((0, jsx_runtime_1.jsx)(List_1.List, { ...listProps, ref: ref, desktopCardWidth: desktopCardWidth }))), [desktopCardWidth]);
    const renderVirtuoso = () => {
        if (!scrollParent) {
            return null;
        }
        // VirtuosoGrid не поддерживает работу со списком без grid сетки (на мобиле обычный список) когда высота item разная
        if (isMobile) {
            return ((0, jsx_runtime_1.jsx)(react_virtuoso_1.Virtuoso, { ...virtuosoProps, data: list, customScrollParent: scrollParent, components: {
                    List: VirtuosoList,
                    Footer: () => (0, jsx_runtime_1.jsx)(Footer_1.Footer, { ...footerProps }),
                }, itemContent: (_, item) => (0, jsx_runtime_1.jsx)(Card_1.Card, { item: item, ...defineCard(item) }) }));
        }
        return ((0, jsx_runtime_1.jsx)(react_virtuoso_1.VirtuosoGrid, { ...virtuosoProps, data: list, customScrollParent: scrollParent, listClassName: constants_1.cardGridClassnames.list, components: {
                List: VirtuosoList,
                Footer: () => (0, jsx_runtime_1.jsx)(Footer_1.Footer, { ...footerProps }),
            }, itemContent: (_, item) => (0, jsx_runtime_1.jsx)(Card_1.Card, { item: item, ...defineCard(item) }) }));
    };
    return ((0, jsx_runtime_1.jsx)(styles_1.ContentStateWrapper, { className: classnames, children: (0, jsx_runtime_1.jsx)(ContentState_1.ContentState, { ...contentStateProps, loadingContent: (0, jsx_runtime_1.jsx)(SkeletonGrid_1.SkeletonGrid, { skeleton: skeleton, desktopCardWidth: desktopCardWidth }), children: list?.length ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [renderVirtuoso(), (0, jsx_runtime_1.jsx)(OnTopButton_1.OnTopButton, { ...onTopButtonProps })] })) : ((0, jsx_runtime_1.jsx)(NoDataPlaceholder_1.NoDataPlaceholder, { noDataImgSrc: noDataImgSrc })) }) }));
};
exports.CardGridInfinite = CardGridInfinite;
