import { describe, expect, it } from 'vitest';
import {
  getClimateScrollProjection,
  getHeatTimelineMarkers,
  HEAT_TIMELINE_YEARS,
} from './climateScrollProjection';

const zone = {
  tempMoyEstivale: 26.5,
  tempMoyEstivale10ans: 28,
  tempMoyEstivale20ans: 29.5,
  joursSup30C: 20,
  joursSup30C10ans: 30,
  joursSup30C20ans: 42,
};

describe('getClimateScrollProjection', () => {
  it('interpolates year, temperature, and hot days continuously from 2026 to 2046', () => {
    expect(getClimateScrollProjection(zone, 0)).toMatchObject({
      year: 2026,
      temp: 26.5,
      days: 20,
      dayDelta: 0,
    });

    expect(getClimateScrollProjection(zone, 0.5)).toMatchObject({
      year: 2036,
      temp: 28,
      days: 30,
      dayDelta: 10,
    });

    expect(getClimateScrollProjection(zone, 1)).toMatchObject({
      year: 2046,
      temp: 29.5,
      days: 42,
      dayDelta: 22,
    });
  });

  it('clamps progress outside the 0-1 range', () => {
    expect(getClimateScrollProjection(zone, -1).year).toBe(2026);
    expect(getClimateScrollProjection(zone, 2).year).toBe(2046);
  });

  it('provides timeline markers for every five years plus the final year', () => {
    expect(HEAT_TIMELINE_YEARS.map((item) => item.year)).toEqual([2026, 2031, 2036, 2041, 2046]);
  });

  it('computes hot-day deltas for every editorial timeline marker', () => {
    const markers = getHeatTimelineMarkers(zone);

    expect(markers.map((item) => ({
      year: item.year,
      days: item.projection.days,
      dayDelta: item.projection.dayDelta,
      temp: item.projection.temp,
    }))).toEqual([
      { year: 2026, days: 20, dayDelta: 0, temp: 26.5 },
      { year: 2031, days: 25, dayDelta: 5, temp: 27.3 },
      { year: 2036, days: 30, dayDelta: 10, temp: 28 },
      { year: 2041, days: 36, dayDelta: 16, temp: 28.8 },
      { year: 2046, days: 42, dayDelta: 22, temp: 29.5 },
    ]);
  });
});
