import { RootState } from './types'

export const deriveStatusIconColor = ({
    syncState,
    backupState,
}: RootState): 'green' | 'red' | 'yellow' => {
    if (syncState === 'error' || backupState === 'error') {
        return 'red'
    }

    if (syncState === 'disabled' && backupState === 'disabled') {
        return 'yellow'
    }

    return 'green'
}

import moment from 'moment'

import type { RootState } from './types'

export const deriveStatusIconColor = ({
    syncState,
    backupState,
    lastSuccessfulSyncDate,
}: RootState): 'green' | 'red' | 'yellow' => {
    const daysSinceLastSync = moment().diff(
        moment(lastSuccessfulSyncDate),
        'days',
    )

    if (
        syncState === 'error' ||
        daysSinceLastSync > 7 ||
        backupState === 'error'
    ) {
        return 'red'
    }

    if (
        (syncState === 'disabled' || daysSinceLastSync > 3) &&
        backupState === 'disabled'
    ) {
        return 'yellow'
    }

    return 'green'
}

Update sync/backup status indicator conditions
Update sync/backup status indicator conditions

- yellow if last sync > 3 days ago
- red if last sync > 7 days ago
