import { jsx as _jsx } from "react/jsx-runtime";
// @vitest-environment happy-dom
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
/**
 * Regression: the shared no-op "Save Changes" footer (driven by the settings
 * global `handleSave`) must only render on tabs that actually persist through
 * it (currently just Layout). On self-managed tabs like SEO it used to render a
 * SECOND footer whose click toasted "Settings saved successfully!" while
 * persisting none of the tab's edits — misleading, no-op UI.
 *
 * The SEO tab now owns a real `SettingsSaveBar` (also labelled "Save Changes")
 * that persists through `/seo/config`, so the contract is: exactly ONE
 * "Save Changes" button on the SEO tab — the tab's own — never the global one
 * stacked on top of it.
 */
const SEO_CONFIG = {
    static: { site: null },
    overrides: { site: {}, collections: {} },
    effective: { site: { siteUrl: 'https://example.com' } },
    collections: [],
};
const cmsApi = vi.fn(async (endpoint, options) => {
    const method = options?.method ?? 'GET';
    if (endpoint === '/globals/settings' && method === 'GET') {
        return { data: { siteTitle: 'Actuate Media' }, status: 200 };
    }
    if (endpoint === '/seo/config' && method === 'GET') {
        return { data: SEO_CONFIG, status: 200 };
    }
    if (endpoint.startsWith('/collections/')) {
        return { data: { docs: [] }, status: 200 };
    }
    return { data: {}, status: 200 };
});
vi.mock('../../lib/api.js', () => ({ cmsApi: (e, o) => cmsApi(e, o) }));
const { Settings } = await import('../../views/Settings.js');
const LAYOUT_CONFIG = {
    layout: { regions: { header: { collection: 'headers', label: 'Header' } } },
};
const SESSION = { user: { role: 'ADMIN' } };
beforeEach(() => {
    cmsApi.mockClear();
});
describe('Settings shared save footer', () => {
    it("renders only the SEO tab's own save bar, not the global footer on top", async () => {
        render(_jsx(Settings, { config: LAYOUT_CONFIG, session: SESSION, initialTab: "seo" }));
        // The Advanced disclosure still mounts the per-collection SEO panel, which
        // owns its own persistence ("Save SEO defaults").
        expect((await screen.findAllByRole('button', { name: 'Save SEO defaults' })).length).toBeGreaterThan(0);
        // The tab's own SettingsSaveBar is the ONLY "Save Changes" button — the
        // no-op global footer must not be stacked on top of it.
        expect(screen.getAllByRole('button', { name: 'Save Changes' })).toHaveLength(1);
    });
    it('renders the global "Save Changes" footer on the Layout tab', async () => {
        render(_jsx(Settings, { config: LAYOUT_CONFIG, session: SESSION, initialTab: "layout" }));
        await waitFor(() => expect(screen.getByRole('button', { name: 'Save Changes' })).toBeTruthy());
    });
});
//# sourceMappingURL=settings-save-footer.render.test.js.map