import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import { describe, expect, it, vi } from "vitest";
import { render } from "ink";
import { Writable } from "node:stream";
import { InputArea } from "./InputArea.js";
import { ThemeContext, loadTheme } from "../theme/theme.js";
const inputHandlers = [];
vi.mock("ink", async (importOriginal) => {
    const actual = await importOriginal();
    return {
        ...actual,
        useInput: (handler) => {
            inputHandlers.push(handler);
        },
        useStdin: () => ({ internal_eventEmitter: { emit: vi.fn() } }),
    };
});
vi.mock("../hooks/useTerminalSize.js", () => ({
    useTerminalSize: () => ({ columns: 100, rows: 30 }),
}));
vi.mock("./AnimationContext.js", () => ({
    deriveFrame: () => 0,
    useFocusedAnimation: () => ({ active: false, tick: 0 }),
}));
vi.mock("../../utils/image.js", () => {
    const extractImagePaths = async () => ({ imagePaths: [], cleanText: "" });
    const readImageFile = async () => ({ kind: "text", fileName: "unused", content: "" });
    return {
        extractImagePaths,
        extractMediaPaths: extractImagePaths,
        getClipboardImage: async () => null,
        readImageFile,
        readMediaFile: readImageFile,
    };
});
function renderInputArea(onSubmit = vi.fn()) {
    inputHandlers.length = 0;
    let output = "";
    const stdout = new Writable({
        write(chunk, _encoding, callback) {
            output += chunk.toString();
            callback();
        },
    });
    stdout.columns = 100;
    stdout.rows = 30;
    stdout.isTTY = true;
    stdout.getColorDepth = () => 24;
    const theme = loadTheme("dark");
    const result = render(_jsx(ThemeContext.Provider, { value: theme, children: _jsx(InputArea, { onSubmit: onSubmit, onAbort: vi.fn(), cwd: process.cwd(), disableMouseTracking: true }) }), { stdout, patchConsole: false });
    return { ...result, theme, output: () => output };
}
function enterText(text) {
    inputHandlers.at(-1)?.(text, {});
}
function pressEnter() {
    inputHandlers.at(-1)?.("", { return: true });
}
function stripAnsi(value) {
    return value.replace(new RegExp(String.raw `\u001B\[[0-?]*[ -/]*[@-~]`, "g"), "");
}
describe("InputArea pasted slash commands", () => {
    it("keeps the slash command prefix styled while a pasted placeholder is displayed and submits the original paste", async () => {
        vi.useFakeTimers();
        const onSubmit = vi.fn();
        const { rerender, theme, output } = renderInputArea(onSubmit);
        const prefix = "/help explain ";
        const pasted = "first line\nsecond line\nthird line";
        const fullInput = prefix + pasted;
        for (const char of prefix)
            enterText(char);
        enterText(pasted);
        await vi.runOnlyPendingTimersAsync();
        rerender(_jsx(ThemeContext.Provider, { value: theme, children: _jsx(InputArea, { onSubmit: onSubmit, onAbort: vi.fn(), cwd: process.cwd(), disableMouseTracking: true }) }));
        await vi.waitFor(() => {
            expect(output()).toContain("/help explain [Pasted text #33 +3 lines]");
        });
        // ANSI escapes are disabled for this captured Ink stream, but this assertion
        // fails on the original regression where the placeholder dropped the prefix.
        expect(stripAnsi(output())).toContain(" > /help explain [Pasted text #33 +3 lines]");
        pressEnter();
        const expectedPaste = { offset: prefix.length, length: pasted.length, lineCount: 3 };
        expect(onSubmit).toHaveBeenCalledWith(fullInput, [], expectedPaste);
        vi.useRealTimers();
    });
    it("paints the Gemini-style input background across the full input height", () => {
        const { output } = renderInputArea();
        const plain = stripAnsi(output());
        expect(plain).toContain("▄".repeat(100));
        expect(plain).toContain("▀".repeat(100));
        expect(plain).toContain(" >   Type your message or / to run a command");
    });
});
//# sourceMappingURL=InputArea.test.js.map