"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SSH_RUNTIME_PREFIX = exports.RUNTIME_MODE = void 0;
exports.parseRuntimeModeAndHost = parseRuntimeModeAndHost;
exports.buildRuntimeString = buildRuntimeString;
/** Runtime mode constants */
exports.RUNTIME_MODE = {
    LOCAL: "local",
    SSH: "ssh",
};
/** Runtime string prefix for SSH mode (e.g., "ssh hostname") */
exports.SSH_RUNTIME_PREFIX = "ssh ";
/**
 * Parse runtime string from localStorage or UI input into mode and host
 * Format: "ssh <host>" -> { mode: "ssh", host: "<host>" }
 *         "local" or undefined -> { mode: "local", host: "" }
 *
 * Use this for UI state management (localStorage, form inputs)
 */
function parseRuntimeModeAndHost(runtime) {
    if (!runtime) {
        return { mode: exports.RUNTIME_MODE.LOCAL, host: "" };
    }
    const trimmed = runtime.trim();
    const lowerTrimmed = trimmed.toLowerCase();
    if (lowerTrimmed === exports.RUNTIME_MODE.LOCAL) {
        return { mode: exports.RUNTIME_MODE.LOCAL, host: "" };
    }
    if (lowerTrimmed.startsWith(exports.SSH_RUNTIME_PREFIX)) {
        const host = trimmed.substring(exports.SSH_RUNTIME_PREFIX.length).trim();
        return { mode: exports.RUNTIME_MODE.SSH, host };
    }
    // Default to local for unrecognized strings
    return { mode: exports.RUNTIME_MODE.LOCAL, host: "" };
}
/**
 * Build runtime string for storage/IPC from mode and host
 * Returns: "ssh <host>" for SSH, undefined for local
 */
function buildRuntimeString(mode, host) {
    if (mode === exports.RUNTIME_MODE.SSH) {
        const trimmedHost = host.trim();
        return trimmedHost ? `${exports.SSH_RUNTIME_PREFIX}${trimmedHost}` : undefined;
    }
    return undefined;
}
//# sourceMappingURL=runtime.js.map