<commit_before>import { c } from 'ttag';
import { RefObject } from 'react';
import { MESSAGE_BUTTONS } from '@proton/shared/lib/constants';
import { ContextMenu, ContextSeparator, ContextMenuButton } from '@proton/components';
import { MailSettings } from '@proton/shared/lib/interfaces';
import { MARK_AS_STATUS, useMarkAs } from '../../hooks/useMarkAs';
import { useGetElementsFromIDs } from '../../hooks/mailbox/useElements';

interface Props {
    mailSettings: MailSettings;
    checkedIDs: string[];
    labelID: string;
    anchorRef: RefObject<HTMLElement>;
    isOpen: boolean;
    onBack: () => void;
    position?: {
        top: number;
        left: number;
    };
    open: () => void;
    close: () => void;
}

const ItemContextMenu = ({ checkedIDs, labelID, mailSettings, onBack, ...rest }: Props) => {
    const { MessageButtons = MESSAGE_BUTTONS.READ_UNREAD } = mailSettings;
    const markAs = useMarkAs();
    const getElementsFromIDs = useGetElementsFromIDs();

    const handleMarkAs = async (status: MARK_AS_STATUS) => {
        const isUnread = status === MARK_AS_STATUS.UNREAD;
        const elements = getElementsFromIDs(checkedIDs);
        if (isUnread) {
            onBack();
        }
        await markAs(elements, labelID, status);
    };

    const readButtons = [
        <ContextMenuButton
            testId="context-menu-read"
            icon="eye"
            name={c('Action').t`Mark as read`}
            action={() => handleMarkAs(MARK_AS_STATUS.READ)}
        />,
        <ContextMenuButton
            testId="context-menu-unread"
            icon="eye-slash"
            name={c('Action').t`Mark as unread`}
            action={() => handleMarkAs(MARK_AS_STATUS.UNREAD)}
        />,
    ];

    if (MessageButtons === MESSAGE_BUTTONS.UNREAD_READ) {
        readButtons.reverse();
    }

    return (
        <ContextMenu noMaxHeight autoClose {...rest}>
            <ContextMenuButton
                testId="context-menu-inbox"
                icon="inbox"
                name={c('Action').t`Move to inbox`}
                action={() => console.log('Inbox')}
            />
            <ContextMenuButton
                testId="context-menu-archive"
                icon="archive-box"
                name={c('Action').t`Move to archive`}
                action={() => console.log('Archive')}
            />
            <ContextMenuButton
                testId="context-menu-trash"
                icon="trash"
                name={c('Action').t`Move to trash`}
                action={() => console.log('Trash')}
            />
            <ContextMenuButton
                testId="context-menu-spam"
                icon="fire"
                name={c('Action').t`Move to spam`}
                action={() => console.log('Spam')}
            />
            <ContextSeparator />
            {readButtons}
        </ContextMenu>
    );
};

export default ItemContextMenu;<commit_msg>Add move actions<commit_after>import { c } from 'ttag';
import { RefObject } from 'react';
import { MESSAGE_BUTTONS, MAILBOX_LABEL_IDS } from '@proton/shared/lib/constants';
import { Folder } from '@proton/shared/lib/interfaces/Folder';
import { ContextMenu, ContextSeparator, ContextMenuButton } from '@proton/components';
import { Label, MailSettings } from '@proton/shared/lib/interfaces';
import { MARK_AS_STATUS, useMarkAs } from '../../hooks/useMarkAs';
import { useGetElementsFromIDs } from '../../hooks/mailbox/useElements';
import { useMoveToFolder } from '../../hooks/useApplyLabels';
import { getFolderName } from '../../helpers/labels';

interface Props {
    mailSettings: MailSettings;
    checkedIDs: string[];
    labels?: Label[];
    folders?: Folder[];
    elementID?: string;
    labelID: string;
    anchorRef: RefObject<HTMLElement>;
    isOpen: boolean;
    onBack: () => void;
    position?: {
        top: number;
        left: number;
    };
    open: () => void;
    close: () => void;
}

const ItemContextMenu = ({
    checkedIDs,
    elementID,
    labelID,
    labels = [],
    folders = [],
    mailSettings,
    onBack,
    ...rest
}: Props) => {
    const { MessageButtons = MESSAGE_BUTTONS.READ_UNREAD } = mailSettings;
    const markAs = useMarkAs();
    const moveToFolder = useMoveToFolder();
    const getElementsFromIDs = useGetElementsFromIDs();
    const labelIDs = labels.map(({ ID }) => ID);

    const handleMarkAs = async (status: MARK_AS_STATUS) => {
        const isUnread = status === MARK_AS_STATUS.UNREAD;
        const elements = getElementsFromIDs(checkedIDs);
        if (isUnread) {
            onBack();
        }
        await markAs(elements, labelID, status);
    };

    const handleMove = async (LabelID: string) => {
        const folderName = getFolderName(LabelID, folders);
        const fromLabelID = labelIDs.includes(labelID) ? MAILBOX_LABEL_IDS.INBOX : labelID;
        const elements = getElementsFromIDs(checkedIDs);
        await moveToFolder(elements, LabelID, folderName, fromLabelID);
        if (checkedIDs.includes(elementID || '')) {
            onBack();
        }
    };

    const readButtons = [
        <ContextMenuButton
            testId="context-menu-read"
            icon="eye"
            name={c('Action').t`Mark as read`}
            action={() => handleMarkAs(MARK_AS_STATUS.READ)}
        />,
        <ContextMenuButton
            testId="context-menu-unread"
            icon="eye-slash"
            name={c('Action').t`Mark as unread`}
            action={() => handleMarkAs(MARK_AS_STATUS.UNREAD)}
        />,
    ];

    if (MessageButtons === MESSAGE_BUTTONS.UNREAD_READ) {
        readButtons.reverse();
    }

    return (
        <ContextMenu noMaxHeight autoClose {...rest}>
            <ContextMenuButton
                testId="context-menu-inbox"
                icon="inbox"
                name={c('Action').t`Move to inbox`}
                action={() => handleMove(MAILBOX_LABEL_IDS.INBOX)}
            />
            <ContextMenuButton
                testId="context-menu-archive"
                icon="archive-box"
                name={c('Action').t`Move to archive`}
                action={() => handleMove(MAILBOX_LABEL_IDS.ARCHIVE)}
            />
            <ContextMenuButton
                testId="context-menu-trash"
                icon="trash"
                name={c('Action').t`Move to trash`}
                action={() => handleMove(MAILBOX_LABEL_IDS.TRASH)}
            />
            <ContextMenuButton
                testId="context-menu-spam"
                icon="fire"
                name={c('Action').t`Move to spam`}
                action={() => handleMove(MAILBOX_LABEL_IDS.SPAM)}
            />
            <ContextSeparator />
            {readButtons}
        </ContextMenu>
    );
};

export default ItemContextMenu;
{'fraction_non_alphanumeric': 0.1354810238305384, 'fraction_numerical': 0.0, 'mean_word_length': 2.1231051906293064, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1691907', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1965, 'n_words': 369}