// @vitest-environment happy-dom
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { act, renderHook } from '@testing-library/react';
import { useAdminRouter } from '../../router/index.js';
// Next.js 16 patches `history.pushState` and only short-circuits to the native
// implementation when the state object carries `__NA` (or `_N`). Without that
// marker it runs URL parsing that throws "Invalid URL" for the admin SPA. These
// tests pin the marker so the Next 16 admin routing regression can't reappear.
describe('useAdminRouter navigate', () => {
    let pushStateSpy;
    beforeEach(() => {
        pushStateSpy = vi.spyOn(window.history, 'pushState');
    });
    afterEach(() => {
        pushStateSpy.mockRestore();
    });
    it('marks pushState state with __NA so Next.js 16 leaves it untouched', () => {
        const { result } = renderHook(() => useAdminRouter('/admin', '/'));
        act(() => {
            result.current.navigate('/collections/posts');
        });
        expect(pushStateSpy).toHaveBeenCalledTimes(1);
        const [state, , url] = pushStateSpy.mock.calls[0];
        expect(state).toMatchObject({ adminPath: '/collections/posts', __NA: true });
        expect(url).toBe('/admin/collections/posts');
    });
    it('uses the bare basePath (with __NA) when navigating to root', () => {
        const { result } = renderHook(() => useAdminRouter('/securelogin', '/'));
        act(() => {
            result.current.navigate('/');
        });
        const [state, , url] = pushStateSpy.mock.calls[0];
        expect(state).toMatchObject({ adminPath: '/', __NA: true });
        expect(url).toBe('/securelogin');
    });
});
//# sourceMappingURL=navigate-pushstate.test.js.map