/** LocalStorage key for tracking coachmark completion */
export const SHIFTS_COACHMARK_STORAGE_KEY = 'shifts_coachmark_completed';

/** Element IDs for coachmark step targeting */
export const COACHMARK_ELEMENT_IDS = {
  actionButtons: 'shifts-coachmark-action-buttons',
  firstShift: 'shifts-coachmark-first-shift',
  emptyCell: 'shifts-coachmark-empty-cell',
  copyOption: 'shifts-coachmark-copy-option',
};

/** ID of the mock shift that will be highlighted in the coachmark */
export const COACHMARK_MOCK_SHIFT_ID = 99999;

/** Mock user ID used in coachmark data */
export const COACHMARK_MOCK_USER_ID = 99999;

import {
  ShiftCalendarDay,
  ShiftCalendarUser,
  ShiftColor,
} from 'src/types/shifts';
import { ScheduleSource } from 'src/types/timeTracking';
import { useLokaliseTranslation } from 'src/utils/i18n';

/**
 * Generate mock data for the shifts table during coachmark.
 * Creates a user with shifts for the current week.
 */
export const generateCoachmarkMockData = (
  startDate: string,
  endDate: string,
): ShiftCalendarUser[] => {
  // Generate days between start and end date
  const days: Record<string, ShiftCalendarDay> = {};
  const start = new Date(startDate);
  const end = new Date(endDate);
  const { t } = useLokaliseTranslation(['shifts']);

  let dayIndex = 0;
  for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
    const dateKey = d.toISOString().split('T')[0];
    const isFirstDay = dayIndex === 0;

    days[dateKey] = {
      daySummaryHours: {
        scheduled: isFirstDay ? 8 : 0,
        worked: 0,
        estimated: 0,
        timeOff: null,
      },
      scheduledData: {
        isWorkday: true,
        scheduleSource: 'SHIFT' as ScheduleSource,
        shiftAssignedDayId: dayIndex + 1000,
        timeSlots: [],
      },
      shiftScheduledHours: {
        published: isFirstDay ? 8 : 0,
        draft: 0,
        total: isFirstDay ? 8 : 0,
      },
      shifts: isFirstDay
        ? [
            {
              code: 'MOCK-001',
              color: ShiftColor.BLUE,
              description: '',
              id: COACHMARK_MOCK_SHIFT_ID,
              instanceId: 1,
              isCustom: false,
              isHalfDayRest: false,
              isRest: false,
              lastVersion: true,
              name: t('shifts:coachmark.mock_shift_name'),
              shiftAssignedShiftId: COACHMARK_MOCK_SHIFT_ID,
              timeSlots: [
                {
                  id: 1,
                  shiftId: COACHMARK_MOCK_SHIFT_ID,
                  startTime: '08:00',
                  endTime: '16:00',
                },
              ],
              version: 1,
            },
          ]
        : [],
      timeOffs: [],
      holidays: [],
    };
    dayIndex++;
  }

  // Generate empty days for other users
  const emptyDays: Record<string, ShiftCalendarDay> = {};
  for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
    const dateKey = d.toISOString().split('T')[0];
    emptyDays[dateKey] = {
      daySummaryHours: {
        scheduled: 0,
        worked: 0,
        estimated: 0,
        timeOff: null,
      },
      scheduledData: {
        isWorkday: true,
        scheduleSource: 'SHIFT' as ScheduleSource,
        shiftAssignedDayId: 0,
        timeSlots: [],
      },
      shiftScheduledHours: {
        published: 0,
        draft: 0,
        total: 0,
      },
      shifts: [],
      timeOffs: [],
      holidays: [],
    };
  }

  return [
    {
      userId: COACHMARK_MOCK_USER_ID,
      employeeInternalId: 'MOCK-USER-001',
      fullName: 'Aaron Gutierres',
      profilePicture: null,
      days,
      shiftScheduleHours: {
        published: 8,
        draft: 0,
        total: 8,
      },
    },
    {
      userId: 99998,
      employeeInternalId: 'MOCK-USER-002',
      fullName: 'Jessica González',
      profilePicture: null,
      days: { ...emptyDays },
      shiftScheduleHours: {
        published: 0,
        draft: 0,
        total: 0,
      },
    },
    {
      userId: 99997,
      employeeInternalId: 'MOCK-USER-003',
      fullName: 'José Pergolani',
      profilePicture: null,
      days: { ...emptyDays },
      shiftScheduleHours: {
        published: 0,
        draft: 0,
        total: 0,
      },
    },
    {
      userId: 99996,
      employeeInternalId: 'MOCK-USER-004',
      fullName: 'Aurelio Alberti',
      profilePicture: null,
      days: { ...emptyDays },
      shiftScheduleHours: {
        published: 0,
        draft: 0,
        total: 0,
      },
    },
    {
      userId: 99995,
      employeeInternalId: 'MOCK-USER-005',
      fullName: 'Carolina Pérez',
      profilePicture: null,
      days: { ...emptyDays },
      shiftScheduleHours: {
        published: 0,
        draft: 0,
        total: 0,
      },
    },
    {
      userId: 99994,
      employeeInternalId: 'MOCK-USER-006',
      fullName: 'Miguel Solé',
      profilePicture: null,
      days: { ...emptyDays },
      shiftScheduleHours: {
        published: 0,
        draft: 0,
        total: 0,
      },
    },
  ];
};
