import { Component } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Subject, BehaviorSubject, takeUntil } from 'rxjs';
import { Metadata, RunView } from '@memberjunction/core';
import { MJNotificationService } from '@memberjunction/ng-notifications';
import { UUIDsEqual } from '@memberjunction/global';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-dialog";
import * as i2 from "./ai-agent-management.service";
import * as i3 from "@angular/forms";
import * as i4 from "@angular/common";
const _forTrack0 = ($index, $item) => $item.ID;
function CreateSubAgentDialogComponent_Conditional_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "p", 4);
    i0.ɵɵelement(1, "i", 11);
    i0.ɵɵtext(2, " Sub-agent of: ");
    i0.ɵɵelementStart(3, "strong");
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate(ctx_r0.config.parentAgentName);
} }
function CreateSubAgentDialogComponent_Conditional_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 5);
    i0.ɵɵelement(1, "i", 12);
    i0.ɵɵelementStart(2, "span");
    i0.ɵɵtext(3, "Loading sub-agent creation form...");
    i0.ɵɵelementEnd()();
} }
function CreateSubAgentDialogComponent_Conditional_8_For_17_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "option", 23);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const type_r3 = ctx.$implicit;
    i0.ɵɵproperty("value", type_r3.ID);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(type_r3.Name);
} }
function CreateSubAgentDialogComponent_Conditional_8_Conditional_108_For_2_Conditional_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 68);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const prompt_r5 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(prompt_r5.Description);
} }
function CreateSubAgentDialogComponent_Conditional_8_Conditional_108_For_2_Template(rf, ctx) { if (rf & 1) {
    const _r4 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 65)(1, "div", 66);
    i0.ɵɵelement(2, "i", 57);
    i0.ɵɵelementStart(3, "span", 67);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(5, CreateSubAgentDialogComponent_Conditional_8_Conditional_108_For_2_Conditional_5_Template, 2, 1, "span", 68);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "button", 69);
    i0.ɵɵlistener("click", function CreateSubAgentDialogComponent_Conditional_8_Conditional_108_For_2_Template_button_click_6_listener() { const prompt_r5 = i0.ɵɵrestoreView(_r4).$implicit; const ctx_r0 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r0.removePrompt(prompt_r5)); });
    i0.ɵɵelement(7, "i", 9);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const prompt_r5 = ctx.$implicit;
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate(prompt_r5.Name);
    i0.ɵɵadvance();
    i0.ɵɵconditional(prompt_r5.Description ? 5 : -1);
} }
function CreateSubAgentDialogComponent_Conditional_8_Conditional_108_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 62);
    i0.ɵɵrepeaterCreate(1, CreateSubAgentDialogComponent_Conditional_8_Conditional_108_For_2_Template, 8, 2, "div", 65, _forTrack0);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵrepeater(ctx_r0.linkedPrompts);
} }
function CreateSubAgentDialogComponent_Conditional_8_Conditional_109_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 63);
    i0.ɵɵelement(1, "i", 57);
    i0.ɵɵelementStart(2, "p");
    i0.ɵɵtext(3, "No prompts added yet. Click the buttons above to add prompts.");
    i0.ɵɵelementEnd()();
} }
function CreateSubAgentDialogComponent_Conditional_8_Conditional_118_For_2_Conditional_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 68);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const action_r7 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(action_r7.Description);
} }
function CreateSubAgentDialogComponent_Conditional_8_Conditional_118_For_2_Template(rf, ctx) { if (rf & 1) {
    const _r6 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 70)(1, "div", 66);
    i0.ɵɵelement(2, "i", 64);
    i0.ɵɵelementStart(3, "span", 67);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(5, CreateSubAgentDialogComponent_Conditional_8_Conditional_118_For_2_Conditional_5_Template, 2, 1, "span", 68);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "button", 69);
    i0.ɵɵlistener("click", function CreateSubAgentDialogComponent_Conditional_8_Conditional_118_For_2_Template_button_click_6_listener() { const action_r7 = i0.ɵɵrestoreView(_r6).$implicit; const ctx_r0 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r0.removeAction(action_r7)); });
    i0.ɵɵelement(7, "i", 9);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const action_r7 = ctx.$implicit;
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate(action_r7.Name);
    i0.ɵɵadvance();
    i0.ɵɵconditional(action_r7.Description ? 5 : -1);
} }
function CreateSubAgentDialogComponent_Conditional_8_Conditional_118_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 62);
    i0.ɵɵrepeaterCreate(1, CreateSubAgentDialogComponent_Conditional_8_Conditional_118_For_2_Template, 8, 2, "div", 70, _forTrack0);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵrepeater(ctx_r0.linkedActions);
} }
function CreateSubAgentDialogComponent_Conditional_8_Conditional_119_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 63);
    i0.ɵɵelement(1, "i", 64);
    i0.ɵɵelementStart(2, "p");
    i0.ɵɵtext(3, "No actions added yet. Click the button above to add actions.");
    i0.ɵɵelementEnd()();
} }
function CreateSubAgentDialogComponent_Conditional_8_Template(rf, ctx) { if (rf & 1) {
    const _r2 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "form", 6)(1, "div", 13)(2, "h3", 14);
    i0.ɵɵelement(3, "i", 15);
    i0.ɵɵtext(4, " Basic Information ");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "div", 16)(6, "div", 17)(7, "label", 18);
    i0.ɵɵtext(8, "Name *");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(9, "input", 19);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(10, "div", 17)(11, "label", 20);
    i0.ɵɵtext(12, "Type *");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(13, "select", 21)(14, "option", 22);
    i0.ɵɵtext(15, "Select agent type...");
    i0.ɵɵelementEnd();
    i0.ɵɵrepeaterCreate(16, CreateSubAgentDialogComponent_Conditional_8_For_17_Template, 2, 2, "option", 23, _forTrack0);
    i0.ɵɵpipe(18, "async");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(19, "div", 16)(20, "div", 17)(21, "label", 24);
    i0.ɵɵtext(22, "Description");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(23, "textarea", 25);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(24, "div", 16)(25, "div", 17)(26, "label", 26);
    i0.ɵɵtext(27, "Status");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(28, "select", 27)(29, "option", 28);
    i0.ɵɵtext(30, "Pending");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(31, "option", 29);
    i0.ɵɵtext(32, "Active");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(33, "option", 30);
    i0.ɵɵtext(34, "Disabled");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(35, "div", 17)(36, "label", 31);
    i0.ɵɵtext(37, "Execution Mode");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(38, "select", 32)(39, "option", 33);
    i0.ɵɵtext(40, "Sequential");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(41, "option", 34);
    i0.ɵɵtext(42, "Parallel");
    i0.ɵɵelementEnd()()()()();
    i0.ɵɵelementStart(43, "div", 13)(44, "h3", 14);
    i0.ɵɵelement(45, "i", 35);
    i0.ɵɵtext(46, " Purpose & Messages ");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(47, "div", 16)(48, "div", 17)(49, "label", 36);
    i0.ɵɵtext(50, "Purpose");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(51, "input", 37);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(52, "div", 16)(53, "div", 17)(54, "label", 38);
    i0.ɵɵtext(55, "User Message");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(56, "textarea", 39);
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(57, "div", 13)(58, "h3", 14);
    i0.ɵɵelement(59, "i", 40);
    i0.ɵɵtext(60, " Model Configuration ");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(61, "div", 16)(62, "div", 17)(63, "label", 41);
    i0.ɵɵtext(64, "Model Selection Mode");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(65, "select", 42)(66, "option", 43);
    i0.ɵɵtext(67, "Agent Type");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(68, "option", 44);
    i0.ɵɵtext(69, "Agent");
    i0.ɵɵelementEnd()()()();
    i0.ɵɵelementStart(70, "div", 16)(71, "div", 17)(72, "label", 45);
    i0.ɵɵtext(73, "Temperature");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(74, "input", 46);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(75, "div", 17)(76, "label", 47);
    i0.ɵɵtext(77, "Top P");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(78, "input", 48);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(79, "div", 16)(80, "div", 17)(81, "label", 49);
    i0.ɵɵtext(82, "Top K");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(83, "input", 50);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(84, "div", 17)(85, "label", 51);
    i0.ɵɵtext(86, "Max Tokens");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(87, "input", 52);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(88, "div", 16)(89, "div", 17)(90, "label", 53);
    i0.ɵɵelement(91, "input", 54);
    i0.ɵɵtext(92, " Enable Caching ");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(93, "div", 17)(94, "label", 55);
    i0.ɵɵtext(95, "Cache TTL (seconds)");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(96, "input", 56);
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(97, "div", 13)(98, "h3", 14);
    i0.ɵɵelement(99, "i", 57);
    i0.ɵɵtext(100);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(101, "div", 58)(102, "button", 59);
    i0.ɵɵlistener("click", function CreateSubAgentDialogComponent_Conditional_8_Template_button_click_102_listener() { i0.ɵɵrestoreView(_r2); const ctx_r0 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r0.addPrompt()); });
    i0.ɵɵelement(103, "i", 60);
    i0.ɵɵtext(104, " Add Existing Prompt ");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(105, "button", 61);
    i0.ɵɵlistener("click", function CreateSubAgentDialogComponent_Conditional_8_Template_button_click_105_listener() { i0.ɵɵrestoreView(_r2); const ctx_r0 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r0.createNewPrompt()); });
    i0.ɵɵelement(106, "i", 60);
    i0.ɵɵtext(107, " Create New Prompt ");
    i0.ɵɵelementEnd()();
    i0.ɵɵconditionalCreate(108, CreateSubAgentDialogComponent_Conditional_8_Conditional_108_Template, 3, 0, "div", 62)(109, CreateSubAgentDialogComponent_Conditional_8_Conditional_109_Template, 4, 0, "div", 63);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(110, "div", 13)(111, "h3", 14);
    i0.ɵɵelement(112, "i", 64);
    i0.ɵɵtext(113);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(114, "div", 58)(115, "button", 59);
    i0.ɵɵlistener("click", function CreateSubAgentDialogComponent_Conditional_8_Template_button_click_115_listener() { i0.ɵɵrestoreView(_r2); const ctx_r0 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r0.addAction()); });
    i0.ɵɵelement(116, "i", 60);
    i0.ɵɵtext(117, " Add Action ");
    i0.ɵɵelementEnd()();
    i0.ɵɵconditionalCreate(118, CreateSubAgentDialogComponent_Conditional_8_Conditional_118_Template, 3, 0, "div", 62)(119, CreateSubAgentDialogComponent_Conditional_8_Conditional_119_Template, 4, 0, "div", 63);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("formGroup", ctx_r0.subAgentForm);
    i0.ɵɵadvance(16);
    i0.ɵɵrepeater(i0.ɵɵpipeBind1(18, 5, ctx_r0.availableAgentTypes$));
    i0.ɵɵadvance(84);
    i0.ɵɵtextInterpolate1(" Prompts (", ctx_r0.linkedPromptCount, ") ");
    i0.ɵɵadvance(8);
    i0.ɵɵconditional(ctx_r0.linkedPrompts.length > 0 ? 108 : 109);
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate1(" Actions (", ctx_r0.linkedActionCount, ") ");
    i0.ɵɵadvance(5);
    i0.ɵɵconditional(ctx_r0.linkedActions.length > 0 ? 118 : 119);
} }
function CreateSubAgentDialogComponent_Conditional_16_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 12);
    i0.ɵɵtext(1, " Creating... ");
} }
function CreateSubAgentDialogComponent_Conditional_18_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 71);
    i0.ɵɵtext(1, " Create Sub-Agent ");
} }
/**
 * Dialog for creating new AI Sub-Agents with essential fields, actions, and prompts management.
 * Creates entities but does not save them - returns entities for parent to add to PendingRecords.
 * This ensures atomicity with the parent form's save operation.
 */
export class CreateSubAgentDialogComponent {
    constructor(dialogRef, cdr, agentManagementService, viewContainerRef) {
        this.dialogRef = dialogRef;
        this.cdr = cdr;
        this.agentManagementService = agentManagementService;
        this.viewContainerRef = viewContainerRef;
        // Configuration
        this.config = {};
        // State management
        this.destroy$ = new Subject();
        this.result = new Subject();
        this.isLoading$ = new BehaviorSubject(false);
        this.isSaving$ = new BehaviorSubject(false);
        // Data
        this.availableAgentTypes$ = new BehaviorSubject([]);
        this.availablePrompts$ = new BehaviorSubject([]);
        this.availableActions$ = new BehaviorSubject([]);
        // Entities (not saved to database)
        this.subAgentEntity = null;
        this.linkedPrompts = [];
        this.linkedActions = [];
        // Link entities for database relationships
        this.agentPromptLinks = [];
        this.agentActionLinks = [];
        // Storage for new entities created within dialog
        this.newlyCreatedPrompts = [];
        this.newlyCreatedPromptTemplates = [];
        this.newlyCreatedTemplateContents = [];
        this.subAgentForm = this.createForm();
    }
    ngOnInit() {
        this.loadInitialData();
        this.setupFormWatching();
    }
    ngOnDestroy() {
        this.destroy$.next();
        this.destroy$.complete();
    }
    createForm() {
        return new FormGroup({
            name: new FormControl(this.config.initialName || '', [Validators.required]),
            description: new FormControl(''),
            typeID: new FormControl(this.config.initialTypeID || '', [Validators.required]),
            status: new FormControl('Pending'),
            executionMode: new FormControl('Sequential'),
            purpose: new FormControl(''),
            userMessage: new FormControl(''),
            // systemMessage: new FormControl(''), // SystemMessage does not exist on MJAIAgentEntity
            modelSelectionMode: new FormControl('Agent Type'),
            temperature: new FormControl(0.1),
            topP: new FormControl(0.1),
            topK: new FormControl(40),
            maxTokens: new FormControl(4000),
            enableCaching: new FormControl(false),
            cacheTTL: new FormControl(3600)
        });
    }
    setupFormWatching() {
        // Watch for form changes to update entity
        this.subAgentForm.valueChanges
            .pipe(takeUntil(this.destroy$))
            .subscribe(formValue => {
            this.updateSubAgentEntity(formValue);
        });
    }
    async loadInitialData() {
        this.isLoading$.next(true);
        try {
            const rv = new RunView();
            // Load all data in a single batch for better performance
            const results = await rv.RunViews([
                // Agent types (index 0)
                {
                    EntityName: 'MJ: AI Agent Types',
                    OrderBy: 'Name ASC',
                    ResultType: 'entity_object'
                },
                // Available prompts (index 1)
                {
                    EntityName: 'MJ: AI Prompts',
                    ExtraFilter: `Status = 'Active'`,
                    OrderBy: 'Name ASC',
                    MaxRows: 1000,
                    ResultType: 'entity_object'
                },
                // Available actions (index 2)
                {
                    EntityName: 'MJ: Actions',
                    ExtraFilter: `Status = 'Active'`,
                    OrderBy: 'Name ASC',
                    MaxRows: 1000,
                    ResultType: 'entity_object'
                }
            ]);
            // Process agent types (index 0)
            if (results[0].Success && results[0].Results) {
                this.availableAgentTypes$.next(results[0].Results);
                // Set default type if not specified
                if (!this.config.initialTypeID && results[0].Results.length > 0) {
                    this.subAgentForm.patchValue({ typeID: results[0].Results[0].ID });
                }
            }
            // Process available prompts (index 1)
            if (results[1].Success && results[1].Results) {
                this.availablePrompts$.next(results[1].Results);
            }
            // Process available actions (index 2)
            const actionsResult = results[2];
            if (actionsResult.Success && actionsResult.Results) {
                this.availableActions$.next(actionsResult.Results);
            }
            // Create the sub-agent entity
            const md = new Metadata();
            this.subAgentEntity = await md.GetEntityObject('MJ: AI Agents');
            this.subAgentEntity.NewRecord();
            // Set default values
            this.subAgentEntity.Status = 'Pending';
            this.subAgentEntity.ExecutionMode = 'Sequential';
            this.subAgentEntity.ExposeAsAction = false; // Database constraint for sub-agents
            this.subAgentEntity.ParentID = this.config.parentAgentId;
            this.subAgentEntity.ModelSelectionMode = 'Agent Type';
            this.subAgentEntity.Set('Temperature', 0.1);
            this.subAgentEntity.Set('TopP', 0.1);
            this.subAgentEntity.Set('TopK', 40);
            this.subAgentEntity.Set('MaxTokensPerRun', 4000);
            this.subAgentEntity.Set('EnableCaching', false);
            this.subAgentEntity.Set('CacheTTLSeconds', 3600);
            // Update form with initial values
            this.updateSubAgentEntity(this.subAgentForm.value);
        }
        catch (error) {
            console.error('Error loading sub-agent creation data:', error);
            MJNotificationService.Instance.CreateSimpleNotification('Error loading data for sub-agent creation', 'error', 3000);
        }
        finally {
            this.isLoading$.next(false);
        }
    }
    updateSubAgentEntity(formValue) {
        if (!this.subAgentEntity)
            return;
        // Update entity with form values
        this.subAgentEntity.Name = formValue.name;
        this.subAgentEntity.Description = formValue.description || '';
        this.subAgentEntity.TypeID = formValue.typeID;
        this.subAgentEntity.Status = formValue.status;
        this.subAgentEntity.ExecutionMode = formValue.executionMode;
        this.subAgentEntity.Set('Purpose', formValue.purpose || '');
        this.subAgentEntity.Set('UserMessage', formValue.userMessage || '');
        // Note: SystemMessage does not exist on MJAIAgentEntityExtended, removing this line
        this.subAgentEntity.ModelSelectionMode = formValue.modelSelectionMode;
        this.subAgentEntity.Set('Temperature', formValue.temperature);
        this.subAgentEntity.Set('TopP', formValue.topP);
        this.subAgentEntity.Set('TopK', formValue.topK);
        this.subAgentEntity.Set('MaxTokensPerRun', formValue.maxTokens);
        this.subAgentEntity.Set('EnableCaching', formValue.enableCaching);
        this.subAgentEntity.Set('CacheTTLSeconds', formValue.cacheTTL);
    }
    async addPrompt() {
        // Get currently linked prompt IDs
        const linkedPromptIds = this.linkedPrompts.map(p => p.ID);
        try {
            this.agentManagementService.openPromptSelectorDialog({
                title: 'Add Prompts to Sub-Agent',
                multiSelect: true,
                selectedPromptIds: [],
                showCreateNew: true,
                linkedPromptIds: linkedPromptIds,
                viewContainerRef: this.viewContainerRef
            }).subscribe({
                next: async (result) => {
                    if (result && result.selectedPrompts.length > 0) {
                        // Filter out already linked prompts
                        const newPrompts = result.selectedPrompts.filter(prompt => !linkedPromptIds.some(id => UUIDsEqual(id, prompt.ID)));
                        if (newPrompts.length > 0) {
                            // Add to UI
                            this.linkedPrompts.push(...newPrompts);
                            // Create agent prompt link entities
                            const md = new Metadata();
                            for (const prompt of newPrompts) {
                                const agentPrompt = await md.GetEntityObject('MJ: AI Agent Prompts');
                                agentPrompt.NewRecord();
                                agentPrompt.AgentID = this.subAgentEntity.ID;
                                agentPrompt.PromptID = prompt.ID;
                                agentPrompt.Status = 'Active';
                                agentPrompt.ExecutionOrder = this.agentPromptLinks.length + 1;
                                this.agentPromptLinks.push(agentPrompt);
                            }
                            // Trigger change detection
                            this.cdr.detectChanges();
                            MJNotificationService.Instance.CreateSimpleNotification(`${newPrompts.length} prompt${newPrompts.length === 1 ? '' : 's'} added to sub-agent`, 'success', 3000);
                        }
                    }
                    else if (result && result.createNew) {
                        // User wants to create a new prompt
                        await this.createNewPrompt();
                    }
                },
                error: (error) => {
                    console.error('Error opening prompt selector:', error);
                    MJNotificationService.Instance.CreateSimpleNotification('Error opening prompt selector. Please try again.', 'error', 3000);
                }
            });
        }
        catch (error) {
            console.error('Error in addPrompt:', error);
            MJNotificationService.Instance.CreateSimpleNotification('Error adding prompts. Please try again.', 'error', 3000);
        }
    }
    async createNewPrompt() {
        try {
            this.agentManagementService.openCreatePromptDialog({
                title: `Create New Prompt for ${this.subAgentEntity?.Name || 'Sub-Agent'}`,
                initialName: '',
                viewContainerRef: this.viewContainerRef
            }).subscribe({
                next: async (result) => {
                    if (result && result.prompt) {
                        try {
                            // Store the newly created entities
                            this.newlyCreatedPrompts.push(result.prompt);
                            if (result.template) {
                                this.newlyCreatedPromptTemplates.push(result.template);
                            }
                            if (result.templateContents && result.templateContents.length > 0) {
                                this.newlyCreatedTemplateContents.push(...result.templateContents);
                            }
                            // Add to UI
                            this.linkedPrompts.push(result.prompt);
                            // Create agent prompt link entity
                            const md = new Metadata();
                            const agentPrompt = await md.GetEntityObject('MJ: AI Agent Prompts');
                            agentPrompt.NewRecord();
                            agentPrompt.AgentID = this.subAgentEntity.ID;
                            agentPrompt.PromptID = result.prompt.ID;
                            agentPrompt.Status = 'Active';
                            agentPrompt.ExecutionOrder = this.agentPromptLinks.length + 1;
                            this.agentPromptLinks.push(agentPrompt);
                            // Trigger change detection
                            this.cdr.detectChanges();
                            MJNotificationService.Instance.CreateSimpleNotification(`New prompt "${result.prompt.Name}" created and linked to sub-agent`, 'success', 3000);
                        }
                        catch (error) {
                            console.error('Error processing created prompt:', error);
                            MJNotificationService.Instance.CreateSimpleNotification('Error processing created prompt. Please try again.', 'error', 3000);
                        }
                    }
                },
                error: (error) => {
                    console.error('Error in create prompt dialog:', error);
                    MJNotificationService.Instance.CreateSimpleNotification('Error opening prompt creation dialog. Please try again.', 'error', 3000);
                }
            });
        }
        catch (error) {
            console.error('Error in createNewPrompt:', error);
            MJNotificationService.Instance.CreateSimpleNotification('Error creating new prompt. Please try again.', 'error', 3000);
        }
    }
    async addAction() {
        // Get currently linked action IDs
        const linkedActionIds = this.linkedActions.map(a => a.ID);
        try {
            this.agentManagementService.openAddActionDialog({
                agentId: this.subAgentEntity?.ID || '',
                agentName: this.subAgentEntity?.Name || 'Sub-Agent',
                existingActionIds: linkedActionIds,
                viewContainerRef: this.viewContainerRef
            }).subscribe({
                next: async (selectedActions) => {
                    if (selectedActions && selectedActions.length > 0) {
                        // Filter out already linked actions
                        const newActions = selectedActions.filter(action => !linkedActionIds.some(id => UUIDsEqual(id, action.ID)));
                        if (newActions.length > 0) {
                            // Add to UI
                            this.linkedActions.push(...newActions);
                            // Create agent action link entities
                            const md = new Metadata();
                            for (const action of newActions) {
                                const agentAction = await md.GetEntityObject('MJ: AI Agent Actions');
                                agentAction.NewRecord();
                                agentAction.AgentID = this.subAgentEntity.ID;
                                agentAction.ActionID = action.ID;
                                agentAction.Status = 'Active';
                                this.agentActionLinks.push(agentAction);
                            }
                            // Trigger change detection
                            this.cdr.detectChanges();
                            MJNotificationService.Instance.CreateSimpleNotification(`${newActions.length} action${newActions.length === 1 ? '' : 's'} added to sub-agent`, 'success', 3000);
                        }
                    }
                },
                error: (error) => {
                    console.error('Error in add action dialog:', error);
                    MJNotificationService.Instance.CreateSimpleNotification('Error opening action selection dialog. Please try again.', 'error', 3000);
                }
            });
        }
        catch (error) {
            console.error('Error in addAction:', error);
            MJNotificationService.Instance.CreateSimpleNotification('Error adding actions. Please try again.', 'error', 3000);
        }
    }
    removePrompt(prompt) {
        // Remove from UI
        const promptIndex = this.linkedPrompts.findIndex(p => UUIDsEqual(p.ID, prompt.ID));
        if (promptIndex >= 0) {
            this.linkedPrompts.splice(promptIndex, 1);
        }
        // Remove from link entities
        const linkIndex = this.agentPromptLinks.findIndex(ap => UUIDsEqual(ap.PromptID, prompt.ID));
        if (linkIndex >= 0) {
            this.agentPromptLinks.splice(linkIndex, 1);
        }
        // Remove from newly created prompts if it was created in this dialog
        const newPromptIndex = this.newlyCreatedPrompts.findIndex(p => UUIDsEqual(p.ID, prompt.ID));
        if (newPromptIndex >= 0) {
            this.newlyCreatedPrompts.splice(newPromptIndex, 1);
        }
        this.cdr.detectChanges();
        MJNotificationService.Instance.CreateSimpleNotification(`Prompt "${prompt.Name}" removed from sub-agent`, 'info', 3000);
    }
    removeAction(action) {
        // Remove from UI
        const actionIndex = this.linkedActions.findIndex(a => UUIDsEqual(a.ID, action.ID));
        if (actionIndex >= 0) {
            this.linkedActions.splice(actionIndex, 1);
        }
        // Remove from link entities
        const linkIndex = this.agentActionLinks.findIndex(aa => UUIDsEqual(aa.ActionID, action.ID));
        if (linkIndex >= 0) {
            this.agentActionLinks.splice(linkIndex, 1);
        }
        this.cdr.detectChanges();
        MJNotificationService.Instance.CreateSimpleNotification(`Action "${action.Name}" removed from sub-agent`, 'info', 3000);
    }
    async save() {
        if (!this.subAgentForm.valid || !this.subAgentEntity) {
            MJNotificationService.Instance.CreateSimpleNotification('Please fill in all required fields', 'warning', 3000);
            return;
        }
        this.isSaving$.next(true);
        try {
            // Update entity with final form values
            this.updateSubAgentEntity(this.subAgentForm.value);
            // Return the created entities (not saved to database)
            const result = {
                subAgent: this.subAgentEntity,
                agentPrompts: this.agentPromptLinks,
                agentActions: this.agentActionLinks,
                newPrompts: this.newlyCreatedPrompts.length > 0 ? this.newlyCreatedPrompts : undefined,
                newPromptTemplates: this.newlyCreatedPromptTemplates.length > 0 ? this.newlyCreatedPromptTemplates : undefined,
                newTemplateContents: this.newlyCreatedTemplateContents.length > 0 ? this.newlyCreatedTemplateContents : undefined
            };
            this.result.next(result);
            this.dialogRef.close();
        }
        catch (error) {
            console.error('Error preparing sub-agent for creation:', error);
            MJNotificationService.Instance.CreateSimpleNotification('Error preparing sub-agent for creation', 'error', 3000);
        }
        finally {
            this.isSaving$.next(false);
        }
    }
    cancel() {
        this.result.next(null);
        this.dialogRef.close();
    }
    // Helper methods for UI
    getAgentIcon() {
        return this.subAgentEntity?.IconClass || 'fa-solid fa-robot';
    }
    getPromptIcon() {
        return 'fa-solid fa-comments';
    }
    getActionIcon() {
        return 'fa-solid fa-bolt';
    }
    get linkedPromptCount() {
        return this.linkedPrompts.length;
    }
    get linkedActionCount() {
        return this.linkedActions.length;
    }
    static { this.ɵfac = function CreateSubAgentDialogComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CreateSubAgentDialogComponent)(i0.ɵɵdirectiveInject(i1.WindowRef), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i2.AIAgentManagementService), i0.ɵɵdirectiveInject(i0.ViewContainerRef)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: CreateSubAgentDialogComponent, selectors: [["mj-create-sub-agent-dialog"]], standalone: false, decls: 19, vars: 14, consts: [[1, "sub-agent-dialog"], [1, "sub-agent-header"], [1, "dialog-title"], [1, "fa-solid", "fa-robot"], [1, "parent-info"], [1, "loading-container"], [1, "sub-agent-form", 3, "formGroup"], [1, "dialog-actions"], ["type", "button", 1, "btn", "btn-secondary", 3, "click", "disabled"], [1, "fa-solid", "fa-times"], ["type", "button", 1, "btn", "btn-primary", 3, "click", "disabled"], [1, "fa-solid", "fa-link"], [1, "fa-solid", "fa-spinner", "fa-spin"], [1, "form-section"], [1, "section-title"], [1, "fa-solid", "fa-info-circle"], [1, "form-row"], [1, "form-group"], ["for", "name"], ["type", "text", "id", "name", "formControlName", "name", "placeholder", "Enter sub-agent name", 1, "form-control"], ["for", "typeID"], ["id", "typeID", "formControlName", "typeID", 1, "form-control"], ["value", ""], [3, "value"], ["for", "description"], ["id", "description", "formControlName", "description", "rows", "2", "placeholder", "Enter description", 1, "form-control"], ["for", "status"], ["id", "status", "formControlName", "status", 1, "form-control"], ["value", "Pending"], ["value", "Active"], ["value", "Disabled"], ["for", "executionMode"], ["id", "executionMode", "formControlName", "executionMode", 1, "form-control"], ["value", "Sequential"], ["value", "Parallel"], [1, "fa-solid", "fa-bullseye"], ["for", "purpose"], ["type", "text", "id", "purpose", "formControlName", "purpose", "placeholder", "Enter the purpose of this sub-agent", 1, "form-control"], ["for", "userMessage"], ["id", "userMessage", "formControlName", "userMessage", "rows", "3", "placeholder", "Enter user message", 1, "form-control"], [1, "fa-solid", "fa-cogs"], ["for", "modelSelectionMode"], ["id", "modelSelectionMode", "formControlName", "modelSelectionMode", 1, "form-control"], ["value", "Agent Type"], ["value", "Agent"], ["for", "temperature"], ["type", "number", "id", "temperature", "formControlName", "temperature", "min", "0", "max", "2", "step", "0.1", 1, "form-control"], ["for", "topP"], ["type", "number", "id", "topP", "formControlName", "topP", "min", "0", "max", "1", "step", "0.1", 1, "form-control"], ["for", "topK"], ["type", "number", "id", "topK", "formControlName", "topK", "min", "1", "max", "100", "step", "1", 1, "form-control"], ["for", "maxTokens"], ["type", "number", "id", "maxTokens", "formControlName", "maxTokens", "min", "1", "max", "32000", "step", "1", 1, "form-control"], ["for", "enableCaching"], ["type", "checkbox", "id", "enableCaching", "formControlName", "enableCaching"], ["for", "cacheTTL"], ["type", "number", "id", "cacheTTL", "formControlName", "cacheTTL", "min", "60", "max", "86400", "step", "60", 1, "form-control"], [1, "fa-solid", "fa-comments"], [1, "section-actions"], ["type", "button", 1, "btn", "btn-primary", "btn-sm", 3, "click"], [1, "fa-solid", "fa-plus"], ["type", "button", 1, "btn", "btn-success", "btn-sm", 3, "click"], [1, "linked-items"], [1, "empty-state"], [1, "fa-solid", "fa-bolt"], [1, "linked-item", "prompt-item"], [1, "item-info"], [1, "item-name"], [1, "item-description"], ["type", "button", 1, "btn", "btn-danger", "btn-xs", 3, "click"], [1, "linked-item", "action-item"], [1, "fa-solid", "fa-save"]], template: function CreateSubAgentDialogComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "div", 1)(2, "h2", 2);
            i0.ɵɵelement(3, "i", 3);
            i0.ɵɵtext(4);
            i0.ɵɵelementEnd();
            i0.ɵɵconditionalCreate(5, CreateSubAgentDialogComponent_Conditional_5_Template, 5, 1, "p", 4);
            i0.ɵɵelementEnd();
            i0.ɵɵconditionalCreate(6, CreateSubAgentDialogComponent_Conditional_6_Template, 4, 0, "div", 5);
            i0.ɵɵpipe(7, "async");
            i0.ɵɵconditionalBranchCreate(8, CreateSubAgentDialogComponent_Conditional_8_Template, 120, 7, "form", 6);
            i0.ɵɵelementStart(9, "div", 7)(10, "button", 8);
            i0.ɵɵpipe(11, "async");
            i0.ɵɵlistener("click", function CreateSubAgentDialogComponent_Template_button_click_10_listener() { return ctx.cancel(); });
            i0.ɵɵelement(12, "i", 9);
            i0.ɵɵtext(13, " Cancel ");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(14, "button", 10);
            i0.ɵɵpipe(15, "async");
            i0.ɵɵlistener("click", function CreateSubAgentDialogComponent_Template_button_click_14_listener() { return ctx.save(); });
            i0.ɵɵconditionalCreate(16, CreateSubAgentDialogComponent_Conditional_16_Template, 2, 0);
            i0.ɵɵpipe(17, "async");
            i0.ɵɵconditionalBranchCreate(18, CreateSubAgentDialogComponent_Conditional_18_Template, 2, 0);
            i0.ɵɵelementEnd()()();
        } if (rf & 2) {
            i0.ɵɵadvance(4);
            i0.ɵɵtextInterpolate1(" ", ctx.config.title || "Create New Sub-Agent", " ");
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.config.parentAgentName ? 5 : -1);
            i0.ɵɵadvance();
            i0.ɵɵconditional(i0.ɵɵpipeBind1(7, 6, ctx.isLoading$) ? 6 : 8);
            i0.ɵɵadvance(4);
            i0.ɵɵproperty("disabled", i0.ɵɵpipeBind1(11, 8, ctx.isSaving$));
            i0.ɵɵadvance(4);
            i0.ɵɵproperty("disabled", i0.ɵɵpipeBind1(15, 10, ctx.isSaving$) || !ctx.subAgentForm.valid);
            i0.ɵɵadvance(2);
            i0.ɵɵconditional(i0.ɵɵpipeBind1(17, 12, ctx.isSaving$) ? 16 : 18);
        } }, dependencies: [i3.ɵNgNoValidate, i3.NgSelectOption, i3.ɵNgSelectMultipleOption, i3.DefaultValueAccessor, i3.NumberValueAccessor, i3.CheckboxControlValueAccessor, i3.SelectControlValueAccessor, i3.NgControlStatus, i3.NgControlStatusGroup, i3.MinValidator, i3.MaxValidator, i3.FormGroupDirective, i3.FormControlName, i4.AsyncPipe], styles: [".sub-agent-dialog[_ngcontent-%COMP%] {\n  padding: 16px;\n  max-width: 100%;\n  max-height: 90vh;\n  overflow-y: auto;\n}\n\n.sub-agent-header[_ngcontent-%COMP%] {\n  margin-bottom: 20px;\n  border-bottom: 1px solid var(--mj-border-default);\n  padding-bottom: 15px;\n}\n\n.dialog-title[_ngcontent-%COMP%] {\n  margin: 0;\n  font-size: 1.4em;\n  font-weight: 600;\n  color: var(--mj-text-primary);\n  display: flex;\n  align-items: center;\n  gap: 10px;\n}\n\n.dialog-title[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-brand-primary);\n}\n\n.parent-info[_ngcontent-%COMP%] {\n  margin: 8px 0 0 0;\n  color: var(--mj-text-secondary);\n  font-size: 0.9em;\n  display: flex;\n  align-items: center;\n  gap: 8px;\n}\n\n.parent-info[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-status-success);\n}\n\n.loading-container[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 10px;\n  padding: 40px;\n  color: var(--mj-text-secondary);\n}\n\n.loading-container[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  font-size: 1.2em;\n  color: var(--mj-brand-primary);\n}\n\n.sub-agent-form[_ngcontent-%COMP%] {\n  display: flex;\n  flex-direction: column;\n  gap: 25px;\n}\n\n.form-section[_ngcontent-%COMP%] {\n  border: 1px solid var(--mj-bg-surface-sunken);\n  border-radius: 8px;\n  padding: 20px;\n  background-color: var(--mj-bg-surface-card);\n}\n\n.section-title[_ngcontent-%COMP%] {\n  margin: 0 0 15px 0;\n  font-size: 1.1em;\n  font-weight: 600;\n  color: var(--mj-text-secondary);\n  display: flex;\n  align-items: center;\n  gap: 8px;\n}\n\n.section-title[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-brand-primary);\n}\n\n.form-row[_ngcontent-%COMP%] {\n  display: flex;\n  gap: 15px;\n  margin-bottom: 15px;\n}\n\n.form-row[_ngcontent-%COMP%]:last-child {\n  margin-bottom: 0;\n}\n\n.form-group[_ngcontent-%COMP%] {\n  flex: 1;\n  display: flex;\n  flex-direction: column;\n}\n\n.form-group[_ngcontent-%COMP%]   label[_ngcontent-%COMP%] {\n  font-weight: 500;\n  color: var(--mj-text-secondary);\n  margin-bottom: 5px;\n  font-size: 0.9em;\n}\n\n.form-group[_ngcontent-%COMP%]   label[for=\"enableCaching\"][_ngcontent-%COMP%] {\n  flex-direction: row;\n  align-items: center;\n  gap: 8px;\n}\n\n.form-group[_ngcontent-%COMP%]   label[for=\"enableCaching\"][_ngcontent-%COMP%]   input[_ngcontent-%COMP%] {\n  margin: 0;\n  width: auto;\n}\n\n.form-control[_ngcontent-%COMP%] {\n  padding: 8px 12px;\n  border: 1px solid var(--mj-border-strong);\n  border-radius: 4px;\n  font-size: 0.9em;\n  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;\n}\n\n.form-control[_ngcontent-%COMP%]:focus {\n  outline: none;\n  border-color: var(--mj-brand-primary);\n  box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--mj-brand-primary) 25%, transparent);\n}\n\n.form-control[readonly][_ngcontent-%COMP%] {\n  background-color: var(--mj-bg-surface-sunken);\n  opacity: 1;\n}\n\n.section-actions[_ngcontent-%COMP%] {\n  display: flex;\n  gap: 10px;\n  margin-bottom: 15px;\n}\n\n.linked-items[_ngcontent-%COMP%] {\n  display: flex;\n  flex-direction: column;\n  gap: 10px;\n}\n\n.linked-item[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 12px;\n  background-color: var(--mj-bg-surface);\n  border: 1px solid var(--mj-border-default);\n  border-radius: 6px;\n  transition: box-shadow 0.15s ease-in-out;\n}\n\n.linked-item[_ngcontent-%COMP%]:hover {\n  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\n}\n\n.item-info[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  flex: 1;\n}\n\n.item-info[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-brand-primary);\n  width: 16px;\n  text-align: center;\n}\n\n.item-name[_ngcontent-%COMP%] {\n  font-weight: 500;\n  color: var(--mj-text-primary);\n}\n\n.item-description[_ngcontent-%COMP%] {\n  color: var(--mj-text-secondary);\n  font-size: 0.85em;\n  margin-left: 10px;\n}\n\n.prompt-item[_ngcontent-%COMP%]   .item-info[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-status-success);\n}\n\n.action-item[_ngcontent-%COMP%]   .item-info[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-status-warning);\n}\n\n.empty-state[_ngcontent-%COMP%] {\n  text-align: center;\n  padding: 30px;\n  color: var(--mj-text-muted);\n}\n\n.empty-state[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  font-size: 2em;\n  color: var(--mj-border-default);\n  margin-bottom: 10px;\n}\n\n.empty-state[_ngcontent-%COMP%]   p[_ngcontent-%COMP%] {\n  margin: 0;\n  font-size: 0.9em;\n}\n\n.dialog-actions[_ngcontent-%COMP%] {\n  display: flex;\n  justify-content: flex-end;\n  gap: 10px;\n  margin-top: 30px;\n  padding-top: 20px;\n  border-top: 1px solid var(--mj-border-default);\n}\n\n.btn[_ngcontent-%COMP%] {\n  padding: 8px 16px;\n  border: none;\n  border-radius: 4px;\n  font-size: 0.9em;\n  font-weight: 500;\n  cursor: pointer;\n  transition: background-color 0.15s ease-in-out;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n}\n\n.btn[_ngcontent-%COMP%]:disabled {\n  opacity: 0.6;\n  cursor: not-allowed;\n}\n\n.btn-primary[_ngcontent-%COMP%] {\n  background-color: var(--mj-brand-primary);\n  color: var(--mj-text-inverse);\n}\n\n.btn-primary[_ngcontent-%COMP%]:hover:not(:disabled) {\n  background-color: var(--mj-brand-primary-hover);\n}\n\n.btn-secondary[_ngcontent-%COMP%] {\n  background-color: var(--mj-text-muted);\n  color: var(--mj-text-inverse);\n}\n\n.btn-secondary[_ngcontent-%COMP%]:hover:not(:disabled) {\n  background-color: var(--mj-text-secondary);\n}\n\n.btn-success[_ngcontent-%COMP%] {\n  background-color: var(--mj-status-success);\n  color: var(--mj-text-inverse);\n}\n\n.btn-success[_ngcontent-%COMP%]:hover:not(:disabled) {\n  background-color: var(--mj-status-success);\n}\n\n.btn-danger[_ngcontent-%COMP%] {\n  background-color: var(--mj-status-error);\n  color: var(--mj-text-inverse);\n}\n\n.btn-danger[_ngcontent-%COMP%]:hover:not(:disabled) {\n  background-color: var(--mj-status-error);\n}\n\n.btn-sm[_ngcontent-%COMP%] {\n  padding: 6px 12px;\n  font-size: 0.8em;\n}\n\n.btn-xs[_ngcontent-%COMP%] {\n  padding: 4px 8px;\n  font-size: 0.75em;\n}\n\n\n\n@media (max-width: 768px) {\n  .sub-agent-dialog[_ngcontent-%COMP%] {\n    padding: 15px;\n    max-width: 95vw;\n  }\n\n  .form-row[_ngcontent-%COMP%] {\n    flex-direction: column;\n    gap: 10px;\n  }\n\n  .section-actions[_ngcontent-%COMP%] {\n    flex-direction: column;\n  }\n\n  .dialog-actions[_ngcontent-%COMP%] {\n    flex-direction: column;\n  }\n\n  .linked-item[_ngcontent-%COMP%] {\n    flex-direction: column;\n    align-items: flex-start;\n    gap: 10px;\n  }\n}\n\n\n\n.form-control.ng-invalid.ng-touched[_ngcontent-%COMP%] {\n  border-color: var(--mj-status-error);\n}\n\n.form-control.ng-valid.ng-touched[_ngcontent-%COMP%] {\n  border-color: var(--mj-status-success);\n}\n\n\n\n.sub-agent-dialog[_ngcontent-%COMP%]::-webkit-scrollbar {\n  width: 8px;\n}\n\n.sub-agent-dialog[_ngcontent-%COMP%]::-webkit-scrollbar-track {\n  background: var(--mj-bg-surface-sunken);\n  border-radius: 4px;\n}\n\n.sub-agent-dialog[_ngcontent-%COMP%]::-webkit-scrollbar-thumb {\n  background: var(--mj-border-strong);\n  border-radius: 4px;\n}\n\n.sub-agent-dialog[_ngcontent-%COMP%]::-webkit-scrollbar-thumb:hover {\n  background: var(--mj-text-disabled);\n}\n\n\n\n[_nghost-%COMP%]     .k-dialog, \n[_nghost-%COMP%]     .k-window {\n  z-index: 10000 !important;\n}\n\n[_nghost-%COMP%]     .k-overlay {\n  z-index: 9999 !important;\n}"] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CreateSubAgentDialogComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-create-sub-agent-dialog', template: "<div class=\"sub-agent-dialog\">\n  <div class=\"sub-agent-header\">\n    <h2 class=\"dialog-title\">\n      <i class=\"fa-solid fa-robot\"></i>\n      {{ config.title || 'Create New Sub-Agent' }}\n    </h2>\n    @if (config.parentAgentName) {\n      <p class=\"parent-info\">\n        <i class=\"fa-solid fa-link\"></i>\n        Sub-agent of: <strong>{{ config.parentAgentName }}</strong>\n      </p>\n    }\n  </div>\n\n  @if (isLoading$ | async) {\n    <div class=\"loading-container\">\n      <i class=\"fa-solid fa-spinner fa-spin\"></i>\n      <span>Loading sub-agent creation form...</span>\n    </div>\n  } @else {\n    <form [formGroup]=\"subAgentForm\" class=\"sub-agent-form\">\n      <!-- Basic Information Section -->\n      <div class=\"form-section\">\n        <h3 class=\"section-title\">\n          <i class=\"fa-solid fa-info-circle\"></i>\n          Basic Information\n        </h3>\n        \n        <div class=\"form-row\">\n          <div class=\"form-group\">\n            <label for=\"name\">Name *</label>\n            <input type=\"text\" id=\"name\" formControlName=\"name\" class=\"form-control\" placeholder=\"Enter sub-agent name\">\n          </div>\n          \n          <div class=\"form-group\">\n            <label for=\"typeID\">Type *</label>\n            <select id=\"typeID\" formControlName=\"typeID\" class=\"form-control\">\n              <option value=\"\">Select agent type...</option>\n              @for (type of availableAgentTypes$ | async; track type.ID) {\n                <option [value]=\"type.ID\">{{ type.Name }}</option>\n              }\n            </select>\n          </div>\n        </div>\n\n        <div class=\"form-row\">\n          <div class=\"form-group\">\n            <label for=\"description\">Description</label>\n            <textarea id=\"description\" formControlName=\"description\" class=\"form-control\" rows=\"2\" placeholder=\"Enter description\"></textarea>\n          </div>\n        </div>\n\n        <div class=\"form-row\">\n          <div class=\"form-group\">\n            <label for=\"status\">Status</label>\n            <select id=\"status\" formControlName=\"status\" class=\"form-control\">\n              <option value=\"Pending\">Pending</option>\n              <option value=\"Active\">Active</option>\n              <option value=\"Disabled\">Disabled</option>\n            </select>\n          </div>\n          \n          <div class=\"form-group\">\n            <label for=\"executionMode\">Execution Mode</label>\n            <select id=\"executionMode\" formControlName=\"executionMode\" class=\"form-control\">\n              <option value=\"Sequential\">Sequential</option>\n              <option value=\"Parallel\">Parallel</option>\n            </select>\n          </div>\n        </div>\n      </div>\n\n      <!-- Purpose & Messages Section -->\n      <div class=\"form-section\">\n        <h3 class=\"section-title\">\n          <i class=\"fa-solid fa-bullseye\"></i>\n          Purpose & Messages\n        </h3>\n        \n        <div class=\"form-row\">\n          <div class=\"form-group\">\n            <label for=\"purpose\">Purpose</label>\n            <input type=\"text\" id=\"purpose\" formControlName=\"purpose\" class=\"form-control\" placeholder=\"Enter the purpose of this sub-agent\">\n          </div>\n        </div>\n\n        <div class=\"form-row\">\n          <div class=\"form-group\">\n            <label for=\"userMessage\">User Message</label>\n            <textarea id=\"userMessage\" formControlName=\"userMessage\" class=\"form-control\" rows=\"3\" placeholder=\"Enter user message\"></textarea>\n          </div>\n        </div>\n\n        <!-- System Message field removed - property does not exist on MJAIAgentEntity -->\n      </div>\n\n      <!-- Model Configuration Section -->\n      <div class=\"form-section\">\n        <h3 class=\"section-title\">\n          <i class=\"fa-solid fa-cogs\"></i>\n          Model Configuration\n        </h3>\n        \n        <div class=\"form-row\">\n          <div class=\"form-group\">\n            <label for=\"modelSelectionMode\">Model Selection Mode</label>\n            <select id=\"modelSelectionMode\" formControlName=\"modelSelectionMode\" class=\"form-control\">\n              <option value=\"Agent Type\">Agent Type</option>\n              <option value=\"Agent\">Agent</option>\n            </select>\n          </div>\n        </div>\n\n        <div class=\"form-row\">\n          <div class=\"form-group\">\n            <label for=\"temperature\">Temperature</label>\n            <input type=\"number\" id=\"temperature\" formControlName=\"temperature\" class=\"form-control\" min=\"0\" max=\"2\" step=\"0.1\">\n          </div>\n          \n          <div class=\"form-group\">\n            <label for=\"topP\">Top P</label>\n            <input type=\"number\" id=\"topP\" formControlName=\"topP\" class=\"form-control\" min=\"0\" max=\"1\" step=\"0.1\">\n          </div>\n        </div>\n\n        <div class=\"form-row\">\n          <div class=\"form-group\">\n            <label for=\"topK\">Top K</label>\n            <input type=\"number\" id=\"topK\" formControlName=\"topK\" class=\"form-control\" min=\"1\" max=\"100\" step=\"1\">\n          </div>\n          \n          <div class=\"form-group\">\n            <label for=\"maxTokens\">Max Tokens</label>\n            <input type=\"number\" id=\"maxTokens\" formControlName=\"maxTokens\" class=\"form-control\" min=\"1\" max=\"32000\" step=\"1\">\n          </div>\n        </div>\n\n        <div class=\"form-row\">\n          <div class=\"form-group\">\n            <label for=\"enableCaching\">\n              <input type=\"checkbox\" id=\"enableCaching\" formControlName=\"enableCaching\">\n              Enable Caching\n            </label>\n          </div>\n          \n          <div class=\"form-group\">\n            <label for=\"cacheTTL\">Cache TTL (seconds)</label>\n            <input type=\"number\" id=\"cacheTTL\" formControlName=\"cacheTTL\" class=\"form-control\" min=\"60\" max=\"86400\" step=\"60\">\n          </div>\n        </div>\n      </div>\n\n      <!-- Prompts Section -->\n      <div class=\"form-section\">\n        <h3 class=\"section-title\">\n          <i class=\"fa-solid fa-comments\"></i>\n          Prompts ({{ linkedPromptCount }})\n        </h3>\n        \n        <div class=\"section-actions\">\n          <button type=\"button\" class=\"btn btn-primary btn-sm\" (click)=\"addPrompt()\">\n            <i class=\"fa-solid fa-plus\"></i>\n            Add Existing Prompt\n          </button>\n          <button type=\"button\" class=\"btn btn-success btn-sm\" (click)=\"createNewPrompt()\">\n            <i class=\"fa-solid fa-plus\"></i>\n            Create New Prompt\n          </button>\n        </div>\n\n        @if (linkedPrompts.length > 0) {\n          <div class=\"linked-items\">\n            @for (prompt of linkedPrompts; track prompt.ID) {\n              <div class=\"linked-item prompt-item\">\n                <div class=\"item-info\">\n                  <i class=\"fa-solid fa-comments\"></i>\n                  <span class=\"item-name\">{{ prompt.Name }}</span>\n                  @if (prompt.Description) {\n                    <span class=\"item-description\">{{ prompt.Description }}</span>\n                  }\n                </div>\n                <button type=\"button\" class=\"btn btn-danger btn-xs\" (click)=\"removePrompt(prompt)\">\n                  <i class=\"fa-solid fa-times\"></i>\n                </button>\n              </div>\n            }\n          </div>\n        } @else {\n          <div class=\"empty-state\">\n            <i class=\"fa-solid fa-comments\"></i>\n            <p>No prompts added yet. Click the buttons above to add prompts.</p>\n          </div>\n        }\n      </div>\n\n      <!-- Actions Section -->\n      <div class=\"form-section\">\n        <h3 class=\"section-title\">\n          <i class=\"fa-solid fa-bolt\"></i>\n          Actions ({{ linkedActionCount }})\n        </h3>\n        \n        <div class=\"section-actions\">\n          <button type=\"button\" class=\"btn btn-primary btn-sm\" (click)=\"addAction()\">\n            <i class=\"fa-solid fa-plus\"></i>\n            Add Action\n          </button>\n        </div>\n\n        @if (linkedActions.length > 0) {\n          <div class=\"linked-items\">\n            @for (action of linkedActions; track action.ID) {\n              <div class=\"linked-item action-item\">\n                <div class=\"item-info\">\n                  <i class=\"fa-solid fa-bolt\"></i>\n                  <span class=\"item-name\">{{ action.Name }}</span>\n                  @if (action.Description) {\n                    <span class=\"item-description\">{{ action.Description }}</span>\n                  }\n                </div>\n                <button type=\"button\" class=\"btn btn-danger btn-xs\" (click)=\"removeAction(action)\">\n                  <i class=\"fa-solid fa-times\"></i>\n                </button>\n              </div>\n            }\n          </div>\n        } @else {\n          <div class=\"empty-state\">\n            <i class=\"fa-solid fa-bolt\"></i>\n            <p>No actions added yet. Click the button above to add actions.</p>\n          </div>\n        }\n      </div>\n    </form>\n  }\n\n  <!-- Dialog Actions -->\n  <div class=\"dialog-actions\">\n    <button type=\"button\" class=\"btn btn-secondary\" (click)=\"cancel()\" [disabled]=\"isSaving$ | async\">\n      <i class=\"fa-solid fa-times\"></i>\n      Cancel\n    </button>\n    <button type=\"button\" class=\"btn btn-primary\" (click)=\"save()\" [disabled]=\"(isSaving$ | async) || !subAgentForm.valid\">\n      @if (isSaving$ | async) {\n        <i class=\"fa-solid fa-spinner fa-spin\"></i>\n        Creating...\n      } @else {\n        <i class=\"fa-solid fa-save\"></i>\n        Create Sub-Agent\n      }\n    </button>\n  </div>\n</div>", styles: [".sub-agent-dialog {\n  padding: 16px;\n  max-width: 100%;\n  max-height: 90vh;\n  overflow-y: auto;\n}\n\n.sub-agent-header {\n  margin-bottom: 20px;\n  border-bottom: 1px solid var(--mj-border-default);\n  padding-bottom: 15px;\n}\n\n.dialog-title {\n  margin: 0;\n  font-size: 1.4em;\n  font-weight: 600;\n  color: var(--mj-text-primary);\n  display: flex;\n  align-items: center;\n  gap: 10px;\n}\n\n.dialog-title i {\n  color: var(--mj-brand-primary);\n}\n\n.parent-info {\n  margin: 8px 0 0 0;\n  color: var(--mj-text-secondary);\n  font-size: 0.9em;\n  display: flex;\n  align-items: center;\n  gap: 8px;\n}\n\n.parent-info i {\n  color: var(--mj-status-success);\n}\n\n.loading-container {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 10px;\n  padding: 40px;\n  color: var(--mj-text-secondary);\n}\n\n.loading-container i {\n  font-size: 1.2em;\n  color: var(--mj-brand-primary);\n}\n\n.sub-agent-form {\n  display: flex;\n  flex-direction: column;\n  gap: 25px;\n}\n\n.form-section {\n  border: 1px solid var(--mj-bg-surface-sunken);\n  border-radius: 8px;\n  padding: 20px;\n  background-color: var(--mj-bg-surface-card);\n}\n\n.section-title {\n  margin: 0 0 15px 0;\n  font-size: 1.1em;\n  font-weight: 600;\n  color: var(--mj-text-secondary);\n  display: flex;\n  align-items: center;\n  gap: 8px;\n}\n\n.section-title i {\n  color: var(--mj-brand-primary);\n}\n\n.form-row {\n  display: flex;\n  gap: 15px;\n  margin-bottom: 15px;\n}\n\n.form-row:last-child {\n  margin-bottom: 0;\n}\n\n.form-group {\n  flex: 1;\n  display: flex;\n  flex-direction: column;\n}\n\n.form-group label {\n  font-weight: 500;\n  color: var(--mj-text-secondary);\n  margin-bottom: 5px;\n  font-size: 0.9em;\n}\n\n.form-group label[for=\"enableCaching\"] {\n  flex-direction: row;\n  align-items: center;\n  gap: 8px;\n}\n\n.form-group label[for=\"enableCaching\"] input {\n  margin: 0;\n  width: auto;\n}\n\n.form-control {\n  padding: 8px 12px;\n  border: 1px solid var(--mj-border-strong);\n  border-radius: 4px;\n  font-size: 0.9em;\n  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;\n}\n\n.form-control:focus {\n  outline: none;\n  border-color: var(--mj-brand-primary);\n  box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--mj-brand-primary) 25%, transparent);\n}\n\n.form-control[readonly] {\n  background-color: var(--mj-bg-surface-sunken);\n  opacity: 1;\n}\n\n.section-actions {\n  display: flex;\n  gap: 10px;\n  margin-bottom: 15px;\n}\n\n.linked-items {\n  display: flex;\n  flex-direction: column;\n  gap: 10px;\n}\n\n.linked-item {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 12px;\n  background-color: var(--mj-bg-surface);\n  border: 1px solid var(--mj-border-default);\n  border-radius: 6px;\n  transition: box-shadow 0.15s ease-in-out;\n}\n\n.linked-item:hover {\n  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\n}\n\n.item-info {\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  flex: 1;\n}\n\n.item-info i {\n  color: var(--mj-brand-primary);\n  width: 16px;\n  text-align: center;\n}\n\n.item-name {\n  font-weight: 500;\n  color: var(--mj-text-primary);\n}\n\n.item-description {\n  color: var(--mj-text-secondary);\n  font-size: 0.85em;\n  margin-left: 10px;\n}\n\n.prompt-item .item-info i {\n  color: var(--mj-status-success);\n}\n\n.action-item .item-info i {\n  color: var(--mj-status-warning);\n}\n\n.empty-state {\n  text-align: center;\n  padding: 30px;\n  color: var(--mj-text-muted);\n}\n\n.empty-state i {\n  font-size: 2em;\n  color: var(--mj-border-default);\n  margin-bottom: 10px;\n}\n\n.empty-state p {\n  margin: 0;\n  font-size: 0.9em;\n}\n\n.dialog-actions {\n  display: flex;\n  justify-content: flex-end;\n  gap: 10px;\n  margin-top: 30px;\n  padding-top: 20px;\n  border-top: 1px solid var(--mj-border-default);\n}\n\n.btn {\n  padding: 8px 16px;\n  border: none;\n  border-radius: 4px;\n  font-size: 0.9em;\n  font-weight: 500;\n  cursor: pointer;\n  transition: background-color 0.15s ease-in-out;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n}\n\n.btn:disabled {\n  opacity: 0.6;\n  cursor: not-allowed;\n}\n\n.btn-primary {\n  background-color: var(--mj-brand-primary);\n  color: var(--mj-text-inverse);\n}\n\n.btn-primary:hover:not(:disabled) {\n  background-color: var(--mj-brand-primary-hover);\n}\n\n.btn-secondary {\n  background-color: var(--mj-text-muted);\n  color: var(--mj-text-inverse);\n}\n\n.btn-secondary:hover:not(:disabled) {\n  background-color: var(--mj-text-secondary);\n}\n\n.btn-success {\n  background-color: var(--mj-status-success);\n  color: var(--mj-text-inverse);\n}\n\n.btn-success:hover:not(:disabled) {\n  background-color: var(--mj-status-success);\n}\n\n.btn-danger {\n  background-color: var(--mj-status-error);\n  color: var(--mj-text-inverse);\n}\n\n.btn-danger:hover:not(:disabled) {\n  background-color: var(--mj-status-error);\n}\n\n.btn-sm {\n  padding: 6px 12px;\n  font-size: 0.8em;\n}\n\n.btn-xs {\n  padding: 4px 8px;\n  font-size: 0.75em;\n}\n\n/* Responsive adjustments */\n@media (max-width: 768px) {\n  .sub-agent-dialog {\n    padding: 15px;\n    max-width: 95vw;\n  }\n\n  .form-row {\n    flex-direction: column;\n    gap: 10px;\n  }\n\n  .section-actions {\n    flex-direction: column;\n  }\n\n  .dialog-actions {\n    flex-direction: column;\n  }\n\n  .linked-item {\n    flex-direction: column;\n    align-items: flex-start;\n    gap: 10px;\n  }\n}\n\n/* Validation styles */\n.form-control.ng-invalid.ng-touched {\n  border-color: var(--mj-status-error);\n}\n\n.form-control.ng-valid.ng-touched {\n  border-color: var(--mj-status-success);\n}\n\n/* Custom scrollbar for dialog */\n.sub-agent-dialog::-webkit-scrollbar {\n  width: 8px;\n}\n\n.sub-agent-dialog::-webkit-scrollbar-track {\n  background: var(--mj-bg-surface-sunken);\n  border-radius: 4px;\n}\n\n.sub-agent-dialog::-webkit-scrollbar-thumb {\n  background: var(--mj-border-strong);\n  border-radius: 4px;\n}\n\n.sub-agent-dialog::-webkit-scrollbar-thumb:hover {\n  background: var(--mj-text-disabled);\n}\n\n/* Ensure dialog appears above banner and other elements */\n:host ::ng-deep .k-dialog,\n:host ::ng-deep .k-window {\n  z-index: 10000 !important;\n}\n\n:host ::ng-deep .k-overlay {\n  z-index: 9999 !important;\n}\n"] }]
    }], () => [{ type: i1.WindowRef }, { type: i0.ChangeDetectorRef }, { type: i2.AIAgentManagementService }, { type: i0.ViewContainerRef }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(CreateSubAgentDialogComponent, { className: "CreateSubAgentDialogComponent", filePath: "src/lib/custom/AIAgents/create-sub-agent-dialog.component.ts", lineNumber: 50 }); })();
//# sourceMappingURL=create-sub-agent-dialog.component.js.map