"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PollingTmuxTransport = void 0;
exports.getPollingTmuxTransport = getPollingTmuxTransport;
const tmux_1 = require("./tmux");
const POLLING_TMUX_CAPABILITIES = {
    streamingOutput: false,
    explicitResize: false,
    snapshotFallback: true,
};
class NoopSubscription {
    async unsubscribe() {
        return;
    }
}
class PollingTmuxTransport {
    async ensureSession(sessionName, cwd) {
        const exists = await (0, tmux_1.hasSession)(sessionName);
        if (!exists) {
            await (0, tmux_1.createSession)(sessionName, cwd);
        }
    }
    async sessionExists(sessionName) {
        return (0, tmux_1.hasSession)(sessionName);
    }
    async sendInput(sessionName, input) {
        await (0, tmux_1.sendKeys)(sessionName, input);
    }
    async sendSpecialKey(sessionName, key) {
        if (key !== 'Escape' && key !== 'C-c' && key !== 'C-d' && key !== 'C-m' && key !== 'Enter') {
            throw new Error(`Unsupported special key for PollingTmuxTransport: ${key}`);
        }
        await (0, tmux_1.sendSpecialKey)(sessionName, key);
    }
    async resize() {
        throw new Error('PollingTmuxTransport does not support explicit resize');
    }
    async captureSnapshot(sessionName, opts) {
        return (0, tmux_1.capturePane)(sessionName, opts);
    }
    async subscribe() {
        return new NoopSubscription();
    }
    getCapabilities() {
        return POLLING_TMUX_CAPABILITIES;
    }
    async killSession(sessionName) {
        return (0, tmux_1.killSession)(sessionName);
    }
}
exports.PollingTmuxTransport = PollingTmuxTransport;
let pollingTmuxTransportSingleton = null;
function getPollingTmuxTransport() {
    if (!pollingTmuxTransportSingleton) {
        pollingTmuxTransportSingleton = new PollingTmuxTransport();
    }
    return pollingTmuxTransportSingleton;
}
