import * as geolib from 'geolib';
import { handleTurnAtFix } from '../pathGenerators/handleTurnAtFix.ts';
import { computeSpeed } from '../utils/computeSpeed.ts';

export const TerminatorsFM = (
  leg: FMTerminalEntry,
  previousFix: NavFix,
  lastCourse: number
): [NavFix?, LineSegment[]?] => {
  const speed = computeSpeed(leg, previousFix);

  const endpoint = geolib.computeDestinationPoint(previousFix, (10).toMetre(), leg.Course.toTrue(previousFix));

  const line = handleTurnAtFix(
    leg.Course.toTrue(previousFix),
    leg.Course.toTrue(previousFix),
    lastCourse,
    previousFix,
    endpoint,
    speed,
    leg.TurnDir
  );

  return [undefined, line];
};
