/**
 * @fileoverview MCP (Model Context Protocol) Management Dashboard
 *
 * Provides a comprehensive admin interface for managing MCP servers,
 * connections, tools, and viewing execution logs.
 *
 * Uses left sidebar navigation with query string deep linking via NavigationService.
 *
 * @module MCP Dashboard
 */
import { OnDestroy, ChangeDetectorRef, AfterViewInit, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { BehaviorSubject } from 'rxjs';
import { BaseDashboard, NavigationService } from '@memberjunction/ng-shared';
import { ResourceData } from '@memberjunction/core-entities';
import { MCPToolsService, MCPSyncState } from './services/mcp-tools.service';
import * as i0 from "@angular/core";
/**
 * Interface for MCP Server data
 */
export interface MCPServerData {
    ID: string;
    Name: string;
    Description: string | null;
    TransportType: string;
    ServerURL: string | null;
    Command: string | null;
    DefaultAuthType: string;
    Status: string;
    RateLimitPerMinute: number | null;
    RateLimitPerHour: number | null;
    LastSyncAt: Date | null;
    ConnectionCount?: number;
    ToolCount?: number;
    OAuthIssuerURL?: string | null;
    OAuthScopes?: string | null;
    OAuthMetadataCacheTTLMinutes?: number | null;
    OAuthClientID?: string | null;
    OAuthClientSecretEncrypted?: string | null;
    OAuthRequirePKCE?: boolean;
}
/**
 * Interface for MCP Connection data
 */
export interface MCPConnectionData {
    ID: string;
    MCPServerID: string;
    ServerName?: string;
    Name: string;
    Description: string | null;
    Status: string;
    CompanyID: string | null;
    AutoSyncTools: boolean;
    LogToolCalls: boolean;
    LastConnectedAt: Date | null;
    LastErrorMessage: string | null;
}
/**
 * Interface for MCP Tool data
 */
export interface MCPToolData {
    ID: string;
    MCPServerID: string;
    ServerName?: string;
    ToolName: string;
    ToolTitle: string | null;
    ToolDescription: string | null;
    InputSchema: string;
    Status: string;
    DiscoveredAt: Date;
    LastSeenAt: Date;
}
/**
 * Interface for server group (tools grouped by server)
 */
export interface MCPServerGroup {
    server: MCPServerData;
    tools: MCPToolData[];
    expanded: boolean;
}
/**
 * Tools view mode
 */
export type ToolsViewMode = 'card' | 'list';
/**
 * Tools sort options
 */
export type ToolsSortBy = 'name' | 'server' | 'discovered' | 'lastSeen';
/**
 * Interface for MCP Execution Log data
 */
export interface MCPExecutionLogData {
    ID: string;
    ConnectionID: string;
    ConnectionName?: string;
    ToolID: string | null;
    ToolName: string;
    Status: string;
    StartedAt: Date;
    CompletedAt: Date | null;
    DurationMs: number | null;
    UserID: string;
    UserName?: string;
    ErrorMessage: string | null;
    InputArgs?: string | null;
    Result?: string | null;
    ServerName?: string;
}
/**
 * Dashboard filter options
 */
export interface MCPDashboardFilters {
    searchTerm: string;
    serverStatus: string;
    connectionStatus: string;
    toolStatus: string;
    logStatus: string;
}
/**
 * Dashboard statistics
 */
export interface MCPDashboardStats {
    totalServers: number;
    activeServers: number;
    totalConnections: number;
    activeConnections: number;
    totalTools: number;
    activeTools: number;
    recentExecutions: number;
    failedExecutions: number;
}
/**
 * Active tab type
 */
export type MCPDashboardTab = 'servers' | 'connections' | 'tools' | 'logs';
/**
 * MCP Management Dashboard Component
 *
 * Provides a tab-based interface for managing:
 * - MCP Servers
 * - MCP Connections
 * - MCP Tools
 * - Execution Logs
 */
export declare class MCPDashboardComponent extends BaseDashboard implements OnInit, AfterViewInit, OnDestroy {
    private cdr;
    private router;
    private route;
    private navigationService;
    private mcpToolsService;
    private readonly USER_SETTINGS_KEY;
    private settingsPersistSubject;
    private settingsLoaded;
    private metadata;
    servers: MCPServerData[];
    connections: MCPConnectionData[];
    tools: MCPToolData[];
    executionLogs: MCPExecutionLogData[];
    filteredServers: MCPServerData[];
    filteredConnections: MCPConnectionData[];
    filteredTools: MCPToolData[];
    filteredLogs: MCPExecutionLogData[];
    stats: MCPDashboardStats;
    ActiveTab: MCPDashboardTab;
    IsLoading: boolean;
    ErrorMessage: string | null;
    filters$: BehaviorSubject<MCPDashboardFilters>;
    ShowServerDialog: boolean;
    ShowConnectionDialog: boolean;
    ShowTestToolDialog: boolean;
    EditingServer: MCPServerData | null;
    EditingConnection: MCPConnectionData | null;
    TestToolServerID: string | null;
    TestToolConnectionID: string | null;
    TestToolID: string | null;
    ShowLogDetailPanel: boolean;
    SelectedLog: MCPExecutionLogData | null;
    ExpandedServerID: string | null;
    ExpandedConnectionID: string | null;
    LogsSortColumn: 'status' | 'server' | 'tool' | 'connection' | 'started' | 'duration' | 'error';
    LogsSortAscending: boolean;
    ToolsViewMode: ToolsViewMode;
    ToolsSortBy: ToolsSortBy;
    ToolsSortAscending: boolean;
    ServerGroups: MCPServerGroup[];
    ExpandedToolId: string | null;
    private skipUrlUpdate;
    private lastNavigatedUrl;
    SyncStates: Map<string, MCPSyncState>;
    private syncSubscriptions;
    FilterPanelVisible: boolean;
    private destroy$;
    constructor(cdr: ChangeDetectorRef, router: Router, route: ActivatedRoute, navigationService: NavigationService, mcpToolsService: MCPToolsService);
    ngOnInit(): Promise<void>;
    /**
     * Parses the current URL query string and applies the tab state
     */
    private parseAndApplyUrlState;
    /**
     * Parses URL query string to extract navigation state
     */
    private parseUrlState;
    /**
     * Validates that a tab value is a valid MCPDashboardTab
     */
    private isValidTab;
    /**
     * Applies configuration params passed via NavigationService
     */
    private applyConfigurationParams;
    /**
     * Subscribes to router NavigationEnd events to handle browser back/forward
     */
    private subscribeToRouterEvents;
    /**
     * Load saved user preferences from the UserInfoEngine
     */
    private loadUserPreferences;
    /**
     * Apply loaded preferences to component state
     */
    private applyUserPreferencesFromStorage;
    /**
     * Get current preferences as an object for saving
     */
    private getCurrentPreferences;
    /**
     * Persist user preferences to storage (debounced)
     */
    private saveUserPreferencesDebounced;
    /**
     * Actually persist user preferences to the UserInfoEngine
     */
    private persistUserPreferences;
    /**
     * Handles external navigation (browser back/forward)
     */
    private onExternalNavigation;
    /**
     * Updates URL query string to reflect current state using NavigationService
     */
    private updateUrl;
    GetResourceDisplayName(data: ResourceData): Promise<string>;
    protected initDashboard(): void;
    protected loadData(): void;
    ngAfterViewInit(): void;
    ngOnDestroy(): void;
    /**
     * Loads all dashboard data using MCPEngine for cached entities
     * and RunView for execution logs (historical data loaded on-demand)
     * @param forceRefresh - If true, forces MCPEngine to reload from database (use after sync operations)
     */
    loadAllData(forceRefresh?: boolean): Promise<void>;
    private enrichServerData;
    private enrichConnectionData;
    private enrichToolData;
    private enrichLogData;
    /**
     * Maps database log entity to UI interface format
     * Handles column name differences between DB schema and UI interface
     */
    private mapLogFromDatabase;
    private calculateStats;
    private setupFilterSubscription;
    applyFilters(): void;
    onSearchChange(term: string): void;
    onStatusFilterChange(filterType: string, value: string): void;
    /**
     * Toggle filter panel visibility
     */
    toggleFilterPanel(): void;
    /**
     * Handle filter changes from the filter panel component
     */
    onFiltersChange(filters: MCPDashboardFilters): void;
    /**
     * Get the current filtered count based on active tab
     */
    get CurrentFilteredCount(): number;
    /**
     * Get the total count based on active tab
     */
    get CurrentTotalCount(): number;
    /**
     * Get current filters value (non-observable)
     */
    get CurrentFilters(): MCPDashboardFilters;
    /**
     * Sets the active tab and updates URL for deep linking
     */
    setActiveTab(tab: MCPDashboardTab): void;
    createServer(): void;
    editServer(server: MCPServerData): void;
    deleteServer(server: MCPServerData): Promise<void>;
    /**
     * Internal helper to delete a tool by ID without confirmation
     */
    private deleteToolInternal;
    /**
     * Internal helper to delete a connection by ID without confirmation.
     * Handles deletion of all related records that don't have ON DELETE CASCADE:
     * - MCP Tool Execution Logs
     * - OAuth Authorization States
     * - OAuth Client Registrations
     * - OAuth Tokens
     */
    private deleteConnectionInternal;
    onServerDialogClose(result: {
        saved: boolean;
    }): Promise<void>;
    createConnection(): void;
    editConnection(connection: MCPConnectionData): void;
    deleteConnection(connection: MCPConnectionData): Promise<void>;
    onConnectionDialogClose(result: {
        saved: boolean;
    }): Promise<void>;
    /**
     * Toggle tool card expansion for details view
     */
    toggleToolExpand(tool: MCPToolData): void;
    /**
     * Check if a tool card is expanded
     */
    isToolExpanded(tool: MCPToolData): boolean;
    /**
     * Set tools view mode (card or list)
     */
    setToolsViewMode(mode: ToolsViewMode): void;
    /**
     * Set tools sort option
     */
    setToolsSort(sortBy: ToolsSortBy): void;
    /**
     * Toggle server group expansion
     */
    toggleServerGroup(group: MCPServerGroup): void;
    /**
     * Build server groups from tools data
     */
    private buildServerGroups;
    /**
     * Sort tools array in place
     */
    private sortTools;
    /**
     * Get total tool count across all groups
     */
    get TotalToolCount(): number;
    /**
     * Open Test Tool dialog
     */
    openTestToolDialog(tool?: MCPToolData, connection?: MCPConnectionData): void;
    /**
     * Close Test Tool dialog
     */
    onTestToolDialogClose(): void;
    /**
     * Parse and return input schema as formatted JSON
     */
    getFormattedInputSchema(tool: MCPToolData): string;
    /**
     * Get parameter count from input schema
     */
    getParamCount(tool: MCPToolData): number;
    /**
     * Get required parameter count from input schema
     */
    getRequiredParamCount(tool: MCPToolData): number;
    /**
     * Syncs tools for a specific connection
     */
    syncConnectionTools(connection: MCPConnectionData): Promise<void>;
    /**
     * Gets the sync state for a connection
     */
    getSyncState(connectionId: string): MCPSyncState | undefined;
    /**
     * Checks if a connection is currently syncing
     */
    isSyncing(connectionId: string): boolean;
    /**
     * Gets sync progress message for a connection
     */
    getSyncProgressMessage(connectionId: string): string;
    /**
     * Checks for OAuth completion by looking for query params set by the OAuth callback
     */
    private checkOAuthCompletion;
    /**
     * Shows a success notification (temporary)
     */
    private showSuccessNotification;
    /**
     * Initiates OAuth authorization flow for a connection.
     * Stores the current URL and redirects directly to the OAuth provider.
     * Always uses the frontend callback URL so the OAuth redirect comes back to MJExplorer.
     *
     * @param connectionId - The MCP connection ID requiring OAuth
     */
    initiateOAuthFlow(connectionId: string): Promise<void>;
    /**
     * Calls the InitiateMCPOAuth mutation with frontend callback URL
     */
    private initiateMCPOAuth;
    getStatusClass(status: string): string;
    getTransportIcon(transportType: string): string;
    formatDate(date: Date | string | null): string;
    formatDuration(ms: number | null): string;
    /**
     * Handles click on a sortable column header
     */
    onLogSortColumn(column: typeof this.LogsSortColumn): void;
    /**
     * Sorts the filtered logs based on current sort settings
     */
    private sortFilteredLogs;
    /**
     * Gets the sort indicator class for a column header
     */
    getLogSortClass(column: typeof this.LogsSortColumn): string;
    /**
     * Handles click on a log row to show detail panel
     */
    onLogClick(log: MCPExecutionLogData): Promise<void>;
    /**
     * Closes the log detail panel
     */
    onLogDetailClose(): void;
    /**
     * Handles run again from log detail panel
     */
    onRunAgainFromLog(event: {
        toolId: string;
        connectionId: string;
    }): void;
    /**
     * Toggles server card expansion
     */
    toggleServerExpand(server: MCPServerData): void;
    /**
     * Toggles connection card expansion
     */
    toggleConnectionExpand(conn: MCPConnectionData): void;
    /**
     * Checks if a server card is expanded
     */
    isServerExpanded(server: MCPServerData): boolean;
    /**
     * Checks if a connection card is expanded
     */
    isConnectionExpanded(conn: MCPConnectionData): boolean;
    /**
     * Gets tools for a specific server
     */
    getToolsForServer(serverId: string): MCPToolData[];
    /**
     * Gets tools for a specific connection (via its server)
     */
    getToolsForConnection(connectionId: string): MCPToolData[];
    /**
     * Opens test tool dialog with a specific tool from expanded card
     */
    runToolFromCard(tool: MCPToolData, connection?: MCPConnectionData): void;
    static ɵfac: i0.ɵɵFactoryDeclaration<MCPDashboardComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<MCPDashboardComponent, "mj-mcp-dashboard", never, {}, {}, never, never, false, never>;
}
//# sourceMappingURL=mcp-dashboard.component.d.ts.map