import { IconBell, IconBellOff, IconPin, IconPinnedOff } from "@tabler/icons-react";
import { useContextMenu } from "../providers/ContextMenuProvider/useContextMenu"
import { useRosettaColors } from "./useRosettaColors";
import { useDialogState } from "../providers/DialogStateProvider.tsx/useDialogState";

export function useDialogContextMenu() : {
    openContextMenu: (dialog_id: string) => void;
} {
    const openContext = useContextMenu();
    const colors = useRosettaColors();
    const {muted, pinned, muteToggle, pinToggle} = useDialogState();

    const openContextMenu = (dialog_id: string) => {
        openContext([
            {
                label: 'Unmute',
                action: () => {
                    muteToggle(dialog_id);
                },
                icon: <IconBell color={colors.success} size={14}></IconBell>,
                cond: async () => {
                    return muted.includes(dialog_id) === true;
                }
            },
            {
                label: 'Mute',
                action: () => {
                    muteToggle(dialog_id);
                },
                icon: <IconBellOff color={colors.error} size={14}></IconBellOff>,
                cond: async () => {
                    return muted.includes(dialog_id) === false;
                }
            },
           {
                label: 'Pin',
                action: () => {
                    pinToggle(dialog_id);
                },
                icon: <IconPin color={colors.success} size={14}></IconPin>,
                cond: async () => {
                    return pinned.includes(dialog_id) === false;
                }
            },
            {
                label: 'Unpin',
                action: () => {
                    pinToggle(dialog_id);
                },
                icon: <IconPinnedOff color={colors.error} size={14}></IconPinnedOff>,
                cond: async () => {
                    return pinned.includes(dialog_id) === true;
                }   
            }
        ], true, true);
    }
    return {
        openContextMenu
    }
}