"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const ConfigProvider_1 = require("../../ConfigProvider");
const useViewportType_1 = require("../../useViewportType");
const useLogic = ({ initialListType = 'all', unreadNotifications, notifications, onTabChange, onClose, onRetry, }) => {
    const { imagesMap } = (0, react_1.useContext)(ConfigProvider_1.ConfigContext);
    const { isMobile } = (0, useViewportType_1.useViewportType)();
    const [listType, setListType] = (0, react_1.useState)(initialListType);
    const viewedIds = (0, react_1.useRef)(new Set());
    const data = (0, react_1.useMemo)(() => {
        if (unreadNotifications && listType === 'unread') {
            return unreadNotifications;
        }
        return notifications;
    }, [unreadNotifications, listType, notifications]);
    const isEmptyData = data.length === 0;
    const isTabsVisible = Boolean(unreadNotifications);
    const handleTabChange = (type) => {
        setListType(type);
        if (onTabChange) {
            onTabChange();
        }
    };
    const handleView = (id) => {
        viewedIds.current.add(id);
    };
    const handleClose = () => {
        onClose(Array.from(viewedIds.current));
        viewedIds.current.clear();
    };
    const handleRetry = () => {
        if (onRetry) {
            onRetry();
        }
    };
    return {
        listType,
        data,
        isEmptyData,
        isTabsVisible,
        handleTabChange,
        handleView,
        handleClose,
        handleRetry,
        imagesMap,
        isMobile,
    };
};
exports.useLogic = useLogic;
