1 import { useCallback } from 'react';
3 import type { MARK_AS_STATUS } from '@proton/shared/lib/mail/constants';
5 import { useMarkAllAs } from 'proton-mail/hooks/actions/markAs/useMarkAllAs';
6 import { useMarkSelectionAs } from 'proton-mail/hooks/actions/markAs/useMarkSelectionAs';
8 import { isMessage as testIsMessage } from '../../../helpers/elements';
9 import type { Element } from '../../../models/element';
11 export interface MarkAsParams {
14 status: MARK_AS_STATUS;
17 onCheckAll?: (check: boolean) => void;
19 export const useMarkAs = () => {
20 const markSelectionAs = useMarkSelectionAs();
21 const { markAllAs, selectAllMarkModal } = useMarkAllAs();
23 const markAs = useCallback(
24 async ({ elements, labelID = '', status, silent = true, selectAll, onCheckAll }: MarkAsParams) => {
25 if (!elements.length) {
29 const isMessage = testIsMessage(elements[0]);
32 await markAllAs({ isMessage, labelID, status, onCheckAll });
34 void markSelectionAs({
43 [markAllAs, markSelectionAs]
46 return { markAs, selectAllMarkModal };