<commit_before>import { c } from 'ttag';
import { MNEMONIC_STATUS } from '@proton/shared/lib/interfaces';

import getOverallStatus from '../containers/recovery/getOverallStatus';
import { FeatureCode } from '../containers/features/FeaturesContext';
import { NotificationDotColor } from '../components/notificationDot/NotificationDot';
import getLikelyHasKeysToReactivate from '../containers/keys/reactivateKeys/getLikelyHasKeysToReactivate';

import useRecoveryStatus from './useRecoveryStatus';
import useIsDataRecoveryAvailable from './useIsDataRecoveryAvailable';
import useUser from './useUser';
import useAddresses from './useAddresses';
import useFeature from './useFeature';
import useIsRecoveryFileAvailable from './useIsRecoveryFileAvailable';
import useIsMnemonicAvailable from './useIsMnemonicAvailable';
import useHasOutdatedRecoveryFile from './useHasOutdatedRecoveryFile';

const useRecoveryNotification = (
    isLessInvasive: boolean
): { path: string; text: string; color: NotificationDotColor } | undefined => {
    const { feature: hasVisitedRecoveryPage } = useFeature(FeatureCode.VisitedRecoveryPage);
    const [user] = useUser();
    const [addresses, loadingAddresses] = useAddresses();

    const [{ accountRecoveryStatus, dataRecoveryStatus, mnemonicIsSet }, loadingRecoveryStatus] = useRecoveryStatus();

    const [isRecoveryFileAvailable, loadingIsRecoveryFileAvailable] = useIsRecoveryFileAvailable();
    const [isMnemonicAvailable, loadingIsMnemonicAvailable] = useIsMnemonicAvailable();
    const [isDataRecoveryAvailable, loadingIsDataRecoveryAvailable] = useIsDataRecoveryAvailable();
    const hasOutdatedRecoveryFile = useHasOutdatedRecoveryFile();
    const hasKeysToReactivate = getLikelyHasKeysToReactivate(user, addresses);

    const overallStatus = getOverallStatus({ accountRecoveryStatus, dataRecoveryStatus, isDataRecoveryAvailable });

    const loading =
        loadingRecoveryStatus ||
        loadingIsRecoveryFileAvailable ||
        loadingIsMnemonicAvailable ||
        loadingIsDataRecoveryAvailable ||
        loadingAddresses;
    if (loading) {
        return;
    }

    if (!isDataRecoveryAvailable) {
        return;
    }

    const hasOutdatedMnemonic = user.MnemonicStatus === MNEMONIC_STATUS.OUTDATED;
    if (isMnemonicAvailable && hasOutdatedMnemonic) {
        return {
            path: '/recovery#data',
            text: c('Action').t`Update recovery phrase`,
            color: 'danger',
        };
    }

    if (isRecoveryFileAvailable && hasOutdatedRecoveryFile) {
        return {
            path: '/recovery#data',
            text: c('Action').t`Update recovery file`,
            color: 'danger',
        };
    }

    if (isLessInvasive && hasVisitedRecoveryPage?.Value === true) {
        return;
    }

    if (hasKeysToReactivate) {
        return {
            path: '/recovery?action=recover-data',
            text: c('Action').t`Unlock data`,
            color: 'danger',
        };<commit_msg>Include shortcircuit when hasVisitedRecoveryPage is undefined in useRecoveryNotification<commit_after>import { c } from 'ttag';
import { MNEMONIC_STATUS } from '@proton/shared/lib/interfaces';

import getOverallStatus from '../containers/recovery/getOverallStatus';
import { FeatureCode } from '../containers/features/FeaturesContext';
import { NotificationDotColor } from '../components/notificationDot/NotificationDot';
import getLikelyHasKeysToReactivate from '../containers/keys/reactivateKeys/getLikelyHasKeysToReactivate';

import useRecoveryStatus from './useRecoveryStatus';
import useIsDataRecoveryAvailable from './useIsDataRecoveryAvailable';
import useUser from './useUser';
import useAddresses from './useAddresses';
import useFeature from './useFeature';
import useIsRecoveryFileAvailable from './useIsRecoveryFileAvailable';
import useIsMnemonicAvailable from './useIsMnemonicAvailable';
import useHasOutdatedRecoveryFile from './useHasOutdatedRecoveryFile';

const useRecoveryNotification = (
    isLessInvasive: boolean
): { path: string; text: string; color: NotificationDotColor } | undefined => {
    const { feature: hasVisitedRecoveryPage } = useFeature(FeatureCode.VisitedRecoveryPage);
    const [user] = useUser();
    const [addresses, loadingAddresses] = useAddresses();

    const [{ accountRecoveryStatus, dataRecoveryStatus, mnemonicIsSet }, loadingRecoveryStatus] = useRecoveryStatus();

    const [isRecoveryFileAvailable, loadingIsRecoveryFileAvailable] = useIsRecoveryFileAvailable();
    const [isMnemonicAvailable, loadingIsMnemonicAvailable] = useIsMnemonicAvailable();
    const [isDataRecoveryAvailable, loadingIsDataRecoveryAvailable] = useIsDataRecoveryAvailable();
    const hasOutdatedRecoveryFile = useHasOutdatedRecoveryFile();
    const hasKeysToReactivate = getLikelyHasKeysToReactivate(user, addresses);

    const overallStatus = getOverallStatus({ accountRecoveryStatus, dataRecoveryStatus, isDataRecoveryAvailable });

    const loading =
        loadingRecoveryStatus ||
        loadingIsRecoveryFileAvailable ||
        loadingIsMnemonicAvailable ||
        loadingIsDataRecoveryAvailable ||
        loadingAddresses;
    if (loading) {
        return;
    }

    if (!isDataRecoveryAvailable) {
        return;
    }

    const hasOutdatedMnemonic = user.MnemonicStatus === MNEMONIC_STATUS.OUTDATED;
    if (isMnemonicAvailable && hasOutdatedMnemonic) {
        return {
            path: '/recovery#data',
            text: c('Action').t`Update recovery phrase`,
            color: 'danger',
        };
    }

    if (isRecoveryFileAvailable && hasOutdatedRecoveryFile) {
        return {
            path: '/recovery#data',
            text: c('Action').t`Update recovery file`,
            color: 'danger',
        };
    }

    if (isLessInvasive && hasVisitedRecoveryPage?.Value !== false) {
        return;
    }

    if (hasKeysToReactivate) {
        return {
            path: '/recovery?action=recover-data',
            text: c('Action').t`Unlock data`,
            color: 'danger',
        };
{'fraction_non_alphanumeric': 0.10033112582781457, 'fraction_numerical': 0.0, 'mean_word_length': 3.9843234323432344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1687171', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1620, 'n_words': 337}