"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotificationList = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const Button_1 = require("../Button");
const ContentState_1 = require("../ContentState");
const SideDialogHeader_1 = require("../SideDialogHeader");
const cva_1 = require("../utils/cva");
const constants_1 = require("./constants");
const Empty_1 = require("./Empty");
const ListItem_1 = require("./ListItem");
const MobileNotificationSkeleton_1 = require("./MobileNotificationSkeleton");
const SettingsButton_1 = require("./SettingsButton");
const styles_1 = require("./styles");
const Tabs_1 = require("./Tabs");
const useLogic_1 = require("./useLogic");
const rootCva = (0, cva_1.cva)(constants_1.notificationListClassnames.root, {
    variants: {
        hasUnreadNotifications: {
            true: constants_1.notificationListClassnames.hasUnreadNotifications,
        },
        isError: {
            true: constants_1.notificationListClassnames.error,
        },
        isLoading: {
            true: constants_1.notificationListClassnames.loading,
        },
    },
});
const NotificationList = ({ isOpen, title = 'Уведомления', isLoading, isError, errorMessage, notifications, unreadNotifications, initialListType, headerContent, footerContent, isSettingsButtonVisible = true, onClose, onDelete, onSettingsButtonClick, onTabChange, onRetry, }) => {
    const { listType, data, isEmptyData, isTabsVisible, handleTabChange, handleView, handleClose, handleRetry, imagesMap, isMobile, } = (0, useLogic_1.useLogic)({
        initialListType,
        unreadNotifications,
        notifications,
        onTabChange,
        onClose,
        onRetry,
    });
    return ((0, jsx_runtime_1.jsxs)(styles_1.StyledSideDialog, { open: isOpen, onClose: handleClose, className: rootCva({
            hasUnreadNotifications: isTabsVisible,
            isError,
            isLoading,
        }), children: [(0, jsx_runtime_1.jsxs)(SideDialogHeader_1.SideDialogHeader, { title: title, onClose: handleClose, justifyContent: "flex-end", children: [headerContent, isSettingsButtonVisible && ((0, jsx_runtime_1.jsx)(SettingsButton_1.SettingsButton, { onClick: onSettingsButtonClick }))] }), (0, jsx_runtime_1.jsxs)(ContentState_1.ContentState, { isLoading: isLoading, isError: isError, loadingContent: isMobile && (0, jsx_runtime_1.jsx)(MobileNotificationSkeleton_1.MobileNotificationSkeleton, {}), loadingPlaceholderClassname: constants_1.notificationListClassnames.loadingPlaceholder, errorState: {
                    imgAlt: '',
                    errorList: [errorMessage || ''],
                    onRetry: handleRetry,
                    imgSrc: imagesMap.defaultErrorImgSrc,
                    actions: ((0, jsx_runtime_1.jsx)(Button_1.Button, { color: "grey", variant: "light", onClick: handleRetry, children: "\u041F\u043E\u043F\u0440\u043E\u0431\u043E\u0432\u0430\u0442\u044C \u0441\u043D\u043E\u0432\u0430" })),
                }, children: [isTabsVisible && ((0, jsx_runtime_1.jsx)(styles_1.TabsWrapper, { children: (0, jsx_runtime_1.jsx)(Tabs_1.Tabs, { onChange: handleTabChange, listType: listType, notificationsCount: notifications.length, unreadNotificationsCount: unreadNotifications?.length || 0 }) })), (0, jsx_runtime_1.jsx)(styles_1.ContentWrapper, { children: isEmptyData ? ((0, jsx_runtime_1.jsx)(Empty_1.Empty, { listType: listType, noDataImgSrc: imagesMap.noDataImgSrc })) : ((0, jsx_runtime_1.jsx)(styles_1.List, { children: data.map((notification) => ((0, jsx_runtime_1.jsx)(ListItem_1.ListItem, { ...notification, onDelete: onDelete, onViewNotification: handleView, isDeleteButtonVisible: Boolean(onDelete) }, notification.id))) })) })] }), footerContent && ((0, jsx_runtime_1.jsx)(styles_1.StyledSideDialogActions, { children: footerContent }))] }));
};
exports.NotificationList = NotificationList;
