import { jsx as _jsx } from "react/jsx-runtime";
// @vitest-environment happy-dom
import { afterEach, describe, expect, it } from 'vitest';
import { cleanup, render, screen } from '@testing-library/react';
import { ConfirmDangerousSettingDialog } from '../../views/settings/components.js';
import { adminPortalContainer } from '../../lib/portal-container.js';
/**
 * Regression: theme tokens only exist under `.actuate-admin` (theme.css), so
 * Radix portals must mount INSIDE that scope. Portaling to document.body
 * (Radix's default) produced unstyled overlays — transparent cards, colorless
 * destructive buttons, broken dark mode.
 */
afterEach(cleanup);
function renderInAdminRoot(ui) {
    const root = document.createElement('div');
    root.className = 'actuate-admin';
    document.body.appendChild(root);
    return render(ui, { container: root });
}
describe('adminPortalContainer', () => {
    it('resolves the admin root element', () => {
        const root = document.createElement('div');
        root.className = 'actuate-admin';
        document.body.appendChild(root);
        expect(adminPortalContainer()).toBe(root);
        root.remove();
    });
    it('returns undefined when no admin root is mounted', () => {
        document.querySelectorAll('.actuate-admin').forEach((el) => el.remove());
        expect(adminPortalContainer()).toBeUndefined();
    });
});
describe('portaled overlays mount inside the admin theme scope', () => {
    it('renders the dangerous-setting confirm dialog within .actuate-admin', async () => {
        renderInAdminRoot(_jsx(ConfirmDangerousSettingDialog, { open: true, title: "Block this production site from search engines?", description: "This may prevent search engines from indexing your production site.", confirmLabel: "Enable No Index", onConfirm: () => { }, onCancel: () => { } }));
        const title = await screen.findByText(/Block this production site/);
        // The dialog content must live inside the token scope, otherwise
        // bg-card / text-warning / bg-destructive resolve to nothing.
        expect(title.closest('.actuate-admin')).not.toBeNull();
    });
});
//# sourceMappingURL=portal-container.test.js.map