import { jsx as _jsx } from "react/jsx-runtime";
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, fireEvent, render } from '@testing-library/react';
import { ThemeProvider } from '../../../theme';
import { Drawer } from '../Drawer';
const renderWithTheme = (props = {}) => {
    const onClose = props.onClose ?? vi.fn();
    const result = render(_jsx(ThemeProvider, { initialThemeName: 'light', children: _jsx(Drawer, { isOpen: false, onClose: onClose, ...props, children: _jsx("div", { children: "Drawer content" }) }) }));
    return {
        onClose,
        ...result
    };
};
afterEach(() => {
    cleanup();
});
describe('Drawer', () => {
    it('renders children regardless of open state', () => {
        const { getByText, rerender, onClose } = renderWithTheme({ isOpen: false });
        expect(getByText('Drawer content')).toBeDefined();
        rerender(_jsx(ThemeProvider, { initialThemeName: 'light', children: _jsx(Drawer, { isOpen: true, onClose: onClose, children: _jsx("div", { children: "Drawer content" }) }) }));
        expect(getByText('Drawer content')).toBeDefined();
    });
    it('invokes onClose when overlay is clicked', () => {
        const { container, onClose } = renderWithTheme({ isOpen: true });
        const overlay = container.querySelector('div[aria-hidden="true"]');
        expect(overlay).toBeTruthy();
        if (overlay) {
            fireEvent.click(overlay);
        }
        expect(onClose).toHaveBeenCalledTimes(1);
    });
    it('invokes onClose when Escape key is pressed', () => {
        const { onClose } = renderWithTheme({ isOpen: true });
        fireEvent.keyDown(window, { key: 'Escape' });
        expect(onClose).toHaveBeenCalledTimes(1);
    });
});
