export const adminNotificationsListener = (echo, userData, setNotifications, setUnreadNotification, updatePendingMembers) => {
    if (userData.isAdmin) {
        const channelName = "users.admin";

        const handleNotification = (id, content) => {
            const newNotification = {
                id,
                content,
                created_at: new Date().toISOString(),
                pivot: { unread: 1 }
            };
            setNotifications(prev => [newNotification, ...prev]);
            setUnreadNotification(true);
        };

        echo.private(channelName)
            .listen(".users.registration", (event) => {
                handleNotification(event.notificationId, `Nouvelle demande d'inscription : ${event.user.name} ${event.user.lastname}`);
                updatePendingMembers();
            });
        return channelName;
    }
    return null;
};