import type { DraftStatKey } from "../../hooks/legacySessionTypes";
import {
  LEGACY_STAT_DEFINITIONS,
  type LegacyStatDefinition,
  type LegacyTrajectoryStep,
} from "../../legacy/interop.js";

export interface LegacyAllocationFieldDefinition {
  id: DraftStatKey;
  label: string;
  min: number;
  max: number;
}

export interface LegacyTrajectoryAutoplayOption {
  label: string;
  speed: number;
}

function isDraftStatDefinition(
  definition: LegacyStatDefinition,
): definition is LegacyStatDefinition & { id: DraftStatKey } {
  return definition.id !== "SPR";
}

export const LEGACY_ALLOCATION_FIELDS: LegacyAllocationFieldDefinition[] =
  LEGACY_STAT_DEFINITIONS.filter(isDraftStatDefinition).map(
    ({ id, label, min, max }) => ({
      id,
      label,
      min,
      max,
    }),
  );

export const LEGACY_TRAJECTORY_AUTOPLAY_OPTIONS: LegacyTrajectoryAutoplayOption[] =
  [
    { label: "Auto 1x", speed: 800 },
    { label: "Auto 2x", speed: 400 },
  ];

export function getLegacyTrajectoryStatusLabel(
  step: LegacyTrajectoryStep,
): string {
  return step.isEnd ? "Run ended" : "In progress";
}
