import Alert from '@material-hu/components/design-system/Alert';

import { useLokaliseTranslation } from 'src/utils/i18n';

import { type SessionBasicInformation } from '../../types';
import { isOldLocalDate, isOldStartTime } from '../../utils';

type BeforeTodayAlertProps = Pick<
  SessionBasicInformation,
  'startTime' | 'localDate' | 'timeZone'
>;

const BeforeTodayAlert = ({
  startTime,
  localDate,
  timeZone,
}: BeforeTodayAlertProps) => {
  const { t } = useLokaliseTranslation('learning');

  if (isOldLocalDate({ localDate, timeZone })) {
    return (
      <Alert
        severity="info"
        title={t('validations:date_is_before_today')}
        description={t('session.date.local_date.before_today')}
      />
    );
  }

  if (isOldStartTime({ startTime, timeZone })) {
    return (
      <Alert
        severity="info"
        title={t('validations:hour.start_hour_is_before_now')}
        description={t('session.date.start_hour.before_today')}
      />
    );
  }

  return null;
};

export default BeforeTodayAlert;
