<commit_before>import React from 'react';
import { Location } from 'history';
import {
    Icon,
    useLoading,
    useNotifications,
    useEventManager,
    useApi,
    ConfirmModal,
    ErrorButton,
    useModals,
    Alert
} from 'react-components';
import { MAILBOX_LABEL_IDS } from 'proton-shared/lib/constants';
import { deleteMessages } from 'proton-shared/lib/api/messages';
import { deleteConversations } from 'proton-shared/lib/api/conversations';
import { c, msgid } from 'ttag';

import ToolbarButton from './ToolbarButton';
import { getCurrentType } from '../../helpers/elements';
import { ELEMENT_TYPES } from '../../constants';
import { MailSettings } from 'proton-shared/lib/interfaces';
import { Breakpoints } from '../../models/utils';
import { labelIncludes } from '../../helpers/labels';

const { TRASH, SPAM, DRAFTS, ALL_DRAFTS, SENT, ALL_SENT } = MAILBOX_LABEL_IDS;

interface Props {
    labelID: string;
    mailSettings: MailSettings;
    breakpoints: Breakpoints;
    selectedIDs: string[];
    location: Location;
}

const DeleteButton = ({ labelID = '', mailSettings, breakpoints, selectedIDs = [], location }: Props) => {
    const { createNotification } = useNotifications();
    const { createModal } = useModals();
    const { call } = useEventManager();
    const api = useApi();
    const [loading, withLoading] = useLoading();
    const type = getCurrentType({ mailSettings, labelID, location });

    const displayDelete =
        labelIncludes(labelID, TRASH, SPAM, DRAFTS, ALL_DRAFTS, SENT, ALL_SENT) &&
        (!breakpoints.isNarrow || !labelIncludes(labelID, SENT, ALL_SENT));

    const handleDelete = async () => {
        await new Promise((resolve, reject) => {
            createModal(
                <ConfirmModal
                    title={c('Title').ngettext(msgid`Delete email`, `Delete emails`, selectedIDs.length)}
                    confirm={(<ErrorButton type="submit" icon={null}>{c('Action').t`Delete`}</ErrorButton>) as any}
                    onConfirm={resolve}
                    onClose={reject}
                >
                    <Alert type="warning">
                        {c('Info').ngettext(
                            msgid`This action will permanently delete the selected email. Are you sure you want to delete this email?`,
                            `This action will permanently delete the selected emails. Are you sure you want to delete these emails?`,
                            selectedIDs.length
                        )}
                    </Alert>
                </ConfirmModal>
            );
        });
        const action = type === ELEMENT_TYPES.CONVERSATION ? deleteConversations : deleteMessages;
        await api(action(selectedIDs));
        await call();
        createNotification({ text: c('Success').t`Elements deleted` });
    };

    if (!displayDelete) {
        return null;
    }

    return (
        <ToolbarButton
            loading={loading}
            title={c('Action').t`Delete`}
            onClick={() => withLoading(handleDelete())}
            disabled={!selectedIDs.length}
        >
            <Icon className="toolbar-icon mauto" name="delete" />
        </ToolbarButton>
    );
};

export default DeleteButton;<commit_msg>Review tooltip for delete button<commit_after>import React from 'react';
import { Location } from 'history';
import {
    Icon,
    useLoading,
    useNotifications,
    useEventManager,
    useApi,
    ConfirmModal,
    ErrorButton,
    useModals,
    Alert
} from 'react-components';
import { MAILBOX_LABEL_IDS } from 'proton-shared/lib/constants';
import { deleteMessages } from 'proton-shared/lib/api/messages';
import { deleteConversations } from 'proton-shared/lib/api/conversations';
import { c, msgid } from 'ttag';

import ToolbarButton from './ToolbarButton';
import { getCurrentType } from '../../helpers/elements';
import { ELEMENT_TYPES } from '../../constants';
import { MailSettings } from 'proton-shared/lib/interfaces';
import { Breakpoints } from '../../models/utils';
import { labelIncludes } from '../../helpers/labels';

const { TRASH, SPAM, DRAFTS, ALL_DRAFTS, SENT, ALL_SENT } = MAILBOX_LABEL_IDS;

interface Props {
    labelID: string;
    mailSettings: MailSettings;
    breakpoints: Breakpoints;
    selectedIDs: string[];
    location: Location;
}

const DeleteButton = ({ labelID = '', mailSettings, breakpoints, selectedIDs = [], location }: Props) => {
    const { createNotification } = useNotifications();
    const { createModal } = useModals();
    const { call } = useEventManager();
    const api = useApi();
    const [loading, withLoading] = useLoading();
    const type = getCurrentType({ mailSettings, labelID, location });

    const displayDelete =
        labelIncludes(labelID, TRASH, SPAM, DRAFTS, ALL_DRAFTS, SENT, ALL_SENT) &&
        (!breakpoints.isNarrow || !labelIncludes(labelID, SENT, ALL_SENT));

    const handleDelete = async () => {
        await new Promise((resolve, reject) => {
            createModal(
                <ConfirmModal
                    title={c('Title').ngettext(msgid`Delete email`, `Delete emails`, selectedIDs.length)}
                    confirm={(<ErrorButton type="submit" icon={null}>{c('Action').t`Delete`}</ErrorButton>) as any}
                    onConfirm={resolve}
                    onClose={reject}
                >
                    <Alert type="warning">
                        {c('Info').ngettext(
                            msgid`This action will permanently delete the selected email. Are you sure you want to delete this email?`,
                            `This action will permanently delete the selected emails. Are you sure you want to delete these emails?`,
                            selectedIDs.length
                        )}
                    </Alert>
                </ConfirmModal>
            );
        });
        const action = type === ELEMENT_TYPES.CONVERSATION ? deleteConversations : deleteMessages;
        await api(action(selectedIDs));
        await call();
        createNotification({ text: c('Success').t`Elements deleted` });
    };

    if (!displayDelete) {
        return null;
    }

    return (
        <ToolbarButton
            loading={loading}
            title={c('Action').t`Delete permanently`}
            onClick={() => withLoading(handleDelete())}
            disabled={!selectedIDs.length}
        >
            <Icon className="toolbar-icon mauto" name="delete" />
        </ToolbarButton>
    );
};

export default DeleteButton;
{'fraction_non_alphanumeric': 0.12414003974927382, 'fraction_numerical': 0.0, 'mean_word_length': 2.425130890052356, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 29, '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': '6718880', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1759, 'n_words': 440}