/**
 * @fileoverview MCP Connection Dialog Component
 *
 * Dialog for creating and editing MCP server connections.
 */
import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { Validators } from '@angular/forms';
import { Metadata, RunView, CompositeKey } from '@memberjunction/core';
import { UUIDsEqual } from '@memberjunction/global';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "@progress/kendo-angular-buttons";
import * as i3 from "@progress/kendo-angular-dialog";
import * as i4 from "@progress/kendo-angular-dropdowns";
import * as i5 from "@progress/kendo-angular-inputs";
import * as i6 from "@memberjunction/ng-credentials";
const _c0 = ["credentialDialog"];
const _c1 = () => ({ Name: "Select a server...", ID: "" });
const _c2 = () => ["Active", "Inactive"];
const _c3 = () => ({ Name: "Global (all companies)", ID: "" });
const _c4 = () => ({ Name: "No credential (anonymous)", ID: "" });
function MCPConnectionDialogComponent_Conditional_0_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 5);
    i0.ɵɵelement(1, "i", 45);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", ctx_r1.ErrorMessage, " ");
} }
function MCPConnectionDialogComponent_Conditional_0_ng_template_13_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 48);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const dataItem_r3 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(dataItem_r3.TransportType);
} }
function MCPConnectionDialogComponent_Conditional_0_ng_template_13_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 46)(1, "span", 47);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(3, MCPConnectionDialogComponent_Conditional_0_ng_template_13_Conditional_3_Template, 2, 1, "span", 48);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const dataItem_r3 = ctx.$implicit;
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(dataItem_r3.Name);
    i0.ɵɵadvance();
    i0.ɵɵconditional(dataItem_r3.TransportType ? 3 : -1);
} }
function MCPConnectionDialogComponent_Conditional_0_Conditional_14_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 13);
    i0.ɵɵtext(1, "Server selection is required");
    i0.ɵɵelementEnd();
} }
function MCPConnectionDialogComponent_Conditional_0_Conditional_21_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 13);
    i0.ɵɵtext(1, "Name is required");
    i0.ɵɵelementEnd();
} }
function MCPConnectionDialogComponent_Conditional_0_Conditional_43_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 25);
    i0.ɵɵelement(1, "i", 43);
    i0.ɵɵtext(2, " Loading credentials... ");
    i0.ɵɵelementEnd();
} }
function MCPConnectionDialogComponent_Conditional_0_Conditional_44_Template(rf, ctx) { if (rf & 1) {
    const _r4 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 49);
    i0.ɵɵelement(1, "kendo-dropdownlist", 50);
    i0.ɵɵelementStart(2, "button", 51);
    i0.ɵɵlistener("click", function MCPConnectionDialogComponent_Conditional_0_Conditional_44_Template_button_click_2_listener() { i0.ɵɵrestoreView(_r4); const ctx_r1 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r1.openCredentialDialog()); });
    i0.ɵɵelement(3, "i", 52);
    i0.ɵɵtext(4, " New ");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(5, "span", 22);
    i0.ɵɵtext(6, "Select an existing credential or create a new one");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("data", ctx_r1.credentials)("valuePrimitive", true)("defaultItem", i0.ɵɵpureFunction0(3, _c4));
} }
function MCPConnectionDialogComponent_Conditional_0_Conditional_102_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "i", 43);
} }
function MCPConnectionDialogComponent_Conditional_0_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "kendo-dialog", 3);
    i0.ɵɵlistener("close", function MCPConnectionDialogComponent_Conditional_0_Template_kendo_dialog_close_0_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.cancel()); });
    i0.ɵɵelementStart(1, "form", 4);
    i0.ɵɵconditionalCreate(2, MCPConnectionDialogComponent_Conditional_0_Conditional_2_Template, 3, 1, "div", 5);
    i0.ɵɵelementStart(3, "div", 6)(4, "h3");
    i0.ɵɵelement(5, "i", 7);
    i0.ɵɵtext(6, " Basic Information");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(7, "div", 8)(8, "label", 9);
    i0.ɵɵtext(9, "MCP Server ");
    i0.ɵɵelementStart(10, "span", 10);
    i0.ɵɵtext(11, "*");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(12, "kendo-dropdownlist", 11);
    i0.ɵɵlistener("valueChange", function MCPConnectionDialogComponent_Conditional_0_Template_kendo_dropdownlist_valueChange_12_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.onServerChange()); });
    i0.ɵɵtemplate(13, MCPConnectionDialogComponent_Conditional_0_ng_template_13_Template, 4, 2, "ng-template", 12);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(14, MCPConnectionDialogComponent_Conditional_0_Conditional_14_Template, 2, 0, "span", 13);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(15, "div", 8)(16, "label", 14);
    i0.ɵɵtext(17, "Connection Name ");
    i0.ɵɵelementStart(18, "span", 10);
    i0.ɵɵtext(19, "*");
    i0.ɵɵelementEnd()();
    i0.ɵɵelement(20, "input", 15);
    i0.ɵɵconditionalCreate(21, MCPConnectionDialogComponent_Conditional_0_Conditional_21_Template, 2, 0, "span", 13);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(22, "div", 8)(23, "label", 16);
    i0.ɵɵtext(24, "Description");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(25, "textarea", 17);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(26, "div", 8)(27, "label", 18);
    i0.ɵɵtext(28, "Status");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(29, "kendo-dropdownlist", 19);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(30, "div", 8)(31, "label", 20);
    i0.ɵɵtext(32, "Company");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(33, "kendo-dropdownlist", 21);
    i0.ɵɵelementStart(34, "span", 22);
    i0.ɵɵtext(35, "Leave as Global to make this connection available to all companies");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(36, "div", 6)(37, "h3");
    i0.ɵɵelement(38, "i", 23);
    i0.ɵɵtext(39, " Authentication");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(40, "div", 8)(41, "label", 24);
    i0.ɵɵtext(42, "Credential");
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(43, MCPConnectionDialogComponent_Conditional_0_Conditional_43_Template, 3, 0, "div", 25)(44, MCPConnectionDialogComponent_Conditional_0_Conditional_44_Template, 7, 4);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(45, "div", 8)(46, "label", 26);
    i0.ɵɵtext(47, "Custom Header Name");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(48, "input", 27);
    i0.ɵɵelementStart(49, "span", 22);
    i0.ɵɵtext(50, "Override the default header name for API key authentication");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(51, "div", 6)(52, "h3");
    i0.ɵɵelement(53, "i", 28);
    i0.ɵɵtext(54, " Behavior");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(55, "div", 29)(56, "label", 30);
    i0.ɵɵelement(57, "input", 31);
    i0.ɵɵelementStart(58, "span");
    i0.ɵɵtext(59, "Auto-sync tools on connect");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(60, "span", 22);
    i0.ɵɵtext(61, "Automatically discover and sync available tools when connecting");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(62, "div", 6)(63, "h3");
    i0.ɵɵelement(64, "i", 32);
    i0.ɵɵtext(65, " Logging");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(66, "div", 29)(67, "label", 30);
    i0.ɵɵelement(68, "input", 33);
    i0.ɵɵelementStart(69, "span");
    i0.ɵɵtext(70, "Enable tool call logging");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(71, "span", 22);
    i0.ɵɵtext(72, "Log all tool executions to the database");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(73, "div", 34)(74, "div", 29)(75, "label", 30);
    i0.ɵɵelement(76, "input", 35);
    i0.ɵɵelementStart(77, "span");
    i0.ɵɵtext(78, "Log input parameters");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(79, "div", 29)(80, "label", 30);
    i0.ɵɵelement(81, "input", 36);
    i0.ɵɵelementStart(82, "span");
    i0.ɵɵtext(83, "Log output content");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(84, "div", 8)(85, "label", 37);
    i0.ɵɵtext(86, "Max Output Log Size (bytes)");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(87, "kendo-numerictextbox", 38);
    i0.ɵɵelementStart(88, "span", 22);
    i0.ɵɵtext(89, "Maximum size of output content to log (0 = unlimited, max 10MB)");
    i0.ɵɵelementEnd()()()();
    i0.ɵɵelementStart(90, "div", 6)(91, "h3");
    i0.ɵɵelement(92, "i", 39);
    i0.ɵɵtext(93, " Advanced");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(94, "div", 8)(95, "label", 40);
    i0.ɵɵtext(96, "Environment Variables (JSON)");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(97, "textarea", 41);
    i0.ɵɵelementStart(98, "span", 22);
    i0.ɵɵtext(99, "Additional environment variables for Stdio transport (JSON object)");
    i0.ɵɵelementEnd()()()();
    i0.ɵɵelementStart(100, "kendo-dialog-actions")(101, "button", 42);
    i0.ɵɵlistener("click", function MCPConnectionDialogComponent_Conditional_0_Template_button_click_101_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.save()); });
    i0.ɵɵconditionalCreate(102, MCPConnectionDialogComponent_Conditional_0_Conditional_102_Template, 1, 0, "i", 43);
    i0.ɵɵtext(103);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(104, "button", 44);
    i0.ɵɵlistener("click", function MCPConnectionDialogComponent_Conditional_0_Template_button_click_104_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.cancel()); });
    i0.ɵɵtext(105, "Cancel");
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    let tmp_18_0;
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("title", ctx_r1.DialogTitle)("width", 600)("minWidth", 400);
    i0.ɵɵadvance();
    i0.ɵɵproperty("formGroup", ctx_r1.connectionForm);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.ErrorMessage ? 2 : -1);
    i0.ɵɵadvance(10);
    i0.ɵɵproperty("data", ctx_r1.ActiveServers)("valuePrimitive", true)("defaultItem", i0.ɵɵpureFunction0(27, _c1));
    i0.ɵɵadvance(2);
    i0.ɵɵconditional(ctx_r1.hasError("MCPServerID", "required") ? 14 : -1);
    i0.ɵɵadvance(7);
    i0.ɵɵconditional(ctx_r1.hasError("Name", "required") ? 21 : -1);
    i0.ɵɵadvance(4);
    i0.ɵɵproperty("rows", 3);
    i0.ɵɵadvance(4);
    i0.ɵɵproperty("data", i0.ɵɵpureFunction0(28, _c2))("valuePrimitive", true);
    i0.ɵɵadvance(4);
    i0.ɵɵproperty("data", ctx_r1.companies)("valuePrimitive", true)("defaultItem", i0.ɵɵpureFunction0(29, _c3));
    i0.ɵɵadvance(10);
    i0.ɵɵconditional(ctx_r1.IsLoadingDropdowns ? 43 : 44);
    i0.ɵɵadvance(30);
    i0.ɵɵclassProp("disabled", !((tmp_18_0 = ctx_r1.connectionForm.get("LogToolCalls")) == null ? null : tmp_18_0.value));
    i0.ɵɵadvance(14);
    i0.ɵɵproperty("min", 0)("max", 10485760)("step", 10240)("format", "n0");
    i0.ɵɵadvance(10);
    i0.ɵɵproperty("rows", 3);
    i0.ɵɵadvance(4);
    i0.ɵɵproperty("disabled", ctx_r1.IsSaving);
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r1.IsSaving ? 102 : -1);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", ctx_r1.IsEditMode ? "Update" : "Create", " ");
} }
function MCPConnectionDialogComponent_Conditional_1_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-credential-dialog", 53, 0);
    i0.ɵɵlistener("close", function MCPConnectionDialogComponent_Conditional_1_Template_mj_credential_dialog_close_0_listener($event) { i0.ɵɵrestoreView(_r5); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.onCredentialDialogClose($event)); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("Visible", ctx_r1.ShowCredentialDialog);
} }
/**
 * MCP Connection Dialog Component
 */
export class MCPConnectionDialogComponent {
    fb;
    cdr;
    credentialDialog;
    connection = null;
    servers = [];
    visible = false;
    close = new EventEmitter();
    connectionForm;
    credentials = [];
    companies = [];
    credentialTypes = [];
    IsSaving = false;
    IsLoadingDropdowns = false;
    ErrorMessage = null;
    ShowCredentialDialog = false;
    get IsEditMode() {
        return !!this.connection?.ID;
    }
    get DialogTitle() {
        return this.IsEditMode ? 'Edit Connection' : 'Add Connection';
    }
    get ActiveServers() {
        return this.servers.filter(s => s.Status === 'Active');
    }
    constructor(fb, cdr) {
        this.fb = fb;
        this.cdr = cdr;
        this.connectionForm = this.createForm();
    }
    ngOnInit() {
        this.loadDropdownData();
    }
    ngOnChanges(changes) {
        if (changes['connection'] || changes['visible']) {
            if (this.visible) {
                this.initializeForm();
            }
        }
    }
    createForm() {
        return this.fb.group({
            MCPServerID: ['', Validators.required],
            Name: ['', [Validators.required, Validators.maxLength(200)]],
            Description: ['', Validators.maxLength(2000)],
            CompanyID: [''],
            CredentialID: [''],
            AutoSyncTools: [true],
            LogToolCalls: [true],
            LogInputParameters: [true],
            LogOutputContent: [true],
            MaxOutputLogSize: [102400, [Validators.min(0), Validators.max(10485760)]],
            CustomHeaderName: [''],
            EnvironmentVars: [''],
            Status: ['Active']
        });
    }
    initializeForm() {
        if (this.connection) {
            this.connectionForm.patchValue({
                MCPServerID: this.connection.MCPServerID,
                Name: this.connection.Name,
                Description: this.connection.Description ?? '',
                CompanyID: this.connection.CompanyID ?? '',
                CredentialID: '', // Would need to load from entity
                AutoSyncTools: this.connection.AutoSyncTools,
                LogToolCalls: this.connection.LogToolCalls,
                LogInputParameters: true,
                LogOutputContent: true,
                MaxOutputLogSize: 102400,
                CustomHeaderName: '',
                EnvironmentVars: '',
                Status: this.connection.Status
            });
        }
        else {
            this.connectionForm.reset({
                MCPServerID: '',
                Name: '',
                Description: '',
                CompanyID: '',
                CredentialID: '',
                AutoSyncTools: true,
                LogToolCalls: true,
                LogInputParameters: true,
                LogOutputContent: true,
                MaxOutputLogSize: 102400,
                CustomHeaderName: '',
                EnvironmentVars: '',
                Status: 'Active'
            });
        }
        this.ErrorMessage = null;
        this.cdr.detectChanges();
    }
    async loadDropdownData() {
        this.IsLoadingDropdowns = true;
        try {
            const rv = new RunView();
            // Load credentials, credential types, and companies in parallel
            const [credResult, typeResult, companyResult] = await rv.RunViews([
                {
                    EntityName: 'MJ: Credentials',
                    Fields: ['ID', 'Name'],
                    OrderBy: 'Name',
                    ResultType: 'simple'
                },
                {
                    EntityName: 'MJ: Credential Types',
                    OrderBy: 'Category, Name',
                    ResultType: 'entity_object'
                },
                {
                    EntityName: 'MJ: Companies',
                    Fields: ['ID', 'Name'],
                    OrderBy: 'Name',
                    ResultType: 'simple'
                }
            ]);
            if (credResult.Success) {
                this.credentials = credResult.Results || [];
            }
            if (typeResult.Success) {
                this.credentialTypes = typeResult.Results || [];
            }
            if (companyResult.Success) {
                this.companies = companyResult.Results || [];
            }
        }
        catch (error) {
            console.error('Failed to load dropdown data:', error);
        }
        finally {
            this.IsLoadingDropdowns = false;
            this.cdr.detectChanges();
        }
    }
    /**
     * Opens the credential creation dialog
     */
    openCredentialDialog() {
        this.ShowCredentialDialog = true;
        this.cdr.detectChanges();
    }
    /**
     * Handles the credential dialog close event
     */
    onCredentialDialogClose(result) {
        this.ShowCredentialDialog = false;
        if (result.success && result.credential) {
            // Add the new credential to the list and select it
            this.credentials.push({
                ID: result.credential.ID,
                Name: result.credential.Name
            });
            // Sort credentials by name
            this.credentials.sort((a, b) => a.Name.localeCompare(b.Name));
            // Select the new credential
            this.connectionForm.patchValue({
                CredentialID: result.credential.ID
            });
        }
        this.cdr.detectChanges();
    }
    onServerChange() {
        const serverId = this.connectionForm.get('MCPServerID')?.value;
        const server = this.servers.find(s => UUIDsEqual(s.ID, serverId));
        if (server && !this.connectionForm.get('Name')?.value) {
            // Auto-fill name based on server
            this.connectionForm.patchValue({
                Name: `${server.Name} Connection`
            });
        }
    }
    async save() {
        if (this.connectionForm.invalid) {
            this.connectionForm.markAllAsTouched();
            return;
        }
        this.IsSaving = true;
        this.ErrorMessage = null;
        this.cdr.detectChanges();
        try {
            const md = new Metadata();
            const entity = await md.GetEntityObject('MJ: MCP Server Connections');
            if (this.IsEditMode && this.connection) {
                await entity.InnerLoad(new CompositeKey([{ FieldName: 'ID', Value: this.connection.ID }]));
            }
            else {
                entity.NewRecord();
            }
            // Apply form values
            const formValue = this.connectionForm.value;
            entity.MCPServerID = formValue.MCPServerID;
            entity.Name = formValue.Name;
            entity.Description = formValue.Description || null;
            entity.CompanyID = formValue.CompanyID || null;
            entity.CredentialID = formValue.CredentialID || null;
            entity.AutoSyncTools = formValue.AutoSyncTools;
            entity.LogToolCalls = formValue.LogToolCalls;
            entity.LogInputParameters = formValue.LogInputParameters;
            entity.LogOutputContent = formValue.LogOutputContent;
            entity.MaxOutputLogSize = formValue.MaxOutputLogSize || 102400;
            entity.CustomHeaderName = formValue.CustomHeaderName || null;
            entity.EnvironmentVars = formValue.EnvironmentVars || null;
            entity.Status = formValue.Status;
            const saved = await entity.Save();
            if (!saved) {
                // Use CompleteMessage for full error details, fall back to Message
                const errorMessage = entity.LatestResult?.CompleteMessage || entity.LatestResult?.Message || 'Unknown error';
                console.error('MCP Connection save failed:', errorMessage, entity.LatestResult);
                throw new Error(errorMessage);
            }
            this.close.emit({ saved: true });
        }
        catch (error) {
            const errorMsg = error instanceof Error ? error.message : String(error);
            this.ErrorMessage = `Failed to save: ${errorMsg}`;
            console.error('MCP Connection save error:', errorMsg);
            this.cdr.detectChanges();
        }
        finally {
            this.IsSaving = false;
            this.cdr.detectChanges();
        }
    }
    cancel() {
        this.close.emit({ saved: false });
    }
    hasError(controlName, errorType) {
        const control = this.connectionForm.get(controlName);
        return control?.hasError(errorType) && control?.touched || false;
    }
    static ɵfac = function MCPConnectionDialogComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || MCPConnectionDialogComponent)(i0.ɵɵdirectiveInject(i1.FormBuilder), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: MCPConnectionDialogComponent, selectors: [["mj-mcp-connection-dialog"]], viewQuery: function MCPConnectionDialogComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(_c0, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.credentialDialog = _t.first);
        } }, inputs: { connection: "connection", servers: "servers", visible: "visible" }, outputs: { close: "close" }, standalone: false, features: [i0.ɵɵNgOnChangesFeature], decls: 2, vars: 2, consts: [["credentialDialog", ""], [3, "title", "width", "minWidth"], [3, "Visible"], [3, "close", "title", "width", "minWidth"], [1, "connection-form", 3, "formGroup"], [1, "error-banner"], [1, "form-section"], [1, "fa-solid", "fa-info-circle"], [1, "form-group"], ["for", "server"], [1, "required"], ["id", "server", "formControlName", "MCPServerID", "textField", "Name", "valueField", "ID", 3, "valueChange", "data", "valuePrimitive", "defaultItem"], ["kendoDropDownListItemTemplate", ""], [1, "error-text"], ["for", "name"], ["kendoTextBox", "", "id", "name", "formControlName", "Name", "placeholder", "e.g., Production GitHub Connection"], ["for", "description"], ["kendoTextArea", "", "id", "description", "formControlName", "Description", "placeholder", "Optional description of this connection", 3, "rows"], ["for", "status"], ["id", "status", "formControlName", "Status", 3, "data", "valuePrimitive"], ["for", "company"], ["id", "company", "formControlName", "CompanyID", "textField", "Name", "valueField", "ID", 3, "data", "valuePrimitive", "defaultItem"], [1, "hint"], [1, "fa-solid", "fa-key"], ["for", "credential"], [1, "loading-credentials"], ["for", "customHeader"], ["kendoTextBox", "", "id", "customHeader", "formControlName", "CustomHeaderName", "placeholder", "e.g., X-Custom-API-Key"], [1, "fa-solid", "fa-sliders"], [1, "checkbox-group"], [1, "checkbox-label"], ["type", "checkbox", "kendoCheckBox", "", "formControlName", "AutoSyncTools"], [1, "fa-solid", "fa-file-lines"], ["type", "checkbox", "kendoCheckBox", "", "formControlName", "LogToolCalls"], [1, "logging-options"], ["type", "checkbox", "kendoCheckBox", "", "formControlName", "LogInputParameters"], ["type", "checkbox", "kendoCheckBox", "", "formControlName", "LogOutputContent"], ["for", "maxOutputSize"], ["id", "maxOutputSize", "formControlName", "MaxOutputLogSize", 3, "min", "max", "step", "format"], [1, "fa-solid", "fa-gear"], ["for", "envVars"], ["kendoTextArea", "", "id", "envVars", "formControlName", "EnvironmentVars", "placeholder", "{\"VAR_NAME\": \"value\"}", 3, "rows"], ["kendoButton", "", "themeColor", "primary", 3, "click", "disabled"], [1, "fa-solid", "fa-spinner", "fa-spin"], ["kendoButton", "", 3, "click"], [1, "fa-solid", "fa-exclamation-triangle"], [1, "server-option"], [1, "server-name"], [1, "server-transport"], [1, "credential-row"], ["id", "credential", "formControlName", "CredentialID", "textField", "Name", "valueField", "ID", 3, "data", "valuePrimitive", "defaultItem"], ["kendoButton", "", "type", "button", "fillMode", "outline", "title", "Create New Credential", 3, "click"], [1, "fa-solid", "fa-plus"], [3, "close", "Visible"]], template: function MCPConnectionDialogComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵconditionalCreate(0, MCPConnectionDialogComponent_Conditional_0_Template, 106, 30, "kendo-dialog", 1);
            i0.ɵɵconditionalCreate(1, MCPConnectionDialogComponent_Conditional_1_Template, 2, 1, "mj-credential-dialog", 2);
        } if (rf & 2) {
            i0.ɵɵconditional(ctx.visible ? 0 : -1);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.ShowCredentialDialog ? 1 : -1);
        } }, dependencies: [i1.ɵNgNoValidate, i1.DefaultValueAccessor, i1.CheckboxControlValueAccessor, i1.NgControlStatus, i1.NgControlStatusGroup, i1.FormGroupDirective, i1.FormControlName, i2.ButtonComponent, i3.DialogComponent, i3.DialogActionsComponent, i4.ItemTemplateDirective, i4.DropDownListComponent, i5.TextBoxDirective, i5.NumericTextBoxComponent, i5.TextAreaDirective, i5.CheckBoxDirective, i6.CredentialDialogComponent], styles: [".connection-form[_ngcontent-%COMP%] {\n    display: flex;\n    flex-direction: column;\n    gap: 20px;\n}\n\n.error-banner[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    padding: 12px;\n    background: color-mix(in srgb, var(--mj-status-error) 10%, var(--mj-bg-surface));\n    border: 1px solid var(--mj-status-error);\n    border-radius: 6px;\n    color: var(--mj-status-error);\n    font-size: 14px;\n}\n\n.form-section[_ngcontent-%COMP%] {\n    border: 1px solid var(--mj-border-default);\n    border-radius: 8px;\n    padding: 16px;\n}\n\n.form-section[_ngcontent-%COMP%]   h3[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    margin: 0 0 16px 0;\n    font-size: 14px;\n    font-weight: 600;\n    color: var(--mj-text-primary);\n}\n\n.form-section[_ngcontent-%COMP%]   h3[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n    color: var(--mj-brand-primary);\n}\n\n.form-group[_ngcontent-%COMP%] {\n    margin-bottom: 16px;\n}\n\n.form-group[_ngcontent-%COMP%]:last-child {\n    margin-bottom: 0;\n}\n\n.form-group[_ngcontent-%COMP%]   label[_ngcontent-%COMP%] {\n    display: block;\n    margin-bottom: 6px;\n    font-size: 13px;\n    font-weight: 500;\n    color: var(--mj-text-primary);\n}\n\n.form-group[_ngcontent-%COMP%]   label[_ngcontent-%COMP%]   .required[_ngcontent-%COMP%] {\n    color: var(--mj-status-error);\n}\n\n.form-group[_ngcontent-%COMP%]   input[_ngcontent-%COMP%], \n.form-group[_ngcontent-%COMP%]   textarea[_ngcontent-%COMP%] {\n    width: 100%;\n}\n\n.form-group[_ngcontent-%COMP%]   .hint[_ngcontent-%COMP%] {\n    display: block;\n    margin-top: 4px;\n    font-size: 12px;\n    color: var(--mj-text-disabled);\n}\n\n.form-group[_ngcontent-%COMP%]   .error-text[_ngcontent-%COMP%] {\n    display: block;\n    margin-top: 4px;\n    font-size: 12px;\n    color: var(--mj-status-error);\n}\n\n.server-option[_ngcontent-%COMP%] {\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n    width: 100%;\n}\n\n.server-name[_ngcontent-%COMP%] {\n    font-weight: 500;\n}\n\n.server-transport[_ngcontent-%COMP%] {\n    font-size: 12px;\n    color: var(--mj-text-muted);\n    padding: 2px 8px;\n    background: var(--mj-bg-surface-card);\n    border-radius: 4px;\n}\n\n.loading-credentials[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    padding: 8px 12px;\n    background: var(--mj-bg-surface-card);\n    border-radius: 6px;\n    color: var(--mj-text-muted);\n    font-size: 14px;\n}\n\n.credential-row[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n}\n\n.credential-row[_ngcontent-%COMP%]   kendo-dropdownlist[_ngcontent-%COMP%] {\n    flex: 1;\n}\n\n.credential-row[_ngcontent-%COMP%]   button[_ngcontent-%COMP%] {\n    white-space: nowrap;\n}\n\n.checkbox-group[_ngcontent-%COMP%] {\n    margin-bottom: 12px;\n}\n\n.checkbox-group[_ngcontent-%COMP%]:last-child {\n    margin-bottom: 0;\n}\n\n.checkbox-label[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    cursor: pointer;\n    font-size: 14px;\n}\n\n.checkbox-group[_ngcontent-%COMP%]   .hint[_ngcontent-%COMP%] {\n    display: block;\n    margin-top: 4px;\n    margin-left: 24px;\n    font-size: 12px;\n    color: var(--mj-text-disabled);\n}\n\n.logging-options[_ngcontent-%COMP%] {\n    margin-top: 16px;\n    padding: 12px;\n    background: var(--mj-bg-surface-card);\n    border-radius: 6px;\n    transition: opacity 0.2s ease;\n}\n\n.logging-options.disabled[_ngcontent-%COMP%] {\n    opacity: 0.5;\n    pointer-events: none;\n}\n\n\n\n[_nghost-%COMP%]     .k-dialog-actions {\n    padding: 16px;\n    border-top: 1px solid var(--mj-border-default);\n}\n\n[_nghost-%COMP%]     .k-dialog-content {\n    padding: 20px;\n    max-height: 70vh;\n    overflow-y: auto;\n}\n\n[_nghost-%COMP%]     .k-textbox, \n[_nghost-%COMP%]     .k-textarea, \n[_nghost-%COMP%]     .k-numerictextbox, \n[_nghost-%COMP%]     .k-dropdownlist {\n    width: 100%;\n}"] });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MCPConnectionDialogComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-mcp-connection-dialog', template: "@if (visible) {\n  <kendo-dialog\n    [title]=\"DialogTitle\"\n    (close)=\"cancel()\"\n    [width]=\"600\"\n    [minWidth]=\"400\">\n    <form [formGroup]=\"connectionForm\" class=\"connection-form\">\n      <!-- Error Message -->\n      @if (ErrorMessage) {\n        <div class=\"error-banner\">\n          <i class=\"fa-solid fa-exclamation-triangle\"></i>\n          {{ ErrorMessage }}\n        </div>\n      }\n      <!-- Basic Info Section -->\n      <div class=\"form-section\">\n        <h3><i class=\"fa-solid fa-info-circle\"></i> Basic Information</h3>\n        <div class=\"form-group\">\n          <label for=\"server\">MCP Server <span class=\"required\">*</span></label>\n          <kendo-dropdownlist\n            id=\"server\"\n            formControlName=\"MCPServerID\"\n            [data]=\"ActiveServers\"\n            textField=\"Name\"\n            valueField=\"ID\"\n            [valuePrimitive]=\"true\"\n            [defaultItem]=\"{ Name: 'Select a server...', ID: '' }\"\n            (valueChange)=\"onServerChange()\">\n            <ng-template kendoDropDownListItemTemplate let-dataItem>\n              <div class=\"server-option\">\n                <span class=\"server-name\">{{ dataItem.Name }}</span>\n                @if (dataItem.TransportType) {\n                  <span class=\"server-transport\">{{ dataItem.TransportType }}</span>\n                }\n              </div>\n            </ng-template>\n          </kendo-dropdownlist>\n          @if (hasError('MCPServerID', 'required')) {\n            <span class=\"error-text\">Server selection is required</span>\n          }\n        </div>\n        <div class=\"form-group\">\n          <label for=\"name\">Connection Name <span class=\"required\">*</span></label>\n          <input kendoTextBox\n            id=\"name\"\n            formControlName=\"Name\"\n            placeholder=\"e.g., Production GitHub Connection\" />\n          @if (hasError('Name', 'required')) {\n            <span class=\"error-text\">Name is required</span>\n          }\n        </div>\n        <div class=\"form-group\">\n          <label for=\"description\">Description</label>\n          <textarea kendoTextArea\n            id=\"description\"\n            formControlName=\"Description\"\n            placeholder=\"Optional description of this connection\"\n          [rows]=\"3\"></textarea>\n        </div>\n        <div class=\"form-group\">\n          <label for=\"status\">Status</label>\n          <kendo-dropdownlist\n            id=\"status\"\n            formControlName=\"Status\"\n            [data]=\"['Active', 'Inactive']\"\n            [valuePrimitive]=\"true\">\n          </kendo-dropdownlist>\n        </div>\n        <div class=\"form-group\">\n          <label for=\"company\">Company</label>\n          <kendo-dropdownlist\n            id=\"company\"\n            formControlName=\"CompanyID\"\n            [data]=\"companies\"\n            textField=\"Name\"\n            valueField=\"ID\"\n            [valuePrimitive]=\"true\"\n            [defaultItem]=\"{ Name: 'Global (all companies)', ID: '' }\">\n          </kendo-dropdownlist>\n          <span class=\"hint\">Leave as Global to make this connection available to all companies</span>\n        </div>\n      </div>\n      <!-- Authentication Section -->\n      <div class=\"form-section\">\n        <h3><i class=\"fa-solid fa-key\"></i> Authentication</h3>\n        <div class=\"form-group\">\n          <label for=\"credential\">Credential</label>\n          @if (IsLoadingDropdowns) {\n            <div class=\"loading-credentials\">\n              <i class=\"fa-solid fa-spinner fa-spin\"></i>\n              Loading credentials...\n            </div>\n          } @else {\n            <div class=\"credential-row\">\n              <kendo-dropdownlist\n                id=\"credential\"\n                formControlName=\"CredentialID\"\n                [data]=\"credentials\"\n                textField=\"Name\"\n                valueField=\"ID\"\n                [valuePrimitive]=\"true\"\n                [defaultItem]=\"{ Name: 'No credential (anonymous)', ID: '' }\">\n              </kendo-dropdownlist>\n              <button kendoButton\n                type=\"button\"\n                fillMode=\"outline\"\n                (click)=\"openCredentialDialog()\"\n                title=\"Create New Credential\">\n                <i class=\"fa-solid fa-plus\"></i>\n                New\n              </button>\n            </div>\n            <span class=\"hint\">Select an existing credential or create a new one</span>\n          }\n        </div>\n        <div class=\"form-group\">\n          <label for=\"customHeader\">Custom Header Name</label>\n          <input kendoTextBox\n            id=\"customHeader\"\n            formControlName=\"CustomHeaderName\"\n            placeholder=\"e.g., X-Custom-API-Key\" />\n          <span class=\"hint\">Override the default header name for API key authentication</span>\n        </div>\n      </div>\n      <!-- Behavior Section -->\n      <div class=\"form-section\">\n        <h3><i class=\"fa-solid fa-sliders\"></i> Behavior</h3>\n        <div class=\"checkbox-group\">\n          <label class=\"checkbox-label\">\n            <input type=\"checkbox\" kendoCheckBox formControlName=\"AutoSyncTools\" />\n            <span>Auto-sync tools on connect</span>\n          </label>\n          <span class=\"hint\">Automatically discover and sync available tools when connecting</span>\n        </div>\n      </div>\n      <!-- Logging Section -->\n      <div class=\"form-section\">\n        <h3><i class=\"fa-solid fa-file-lines\"></i> Logging</h3>\n        <div class=\"checkbox-group\">\n          <label class=\"checkbox-label\">\n            <input type=\"checkbox\" kendoCheckBox formControlName=\"LogToolCalls\" />\n            <span>Enable tool call logging</span>\n          </label>\n          <span class=\"hint\">Log all tool executions to the database</span>\n        </div>\n        <div class=\"logging-options\" [class.disabled]=\"!connectionForm.get('LogToolCalls')?.value\">\n          <div class=\"checkbox-group\">\n            <label class=\"checkbox-label\">\n              <input type=\"checkbox\" kendoCheckBox formControlName=\"LogInputParameters\" />\n              <span>Log input parameters</span>\n            </label>\n          </div>\n          <div class=\"checkbox-group\">\n            <label class=\"checkbox-label\">\n              <input type=\"checkbox\" kendoCheckBox formControlName=\"LogOutputContent\" />\n              <span>Log output content</span>\n            </label>\n          </div>\n          <div class=\"form-group\">\n            <label for=\"maxOutputSize\">Max Output Log Size (bytes)</label>\n            <kendo-numerictextbox\n              id=\"maxOutputSize\"\n              formControlName=\"MaxOutputLogSize\"\n              [min]=\"0\"\n              [max]=\"10485760\"\n              [step]=\"10240\"\n              [format]=\"'n0'\">\n            </kendo-numerictextbox>\n            <span class=\"hint\">Maximum size of output content to log (0 = unlimited, max 10MB)</span>\n          </div>\n        </div>\n      </div>\n      <!-- Advanced Section -->\n      <div class=\"form-section\">\n        <h3><i class=\"fa-solid fa-gear\"></i> Advanced</h3>\n        <div class=\"form-group\">\n          <label for=\"envVars\">Environment Variables (JSON)</label>\n          <textarea kendoTextArea\n            id=\"envVars\"\n            formControlName=\"EnvironmentVars\"\n            placeholder='{\"VAR_NAME\": \"value\"}'\n          [rows]=\"3\"></textarea>\n          <span class=\"hint\">Additional environment variables for Stdio transport (JSON object)</span>\n        </div>\n      </div>\n    </form>\n    <kendo-dialog-actions>\n      <button kendoButton (click)=\"save()\" themeColor=\"primary\" [disabled]=\"IsSaving\">\n        @if (IsSaving) {\n          <i class=\"fa-solid fa-spinner fa-spin\"></i>\n        }\n        {{ IsEditMode ? 'Update' : 'Create' }}\n      </button>\n      <button kendoButton (click)=\"cancel()\">Cancel</button>\n    </kendo-dialog-actions>\n  </kendo-dialog>\n}\n\n<!-- Credential Creation Dialog -->\n@if (ShowCredentialDialog) {\n  <mj-credential-dialog\n    #credentialDialog\n    [Visible]=\"ShowCredentialDialog\"\n    (close)=\"onCredentialDialogClose($event)\">\n  </mj-credential-dialog>\n}\n", styles: [".connection-form {\n    display: flex;\n    flex-direction: column;\n    gap: 20px;\n}\n\n.error-banner {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    padding: 12px;\n    background: color-mix(in srgb, var(--mj-status-error) 10%, var(--mj-bg-surface));\n    border: 1px solid var(--mj-status-error);\n    border-radius: 6px;\n    color: var(--mj-status-error);\n    font-size: 14px;\n}\n\n.form-section {\n    border: 1px solid var(--mj-border-default);\n    border-radius: 8px;\n    padding: 16px;\n}\n\n.form-section h3 {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    margin: 0 0 16px 0;\n    font-size: 14px;\n    font-weight: 600;\n    color: var(--mj-text-primary);\n}\n\n.form-section h3 i {\n    color: var(--mj-brand-primary);\n}\n\n.form-group {\n    margin-bottom: 16px;\n}\n\n.form-group:last-child {\n    margin-bottom: 0;\n}\n\n.form-group label {\n    display: block;\n    margin-bottom: 6px;\n    font-size: 13px;\n    font-weight: 500;\n    color: var(--mj-text-primary);\n}\n\n.form-group label .required {\n    color: var(--mj-status-error);\n}\n\n.form-group input,\n.form-group textarea {\n    width: 100%;\n}\n\n.form-group .hint {\n    display: block;\n    margin-top: 4px;\n    font-size: 12px;\n    color: var(--mj-text-disabled);\n}\n\n.form-group .error-text {\n    display: block;\n    margin-top: 4px;\n    font-size: 12px;\n    color: var(--mj-status-error);\n}\n\n.server-option {\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n    width: 100%;\n}\n\n.server-name {\n    font-weight: 500;\n}\n\n.server-transport {\n    font-size: 12px;\n    color: var(--mj-text-muted);\n    padding: 2px 8px;\n    background: var(--mj-bg-surface-card);\n    border-radius: 4px;\n}\n\n.loading-credentials {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    padding: 8px 12px;\n    background: var(--mj-bg-surface-card);\n    border-radius: 6px;\n    color: var(--mj-text-muted);\n    font-size: 14px;\n}\n\n.credential-row {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n}\n\n.credential-row kendo-dropdownlist {\n    flex: 1;\n}\n\n.credential-row button {\n    white-space: nowrap;\n}\n\n.checkbox-group {\n    margin-bottom: 12px;\n}\n\n.checkbox-group:last-child {\n    margin-bottom: 0;\n}\n\n.checkbox-label {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    cursor: pointer;\n    font-size: 14px;\n}\n\n.checkbox-group .hint {\n    display: block;\n    margin-top: 4px;\n    margin-left: 24px;\n    font-size: 12px;\n    color: var(--mj-text-disabled);\n}\n\n.logging-options {\n    margin-top: 16px;\n    padding: 12px;\n    background: var(--mj-bg-surface-card);\n    border-radius: 6px;\n    transition: opacity 0.2s ease;\n}\n\n.logging-options.disabled {\n    opacity: 0.5;\n    pointer-events: none;\n}\n\n/* Kendo overrides */\n:host ::ng-deep .k-dialog-actions {\n    padding: 16px;\n    border-top: 1px solid var(--mj-border-default);\n}\n\n:host ::ng-deep .k-dialog-content {\n    padding: 20px;\n    max-height: 70vh;\n    overflow-y: auto;\n}\n\n:host ::ng-deep .k-textbox,\n:host ::ng-deep .k-textarea,\n:host ::ng-deep .k-numerictextbox,\n:host ::ng-deep .k-dropdownlist {\n    width: 100%;\n}\n"] }]
    }], () => [{ type: i1.FormBuilder }, { type: i0.ChangeDetectorRef }], { credentialDialog: [{
            type: ViewChild,
            args: ['credentialDialog']
        }], connection: [{
            type: Input
        }], servers: [{
            type: Input
        }], visible: [{
            type: Input
        }], close: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(MCPConnectionDialogComponent, { className: "MCPConnectionDialogComponent", filePath: "src/MCP/components/mcp-connection-dialog.component.ts", lineNumber: 32 }); })();
//# sourceMappingURL=mcp-connection-dialog.component.js.map