import { type Shift } from 'src/types/shifts';
import { type LokaliseTFunction } from 'src/utils/i18n';
import { UserPermissions } from 'src/utils/permissions';
import {
  calculateTimeSpanInHours,
  parseHoursAndMinutesDisplay,
  processHoursForDisplay,
} from 'src/utils/timeTracking';

export {
  getAssignmentParams,
  getBulkDeleteParams,
  mapFilters,
  parsePreFillData,
  parseShiftTemplateData,
  type ShiftFilters,
} from './assignment';
export {
  type BuildPastePayloadsForPatternResult,
  buildPastePayload,
  buildPastePayloadsForPattern,
  calculateAffectedPasteCells,
  groupCellsByUserAndFirstDate,
  parsePasteTargetDate,
  validateCopiedCells,
  validatePasteOperation,
} from './copyPaste';
export {
  allDateCellsSelected,
  allDatesSelected,
  buildCopiedCellsWithShifts,
  calculateAffectedCounts,
  checkCellSelection,
  checkCellSelectionPromotions,
  filterCellsByCollaborators,
  filterCellsByDate,
  filterShiftsByCells,
  filterShiftsByCollaborator,
  filterShiftsByDate,
  filterShiftsByIds,
  getCellShifts,
  getCellsFromShifts,
  getUserDayData,
  validateSingleCollaboratorSelection,
} from './selection';

export { formatRotationDaysSummary } from './rotationDaysSummary';

export const processTimeSlotRange = (
  timeSlot: Shift['timeSlots'][number],
  t: LokaliseTFunction,
) => {
  const timeSlotRange = `${timeSlot.startTime} - ${timeSlot.endTime}`;
  const timeSlotDuration = calculateTimeSpanInHours(
    timeSlot.startTime,
    timeSlot.endTime,
  );
  return `${timeSlotRange} (${t(...parseHoursAndMinutesDisplay(timeSlotDuration, true))})`;
};

export const checkIfUserIsShiftManager = (permissions: string[]) =>
  permissions.includes(UserPermissions.MANAGE_SHIFTS);

export const displayProgrammedHours = (
  hourDecimal: number,
  t: LokaliseTFunction,
) => {
  const { hours, minutes } = processHoursForDisplay(hourDecimal);
  if (minutes === '00') {
    return t('time_tracking_common:hours_abbreviated', { hours });
  }
  if (hours === '00') {
    return t('time_tracking_common:hours_and_minutes_abbreviated', {
      hours,
      minutes,
    });
  }
  return t('time_tracking_common:hours_and_minutes_abbreviated', {
    hours,
    minutes,
  });
};
