import { APPROVAL } from '../../app/approvals/types.js';
import { Container, SelectList, Spacer, Text } from '../../tui/index.js';
import { getSelectListTheme } from '../theme/theme.js';
import { Border } from './approval.js';
export class FileAccessApprovalComponent extends Container {
    optionList;
    onDone;
    constructor(data, theme, onDone, queueInfo) {
        super();
        this.onDone = onDone;
        const borderColor = (s) => theme.fg('border', s);
        const queueLabel = queueInfo
            ? theme.fg('accent', ` (${queueInfo.current}/${queueInfo.total})`)
            : '';
        const verb = data.access === 'read' ? 'Read' : 'Write';
        const options = [
            { value: APPROVAL.ALLOW_ONCE, label: 'Allow once' },
            ...(data.allowPersistentGrant
                ? [
                    {
                        value: APPROVAL.ALLOW_FILE,
                        label: `Always allow: ${data.fileGrantPath}`
                    },
                    {
                        value: APPROVAL.ALLOW_FOLDER,
                        label: `Always allow parent folder: ${data.folderGrantPath}`
                    }
                ]
                : []),
            { value: APPROVAL.REJECT, label: 'Reject' }
        ];
        this.addChild(new Border(borderColor));
        this.addChild(new Text(theme.fg('accent', ` ${verb} outside approved workspaces`) + queueLabel, 0, 0));
        this.addChild(new Spacer(1));
        this.addChild(new Text(`  ${theme.bold('Request:')} ${theme.fg('dim', data.path)}`, 0, 0));
        this.addChild(new Spacer(1));
        this.optionList = new SelectList(options, options.length, getSelectListTheme());
        this.optionList.onSelect = (item) => this.onDone(item.value);
        this.optionList.onCancel = () => this.onDone(APPROVAL.REJECT);
        this.addChild(this.optionList);
        this.addChild(new Spacer(1));
        this.addChild(new Text(theme.fg('dim', '  ↑↓ select  enter confirm  esc reject'), 0, 0));
        this.addChild(new Border(borderColor));
    }
    handleInput(keyData) {
        this.optionList.handleInput(keyData);
    }
}
//# sourceMappingURL=file-access-approval.js.map