import { type DaySummary, type TimeOffRequest } from 'src/types/timeTracking';
import { type LokaliseTFunction } from 'src/utils/i18n';
import {
  formatCompleteDecimalHours,
  type parseDayScheduleStatus,
} from 'src/utils/timeTracking';

import {
  ACTIVITY,
  CONSUMPTION,
  HOLIDAY_TYPE,
  TIME_OFF_TYPE,
} from '../constants';

export const getTimeOffCardDescription = (
  request: TimeOffRequest,
  isPeriod: boolean,
  t: LokaliseTFunction,
) => {
  if (request.activityType === ACTIVITY.WORK) {
    if (isPeriod) return t('time_tracker:time_off_period_workable_description');
    return t('time_tracker:time_off_workable_description');
  }
  switch (request.consumptionType) {
    case CONSUMPTION.HOURS:
      return t('time_tracker:time_off_hours_card_description');
    case CONSUMPTION.HALF_DAY:
      return t('time_tracker:time_off_half_day_card_description');
    case CONSUMPTION.FULL_DAY:
      if (isPeriod) return t('time_tracker:time_off_period_card_description');
      return t('time_tracker:time_off_full_day_card_description');
    default:
      return t('time_tracker:time_off_full_day_card_description');
  }
};

export const getSubtitle = (
  day: DaySummary,
  dayStatus: ReturnType<typeof parseDayScheduleStatus>,
  t: LokaliseTFunction,
) => {
  if (dayStatus.holiday?.type === HOLIDAY_TYPE) return dayStatus.holiday.name;

  if (dayStatus.isScheduledDayOff) return t('time_tracker:day_off');

  if (dayStatus.holiday?.type === TIME_OFF_TYPE) {
    if (day.estimatedHours > 0) {
      return `${formatCompleteDecimalHours(day.estimatedHours)} ${t('time_tracker:programmed').toLowerCase()}`;
    }
    return '';
  }

  if (day.isWorkday && day.scheduledHours > 0) {
    return `${formatCompleteDecimalHours(day.scheduledHours)} ${t('time_tracker:programmed').toLowerCase()}`;
  }

  return '';
};
