export function parseRemoteChatCommand(text) {
    const trimmed = text.trim();
    const lowered = trimmed.toLowerCase();
    if (lowered === 'y' || lowered === 'yes') {
        return { kind: 'approve-default' };
    }
    if (lowered === 'n' || lowered === 'no') {
        return { kind: 'deny-default' };
    }
    const [head, ...rest] = trimmed.split(/\s+/);
    switch (head.toLowerCase()) {
        case '/desktops':
            return { kind: 'desktops' };
        case '/desktop':
            return { kind: 'desktop', desktopId: rest[0] };
        case '/sessions':
            return { kind: 'sessions' };
        case '/attach':
            return { kind: 'attach', sessionId: rest[0] };
        case '/new':
            return { kind: 'new' };
        case '/interrupt':
            return { kind: 'interrupt' };
        case '/approve':
            return { kind: 'approve', approvalId: rest[0] ?? '' };
        case '/deny':
            return { kind: 'deny', approvalId: rest[0] ?? '' };
        case '/help':
        case '/start':
        case '/pair':
            return { kind: 'help' };
        default:
            return { kind: 'prompt', message: trimmed };
    }
}
export function formatRemoteSessionList(sessions) {
    if (sessions.length === 0) {
        return 'No local sessions found on this desktop.';
    }
    return [
        'Sessions:',
        ...sessions.map((session) => {
            const title = session.name?.trim() || session.id;
            const marker = session.isCurrent ? ' [current]' : '';
            return `- ${title}${marker}\n  /attach ${session.id}\n  ${session.lastMessage || session.cwd}`;
        })
    ].join('\n');
}
export function formatBrokerDesktopList(desktops) {
    if (desktops.length === 0) {
        return 'No live ShortcutXL desktop sessions are currently registered.';
    }
    return [
        'ShortcutXL desktop sessions:',
        ...desktops.map((desktop) => {
            const title = desktop.sessionName?.trim() || desktop.sessionId;
            const marker = desktop.isActiveTarget ? ' [phone target]' : '';
            const state = desktop.isStreaming ? 'streaming' : 'idle';
            return `- ${title}${marker}\n  /desktop ${desktop.desktopId}\n  ${state} • ${desktop.cwd}`;
        })
    ].join('\n');
}
export function formatRemoteAttachResult(result) {
    switch (result.kind) {
        case 'attached':
            return result.snapshot.pendingApprovals.length > 0
                ? `Attached. ${result.snapshot.pendingApprovals.length} approval(s) are pending.`
                : 'Attached to the requested session.';
        case 'desktops':
            return formatBrokerDesktopList(result.desktops);
        case 'desktop_selected':
            return `Phone control switched to ${result.desktop.sessionName?.trim() || result.desktop.sessionId}.`;
        case 'desktop_missing':
            return `Desktop ${result.desktopId} was not found.`;
        case 'no_desktops':
            return 'No live ShortcutXL desktop sessions are currently registered.';
        case 'picker':
            return formatRemoteSessionList(result.sessions);
        case 'create':
            return 'No existing sessions were found. Use /new to create one.';
        case 'not_found':
            return `Session ${result.requestedSessionId} was not found.`;
        case 'cancelled':
            return 'Attach was cancelled.';
        default:
            return `Unexpected result: ${result.kind}`;
    }
}
//# sourceMappingURL=chat-commands.js.map