import { jsx as _jsx } from "react/jsx-runtime";
import { beforeAll, afterAll, describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/react';
import { ThemeProvider } from '../../theme';
import { ChatInput } from '../ChatDialog/components/ChatInput';
const baseProps = {
    inputValue: '',
    inputHistory: [],
    placeholder: 'Type a message…',
    isInputDisabled: false,
    isStreaming: false,
    isSubmissionDisabled: false,
    isSending: false,
    onInputChange: () => { },
    attachments: [],
    onAttachmentsAdd: () => { },
    onAttachmentRemove: () => { },
    slashCommandOptions: [],
    onSlashCommandStateChange: () => { }
};
const renderWithTheme = (props = {}) => {
    return render(_jsx(ThemeProvider, { initialThemeName: 'light', children: _jsx(ChatInput, { ...baseProps, ...props }) }));
};
beforeAll(() => {
    vi.stubGlobal('requestAnimationFrame', (callback) => {
        return setTimeout(() => callback(performance.now()), 0);
    });
    vi.stubGlobal('cancelAnimationFrame', (handle) => {
        clearTimeout(handle);
    });
});
afterAll(() => {
    vi.unstubAllGlobals();
});
describe('ChatInput', () => {
    it('shows the send button when idle', () => {
        renderWithTheme({ inputValue: 'Hello world' });
        const sendButton = screen.getByRole('button', { name: 'Send' });
        expect(sendButton.getAttribute('disabled')).toBeNull();
    });
    it('renders a cancel button while sending and invokes handler on click', () => {
        const handleCancel = vi.fn();
        renderWithTheme({ isSending: true, onCancelSend: handleCancel, canCancel: true });
        const cancelButton = screen.getByRole('button', { name: 'Cancel' });
        expect(cancelButton.getAttribute('disabled')).toBeNull();
        fireEvent.click(cancelButton);
        expect(handleCancel).toHaveBeenCalledTimes(1);
    });
    it('disables the cancel button and updates label while cancelling', () => {
        renderWithTheme({
            isSending: true,
            onCancelSend: () => { },
            canCancel: true,
            isCancelling: true
        });
        const cancellingButton = screen.getByRole('button', { name: 'Cancelling…' });
        expect(cancellingButton.getAttribute('disabled')).not.toBeNull();
    });
});
