import type { LabTaskStatus, TaskSortField } from '@/types/cases';

export type TasksViewState = {
  search: string;
  clinicId: string;
  statusFilter: LabTaskStatus | '';
  stepCompleted: string;
  sortBy: TaskSortField;
  sortDir: 'asc' | 'desc';
  importantOnly: boolean;
  assignedToMe: boolean;
  overdueOnly: boolean;
  unassignedOnly: boolean;
  origin: '' | 'CLINIC_DISPATCH' | 'LAB_INTERNAL';
  prosthesisTypeCode: string;
  page: number;
  highlightTaskId: string | null;
};

export const DEFAULT_TASKS_VIEW: TasksViewState = {
  search: '',
  clinicId: '',
  statusFilter: 'IN_PROGRESS',
  stepCompleted: '',
  sortBy: 'date',
  sortDir: 'desc',
  importantOnly: false,
  assignedToMe: false,
  overdueOnly: false,
  unassignedOnly: false,
  origin: '',
  prosthesisTypeCode: '',
  page: 1,
  highlightTaskId: null,
};

export const TASK_COMPLETE_EXIT_MS = 550;

export function isDefaultTasksView(state: TasksViewState): boolean {
  return (
    state.search === DEFAULT_TASKS_VIEW.search &&
    state.clinicId === DEFAULT_TASKS_VIEW.clinicId &&
    state.statusFilter === DEFAULT_TASKS_VIEW.statusFilter &&
    state.stepCompleted === DEFAULT_TASKS_VIEW.stepCompleted &&
    state.sortBy === DEFAULT_TASKS_VIEW.sortBy &&
    state.sortDir === DEFAULT_TASKS_VIEW.sortDir &&
    state.importantOnly === DEFAULT_TASKS_VIEW.importantOnly &&
    state.assignedToMe === DEFAULT_TASKS_VIEW.assignedToMe &&
    state.overdueOnly === DEFAULT_TASKS_VIEW.overdueOnly &&
    state.unassignedOnly === DEFAULT_TASKS_VIEW.unassignedOnly &&
    state.origin === DEFAULT_TASKS_VIEW.origin &&
    state.prosthesisTypeCode === DEFAULT_TASKS_VIEW.prosthesisTypeCode &&
    state.page === DEFAULT_TASKS_VIEW.page &&
    state.highlightTaskId === DEFAULT_TASKS_VIEW.highlightTaskId
  );
}

export function buildDefaultLocateParams(taskId: string, limit: number) {
  return {
    taskId,
    limit,
    sortBy: 'date' as const,
    sortDir: 'desc' as const,
    status: 'IN_PROGRESS' as const,
  };
}
