import { useEffect, useRef } from "react";
import { useStdout } from "ink";
export function useTerminalTitle({ isRunning, sessionTitle }) {
    const { stdout } = useStdout();
    // Track previous title to avoid redundant writes
    const prevTitleRef = useRef("");
    // Write terminal title
    useEffect(() => {
        if (!stdout)
            return;
        let title;
        if (sessionTitle) {
            title = isRunning ? `● ${sessionTitle}` : sessionTitle;
        }
        else {
            title = "EZ Coder";
        }
        if (title !== prevTitleRef.current) {
            prevTitleRef.current = title;
            stdout.write(`\x1b]0;${title}\x1b\\`);
        }
    }, [stdout, isRunning, sessionTitle]);
    // Reset title on unmount
    useEffect(() => {
        return () => {
            stdout?.write(`\x1b]0;EZ Coder\x1b\\`);
        };
    }, [stdout]);
}
//# sourceMappingURL=useTerminalTitle.js.map