import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
import { Emitter } from '../../../../../base/common/event.js';
import { Disposable } from '../../../../../base/common/lifecycle.js';
import { localizeWithPath } from '../../../../../nls.js';
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
import { ChatConfirmationWidget } from './chatConfirmationWidget.js';
import { IChatService } from '../../common/chatService.service.js';
import { isResponseVM } from '../../common/chatViewModel.js';
const _moduleId = "vs/workbench/contrib/chat/browser/chatContentParts/chatConfirmationContentPart";
let ChatConfirmationContentPart = class ChatConfirmationContentPart extends Disposable {
    constructor(confirmation, context, instantiationService, chatService) {
        super();
        this.instantiationService = instantiationService;
        this.chatService = chatService;
        this._onDidChangeHeight = this._register(( (new Emitter())));
        this.onDidChangeHeight = this._onDidChangeHeight.event;
        const element = context.element;
        const confirmationWidget = this._register(this.instantiationService.createInstance(ChatConfirmationWidget, confirmation.title, confirmation.message, [
            { label: ( localizeWithPath(_moduleId, 0, "Accept")), data: confirmation.data },
            { label: ( localizeWithPath(_moduleId, 1, "Dismiss")), data: confirmation.data, isSecondary: true },
        ]));
        confirmationWidget.setShowButtons(!confirmation.isUsed);
        this._register(confirmationWidget.onDidClick(async (e) => {
            if (isResponseVM(element)) {
                const prompt = `${e.label}: "${confirmation.title}"`;
                const data = e.isSecondary ?
                    { rejectedConfirmationData: [e.data] } :
                    { acceptedConfirmationData: [e.data] };
                data.agentId = element.agent?.id;
                data.slashCommand = element.slashCommand?.name;
                if (await this.chatService.sendRequest(element.sessionId, prompt, data)) {
                    confirmation.isUsed = true;
                    confirmationWidget.setShowButtons(false);
                    this._onDidChangeHeight.fire();
                }
            }
        }));
        this.domNode = confirmationWidget.domNode;
    }
    hasSameContent(other) {
        return other.kind === 'confirmation';
    }
    addDisposable(disposable) {
        this._register(disposable);
    }
};
ChatConfirmationContentPart = ( (__decorate([
    ( (__param(2, IInstantiationService))),
    ( (__param(3, IChatService)))
], ChatConfirmationContentPart)));
export { ChatConfirmationContentPart };
