import { expect, test } from 'bun:test';
import { fixture } from '../habits/test-fixture';
import { toResponsiveCalendarProps } from './calendar';
test('Nivo adapter preserves per-date colors, neutral/future states and readable exact counts', async () => {
  const f = fixture();
  try {
    const h = await f.json('/habits', 'POST', { name: 'Water', method: 'count', target: 8 }, 201);
    await f.json(`/habits/${h.id}/days/2026-09-04/progress`, 'PUT', { count: 7 });
    f.setTime('2026-09-05T12:00Z'); await f.json(`/habits/${h.id}`, 'PATCH', { target: 10 });
    await f.json(`/habits/${h.id}/days/2026-09-05/progress`, 'PUT', { count: 7 });
    const payload = await f.json(`/habits/${h.id}/calendar?from=2026-09-03&to=2026-09-06`);
    const props = toResponsiveCalendarProps(payload);
    expect(props.data).toHaveLength(4);
    expect(props.colorScale(1)).not.toBe(props.colorScale(2));
    expect(props.colorScale(0)).toBe(payload.settings.notDueColor); expect(props.colorScale(3)).toBe(payload.settings.futureColor);
    expect(props.valueFormat(0)).toBe('Nothing scheduled'); expect(props.valueFormat(1)).toBe('7 of 8 steps');
    expect(props.valueFormat(2)).toBe('7 of 10 steps'); expect(props.valueFormat(3)).toBe('Upcoming');
    expect(props.valueFormat(99)).toBe(''); expect(props.colorScale(99)).toBe(payload.settings.notDueColor); expect(props.colorScale.ticks()).toEqual([]);
    const c = await f.json('/charts', 'POST', { name: 'One', habitIds: [h.id] }, 201);
    const combined = await f.json(`/charts/${c.id}/calendar?from=2026-09-04&to=2026-09-04`);
    expect(toResponsiveCalendarProps(combined).valueFormat(0)).toBe('0 of 1 habits complete');
  } finally { f.close(); }
});
