import { useContext, useMemo, useRef, useState } from 'react';
import { ConfigContext } from '../../ConfigProvider';
import { useViewportType } from '../../useViewportType';
export const useLogic = ({ initialListType = 'all', unreadNotifications, notifications, onTabChange, onClose, onRetry, }) => {
    const { imagesMap } = useContext(ConfigContext);
    const { isMobile } = useViewportType();
    const [listType, setListType] = useState(initialListType);
    const viewedIds = useRef(new Set());
    const data = 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,
    };
};
