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

const { hostRef } = vi.hoisted(() => ({ hostRef: { value: '' } }));

vi.mock('next/headers', () => ({
    headers: async () => ({ get: (k) => (k === 'host' ? hostRef.value : null) }),
}));

import { getStateInfo } from '@/lib/getStateInfo';

beforeEach(() => {
    hostRef.value = '';
});

describe('getStateInfo (server)', () => {
    it('subdomain شناخته‌شده → شهر و استان درست', async () => {
        hostRef.value = 'arak-nobat.ir';
        const { matchedCity, matchedState } = await getStateInfo();
        expect(matchedCity?.name).toBe('اراک');
        expect(matchedState?.name).toBe('مرکزی');
    });

    it('host ناشناخته → بدون تطبیق', async () => {
        hostRef.value = 'unknown-city.ir';
        const { matchedCity, matchedState } = await getStateInfo();
        expect(matchedCity).toBeUndefined();
        expect(matchedState).toBeFalsy();
    });

    it('host خالی → بدون تطبیق', async () => {
        hostRef.value = '';
        const { matchedCity } = await getStateInfo();
        expect(matchedCity).toBeUndefined();
    });
});
