import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2022-2025 GoodData Corporation
import { useCallback } from "react";
import { FormattedMessage } from "react-intl";
import { LoadingSpinner, SELECT_ITEM_ACTION, UiAutofocus, useListWithActionsKeyboardNavigation, } from "@gooddata/sdk-ui-kit";
import { useTheme } from "@gooddata/sdk-ui-theme-provider";
import { ScheduledEmail } from "./ScheduledEmail.js";
export function ScheduledEmails({ isLoading, scheduledEmails, onDelete, onEdit, noSchedulesMessageId, notificationChannels, }) {
    const theme = useTheme();
    const handleEdit = useCallback((scheduledEmail) => () => {
        onEdit(scheduledEmail);
    }, [onEdit]);
    const handleDelete = useCallback((scheduledEmail) => () => {
        onDelete(scheduledEmail);
    }, [onDelete]);
    const { onKeyboardNavigation, onBlur, focusedItem, focusedAction, setFocusedAction } = useListWithActionsKeyboardNavigation({
        items: scheduledEmails,
        getItemAdditionalActions: () => ["delete"],
        actionHandlers: {
            selectItem: handleEdit,
            delete: handleDelete,
        },
        isNestedList: true,
    });
    const handleKeyDown = (event) => {
        if (event.key === "ArrowRight" || event.key === "ArrowLeft")
            if (focusedAction === "delete") {
                setFocusedAction(SELECT_ITEM_ACTION);
            }
            else {
                setFocusedAction("delete");
            }
        onKeyboardNavigation(event);
    };
    if (isLoading) {
        return (_jsx("div", { className: "gd-loading-equalizer-wrap gd-notifications-channels-message", children: _jsx("div", { className: "gd-loading-equalizer gd-loading-equalizer-fade", children: _jsx(LoadingSpinner, { className: "large gd-loading-equalizer-spinner", color: theme?.palette?.complementary?.c9 }) }) }));
    }
    if (scheduledEmails.length === 0) {
        return (_jsx("div", { className: "gd-notifications-channels-message s-no-schedules-message", children: _jsx(FormattedMessage, { id: noSchedulesMessageId, values: { br: _jsx("br", {}) } }) }));
    }
    return (_jsx(UiAutofocus, { children: _jsx("div", { className: "configuration-category gd-schedule-email__list", onKeyDown: handleKeyDown, onBlur: onBlur, tabIndex: scheduledEmails.length > 0 ? 0 : -1, children: scheduledEmails.map((scheduledEmail) => (_jsx(ScheduledEmail, { scheduledEmail: scheduledEmail, focusedAction: scheduledEmail === focusedItem ? focusedAction : undefined, onDelete: onDelete, onEdit: handleEdit(scheduledEmail), notificationChannels: notificationChannels }, scheduledEmail.id))) }) }));
}
//# sourceMappingURL=ScheduledEmailsList.js.map