import { describe, expect, it } from 'vitest';

import { parseOperationalFilters } from '@/lib/services/reports/operational-filters';

function params(qs: string): URLSearchParams {
  return new URLSearchParams(qs);
}

describe('parseOperationalFilters', () => {
  it('returns undefined when no area param is present', () => {
    expect(parseOperationalFilters(params(''))).toBeUndefined();
    expect(parseOperationalFilters(params('from=x&to=y'))).toBeUndefined();
  });

  it('parses a single area', () => {
    expect(parseOperationalFilters(params('area=A'))).toEqual({ areas: ['A'] });
  });

  it('parses a CSV of areas and trims whitespace', () => {
    expect(parseOperationalFilters(params('area=A,%20B%20,C'))).toEqual({
      areas: ['A', 'B', 'C'],
    });
  });

  it('drops empty / whitespace-only entries, returning undefined when nothing is left', () => {
    expect(parseOperationalFilters(params('area=%20,%20'))).toBeUndefined();
    expect(parseOperationalFilters(params('area='))).toBeUndefined();
  });
});
