import React, { useMemo } from 'react'; import dayjs from 'dayjs'; import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'; import { useTranslation } from 'react-i18next'; import isEmpty from 'lodash-es/isEmpty'; import { useSelectedDateContext } from '../hooks/selected-date-context'; import styles from './metrics-card.scss'; dayjs.extend(isSameOrBefore); interface MetricsCardProps { label: string; value: number; headerLabel: string; count?: { pendingAppointments: Array; arrivedAppointments: Array }; } const MetricsCard: React.FC = ({ label, value, headerLabel, count }) => { const { t } = useTranslation(); const { selectedDate } = useSelectedDateContext(); const isSelectedDateInPast = useMemo(() => dayjs(selectedDate).isBefore(dayjs(), 'date'), [selectedDate]); return (
{headerLabel}
{label}

{value}

{!isEmpty(count) && (
{t('checkedIn', 'Checked in')} {isSelectedDateInPast ? t('missed', 'Missed') : t('notArrived', 'Not arrived')}

{count.arrivedAppointments?.length}

{count.pendingAppointments?.length}

)}
); }; export default MetricsCard;