import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { TemplateSelectorDialogComponent } from './template-selector-dialog.component';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-dialog";
export class AIPromptManagementService {
    constructor(dialogService) {
        this.dialogService = dialogService;
    }
    /**
     * Opens the template selector dialog for linking existing templates to AI prompts
     */
    openTemplateSelectorDialog(config) {
        const dialogRef = this.dialogService.open({
            title: config.title,
            content: TemplateSelectorDialogComponent,
            width: 800,
            height: 600,
            minWidth: 600,
            minHeight: 400,
            preventAction: (action) => {
                // Prevent closing on backdrop click
                return action === 'close';
            }
        });
        // Configure the dialog component
        const dialogComponent = dialogRef.content.instance;
        dialogComponent.config = {
            title: config.title,
            showCreateNew: config.showCreateNew ?? true,
            extraFilter: config.extraFilter,
            multiSelect: config.multiSelect ?? false,
            selectedTemplateIds: config.selectedTemplateIds,
            showActiveOnly: config.showActiveOnly ?? true
        };
        // Create a subject to handle the result
        const resultSubject = new Subject();
        // Subscribe to the dialog component's result
        dialogComponent.result.subscribe({
            next: (result) => {
                resultSubject.next(result);
                resultSubject.complete();
            },
            error: (error) => {
                resultSubject.error(error);
            }
        });
        // Handle dialog close
        dialogRef.result.subscribe({
            next: () => {
                // Dialog was closed, emit null if no result was already emitted
                if (!resultSubject.closed) {
                    resultSubject.next(null);
                    resultSubject.complete();
                }
            },
            error: (error) => {
                if (!resultSubject.closed) {
                    resultSubject.error(error);
                }
            }
        });
        return resultSubject.asObservable();
    }
    /**
     * Opens a template creation dialog and returns the created template
     */
    openCreateTemplateDialog(config) {
        // For now, we'll return a placeholder - in a full implementation,
        // this would open a template creation dialog
        const resultSubject = new Subject();
        // Simulate async operation
        setTimeout(() => {
            resultSubject.next(null);
            resultSubject.complete();
        }, 100);
        return resultSubject.asObservable();
    }
    static { this.ɵfac = function AIPromptManagementService_Factory(t) { return new (t || AIPromptManagementService)(i0.ɵɵinject(i1.DialogService)); }; }
    static { this.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: AIPromptManagementService, factory: AIPromptManagementService.ɵfac, providedIn: 'root' }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AIPromptManagementService, [{
        type: Injectable,
        args: [{
                providedIn: 'root'
            }]
    }], () => [{ type: i1.DialogService }], null); })();
//# sourceMappingURL=ai-prompt-management.service.js.map