import { Injectable } from '@angular/core';
import { NewAgentDialogComponent } from './new-agent-dialog.component';
import { Subject } from 'rxjs';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-dialog";
export class NewAgentDialogService {
    constructor(dialogService) {
        this.dialogService = dialogService;
        this.dialogRef = null;
    }
    /**
     * Opens the New Agent dialog
     * @param config Configuration for the dialog
     * @param viewContainerRef Optional ViewContainerRef for proper positioning
     * @returns Observable that emits the result when dialog closes
     */
    open(config = {}, viewContainerRef) {
        const resultSubject = new Subject();
        const dialogSettings = {
            title: config.parentAgentId ? 'Create Sub-Agent' : 'Create New AI Agent',
            content: NewAgentDialogComponent,
            width: 600,
            height: 600,
            minWidth: 500,
            minHeight: 500,
            preventAction: () => false
        };
        this.dialogRef = this.dialogService.open(dialogSettings);
        // Configure the component
        const component = this.dialogRef.content.instance;
        component.config = config;
        // Handle dialog result
        this.dialogRef.result.subscribe((result) => {
            if (result && result.agent) {
                resultSubject.next({ agent: result.agent, action: 'created' });
            }
            else {
                resultSubject.next({ action: 'cancelled' });
            }
            resultSubject.complete();
            this.dialogRef = null;
        });
        return resultSubject.asObservable();
    }
    /**
     * Opens the dialog to create a top-level agent
     */
    openForNewAgent(viewContainerRef) {
        return this.open({
            redirectToForm: true
        }, viewContainerRef);
    }
    /**
     * Opens the dialog to create a sub-agent
     */
    openForSubAgent(parentAgentId, parentAgentName, viewContainerRef) {
        return this.open({
            parentAgentId,
            parentAgentName,
            redirectToForm: false
        }, viewContainerRef);
    }
    /**
     * Closes the currently open dialog
     */
    close() {
        if (this.dialogRef) {
            this.dialogRef.close();
            this.dialogRef = null;
        }
    }
    /**
     * Checks if a dialog is currently open
     */
    isOpen() {
        return this.dialogRef !== null;
    }
    static { this.ɵfac = function NewAgentDialogService_Factory(t) { return new (t || NewAgentDialogService)(i0.ɵɵinject(i1.DialogService)); }; }
    static { this.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: NewAgentDialogService, factory: NewAgentDialogService.ɵfac, providedIn: 'root' }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(NewAgentDialogService, [{
        type: Injectable,
        args: [{
                providedIn: 'root'
            }]
    }], () => [{ type: i1.DialogService }], null); })();
//# sourceMappingURL=new-agent-dialog.service.js.map