/**
 * Bash-specific approval component.
 *
 * Shows the command to be executed with an
 * ApprovalButtonBar for Accept / Reject.
 *
 * Shell commands are always explicit-only in the runtime permission model,
 * so this surface never offers "Accept All".
 *
 * When `connections` are present, shows a credential warning.
 */
import { Container, Spacer, Text } from '../../tui/index.js';
import { ApprovalButtonBar, Border } from './approval.js';
export class BashApprovalComponent extends Container {
    buttonBar;
    onDone;
    constructor(data, theme, onDone, queueInfo) {
        super();
        this.onDone = onDone;
        const borderColor = (s) => theme.fg('border', s);
        const hasConnections = (data.connections?.length ?? 0) > 0;
        const hasHighRiskOperations = (data.highRiskOperations?.length ?? 0) > 0;
        this.addChild(new Border(borderColor));
        // Header
        const queueLabel = queueInfo
            ? theme.fg('accent', ` (${queueInfo.current}/${queueInfo.total})`)
            : '';
        if (hasHighRiskOperations) {
            this.addChild(new Text(theme.fg('warning', ' ⚠ Run high-risk shell command') + queueLabel, 0, 0));
            this.addChild(new Spacer(1));
            for (const operation of data.highRiskOperations) {
                this.addChild(new Text(`  ${theme.bold(operation.label)}: ${operation.reason}`, 0, 0));
            }
            this.addChild(new Text(theme.fg('dim', '  This requires explicit one-time approval.'), 0, 0));
        }
        else if (hasConnections) {
            const connList = data.connections.join(', ');
            this.addChild(new Text(theme.fg('warning', ' ⚠ Run connection-backed shell command') + queueLabel, 0, 0));
            this.addChild(new Spacer(1));
            this.addChild(new Text(`  Credentials for: ${theme.bold(connList)}`, 0, 0));
            this.addChild(new Text(theme.fg('dim', '  Code can access and exfiltrate these credentials.'), 0, 0));
        }
        else {
            const header = data.description
                ? theme.fg('accent', ' Run shell command') +
                    queueLabel +
                    theme.fg('dim', ' – ') +
                    data.description
                : theme.fg('accent', ' Run shell command') + queueLabel;
            this.addChild(new Text(header, 0, 0));
        }
        this.addChild(new Spacer(1));
        // Show bash command
        this.addChild(new Text('  ' + theme.fg('dim', data.command), 0, 0));
        this.addChild(new Spacer(1));
        this.buttonBar = new ApprovalButtonBar(theme, undefined, true);
        this.addChild(this.buttonBar.getContainer());
        this.addChild(new Border(borderColor));
    }
    handleInput(keyData) {
        const choice = this.buttonBar.handleInput(keyData);
        if (choice)
            this.onDone(choice);
    }
}
//# sourceMappingURL=bash-approval.js.map