type MultiDragStateLike<TMode extends string = string> = {
  selectedAllocationIds: string[];
  multiDragDaysDelta: number;
  isMultiDragging: boolean;
  multiDragMode: TMode;
};

export function isAllocationMultiSelected<TState extends MultiDragStateLike>(
  state: TState,
  allocationId: string,
): boolean {
  return state.selectedAllocationIds.length > 1 && state.selectedAllocationIds.includes(allocationId);
}

export function startAllocationMultiDrag<TState extends MultiDragStateLike, TMode extends string>(
  state: TState,
  dragMode: TMode,
): TState {
  return {
    ...state,
    isMultiDragging: true,
    multiDragDaysDelta: 0,
    multiDragMode: dragMode,
  };
}

export function updateAllocationMultiDrag<TState extends MultiDragStateLike>(
  state: TState,
  nextDaysDelta: number,
): TState | null {
  if (nextDaysDelta === state.multiDragDaysDelta) {
    return null;
  }

  return {
    ...state,
    multiDragDaysDelta: nextDaysDelta,
  };
}

export function finalizeAllocationMultiDrag<TState extends MultiDragStateLike>(state: TState): TState {
  return {
    ...state,
    isMultiDragging: false,
    multiDragDaysDelta: 0,
  };
}
