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

const { mockDefineRouting } = vi.hoisted(() => ({
  mockDefineRouting: vi.fn((config: unknown) => config),
}));

// Mock the config module before importing routing
vi.mock('../config', () => ({
  locales: ['vi', 'en'] as const,
  defaultLocale: 'vi' as const,
}));

// Mock next-intl/routing
vi.mock('next-intl/routing', () => ({
  defineRouting: mockDefineRouting,
}));

import { routing } from '../routing';

describe('i18n/routing', () => {
  it('calls defineRouting with the correct configuration', () => {
    expect(mockDefineRouting).toHaveBeenCalledWith({
      locales: ['vi', 'en'],
      defaultLocale: 'vi',
      localePrefix: 'as-needed',
    });
  });

  it('exports a routing object', () => {
    expect(routing).toBeDefined();
  });

  it('includes all supported locales', () => {
    const routingConfig = mockDefineRouting.mock.calls[0][0] as {
      locales: readonly string[];
    };
    expect(routingConfig.locales).toEqual(['vi', 'en']);
  });

  it('sets defaultLocale to vi', () => {
    const routingConfig = mockDefineRouting.mock.calls[0][0] as {
      defaultLocale: string;
    };
    expect(routingConfig.defaultLocale).toBe('vi');
  });

  it('uses as-needed locale prefix strategy', () => {
    const routingConfig = mockDefineRouting.mock.calls[0][0] as {
      localePrefix: string;
    };
    expect(routingConfig.localePrefix).toBe('as-needed');
  });
});
