import { ChangeDetectionStrategy, ChangeDetectorRef, Component, inject, } from '@angular/core';
import { CompositeKey, LogError } from '@memberjunction/core';
import { UUIDsEqual } from '@memberjunction/global';
import { AIEngineBase } from '@memberjunction/ai-engine-base';
import { BaseAngularComponent } from '@memberjunction/ng-base-types';
import { Subject, takeUntil } from 'rxjs';
import { MJEnvironmentEntityExtended } from '@memberjunction/core-entities';
import { NavigationService } from '@memberjunction/ng-shared';
import * as i0 from "@angular/core";
import * as i1 from "../../services/component-studio-state.service";
import * as i2 from "@memberjunction/ng-conversations";
const _forTrack0 = ($index, $item) => $item.Label;
function AIAssistantPanelComponent_For_10_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 11);
    i0.ɵɵlistener("click", function AIAssistantPanelComponent_For_10_Template_button_click_0_listener() { const action_r2 = i0.ɵɵrestoreView(_r1).$implicit; const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnQuickAction(action_r2)); });
    i0.ɵɵelement(1, "i");
    i0.ɵɵelementStart(2, "span");
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const action_r2 = ctx.$implicit;
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵclassProp("disabled", !ctx_r2.IsQuickActionEnabled(action_r2));
    i0.ɵɵproperty("disabled", !ctx_r2.IsQuickActionEnabled(action_r2))("title", action_r2.Label);
    i0.ɵɵadvance();
    i0.ɵɵclassMap(i0.ɵɵinterpolate1("fa-solid ", action_r2.Icon));
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(action_r2.Label);
} }
function AIAssistantPanelComponent_Conditional_12_Template(rf, ctx) { if (rf & 1) {
    const _r4 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-conversation-chat-area", 12);
    i0.ɵɵlistener("conversationCreated", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_conversationCreated_0_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnConversationCreated($event)); })("pendingMessageConsumed", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_pendingMessageConsumed_0_listener() { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnPendingMessageConsumed()); })("openEntityRecord", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_openEntityRecord_0_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnOpenEntityRecord($event)); })("navigationRequest", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_navigationRequest_0_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnNavigationRequest($event)); })("taskClicked", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_taskClicked_0_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnTaskClicked($event)); })("artifactLinkClicked", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_artifactLinkClicked_0_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnArtifactLinkClicked($event)); })("conversationRenamed", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_conversationRenamed_0_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnConversationRenamed($event)); })("threadOpened", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_threadOpened_0_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnThreadOpened($event)); })("threadClosed", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_threadClosed_0_listener() { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnThreadClosed()); })("pendingArtifactConsumed", function AIAssistantPanelComponent_Conditional_12_Template_mj_conversation_chat_area_pendingArtifactConsumed_0_listener() { i0.ɵɵrestoreView(_r4); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.OnPendingArtifactConsumed()); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵproperty("Provider", ctx_r2.Provider)("environmentId", ctx_r2.EnvironmentId)("currentUser", ctx_r2.CurrentUser)("conversationId", ctx_r2.ChatConversationId)("conversation", ctx_r2.ChatConversation)("isNewConversation", ctx_r2.ChatIsNewConversation)("pendingMessage", ctx_r2.PendingMessage)("pendingAttachments", ctx_r2.PendingAttachments)("threadId", ctx_r2.ChatThreadId)("pendingArtifactId", ctx_r2.ChatPendingArtifactId)("pendingArtifactVersionNumber", ctx_r2.ChatPendingArtifactVersionNumber)("overlayMode", true)("showExportButton", false)("showShareButton", false)("showArtifactIndicator", false)("appContext", ctx_r2.ChatAppContext)("defaultAgentId", ctx_r2.CodesmithAgentId)("applicationScope", "Application")("applicationId", ctx_r2.CockpitApplicationId)("linkedEntityId", ctx_r2.ComponentsEntityID)("linkedRecordId", ctx_r2.LinkedComponentID)("emptyStateGreeting", "How can I help with this component?");
} }
function AIAssistantPanelComponent_Conditional_13_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 10);
    i0.ɵɵtext(1, "Loading\u2026");
    i0.ɵɵelementEnd();
} }
/**
 * Component Studio's right-pane AI assistant.
 *
 * Previously this was a 880-line bespoke chat stub that emitted "AI
 * assistant coming soon" — no agent was actually called. This version
 * thin-wraps `<mj-conversation-chat-area>` (the same primitive the main
 * Chat app and the Form Builder cockpit use) so the assistant becomes
 * fully functional with zero duplicated chat plumbing.
 *
 * Domain integration preserved from the old stub:
 *   - **Quick-actions bar** (Fix Errors / Improve / Generate / Explain)
 *     above the chat — clicking sets `PendingMessage` which the chat-area
 *     consumes on the next render, mirroring the empty-state handoff.
 *   - **`SendErrorToAI` channel** — when the runtime preview throws, the
 *     state service emits a `ComponentError`. We listen and shove a
 *     "Fix this error: …" message into the same pendingMessage pipe so
 *     the user doesn't have to copy/paste error text.
 *
 * Scoping:
 *   - `[applicationScope]="'Application'"` + Component Studio app ID →
 *     conversations stay out of main chat (per the migration scoping work).
 *   - `[defaultAgentId]` → Codesmith Agent so messages route to the code
 *     specialist instead of Sage by default. User can still @mention any
 *     agent, override via the per-conversation pin, or pick a different
 *     agent through the chat header's picker.
 */
export class AIAssistantPanelComponent extends BaseAngularComponent {
    State;
    /** Quick actions surfaced as buttons above the embedded chat. */
    QuickActions = [
        { Label: 'Fix Errors', Icon: 'fa-bug', Prompt: 'Fix this error: ', RequiresError: true },
        { Label: 'Improve Code', Icon: 'fa-magic', Prompt: 'Review and improve the current component code. Suggest optimizations, better patterns, and cleaner structure.', RequiresError: false },
        { Label: 'Generate Code', Icon: 'fa-code', Prompt: 'Generate code for the current component based on its specification.', RequiresError: false },
        { Label: 'Explain', Icon: 'fa-question-circle', Prompt: 'Explain what the current component does, including its structure, data flow, and key behaviors.', RequiresError: false },
    ];
    /** Embedded chat state — same shape the Form Builder cockpit uses. */
    ChatConversation = null;
    ChatConversationId = null;
    ChatIsNewConversation = true;
    PendingMessage = null;
    PendingAttachments = null;
    ChatThreadId = null;
    ChatPendingArtifactId = null;
    ChatPendingArtifactVersionNumber = null;
    /** Snapshot from NavigationService — drives the agent's app context. */
    ChatAppContext = null;
    /** Codesmith Agent ID resolved from AIEngineBase cache (no RunView). */
    CodesmithAgentId = null;
    /** Component Studio's Application ID — resolved from Metadata cache. */
    CockpitApplicationId = null;
    /**
     * EntityID for `MJ: Components`. Stamped on every conversation
     * created from this panel as the `LinkedEntityID`, paired with the
     * currently-selected Component's ID. Enables "show prior conversations
     * about THIS component" later. In-memory Metadata lookup; no RunView.
     */
    ComponentsEntityID = null;
    /**
     * The DB-backed Component ID currently selected — null when the
     * panel has nothing selected, or when the selection is a
     * file-loaded (transient) component that has no persistent DB row
     * to link conversations to. Used as `[linkedRecordId]` on the
     * embedded chat-area. Pairs with {@link ComponentsEntityID}.
     */
    get LinkedComponentID() {
        const sel = this.State.SelectedComponent;
        if (!sel)
            return null;
        // FileLoadedComponent has `isFileLoaded === true` and a lower-case
        // `id`; DbComponentSummary has the canonical `ID`. Discriminate by
        // the flag rather than property presence to keep TS happy.
        if ('isFileLoaded' in sel && sel.isFileLoaded === true)
            return null;
        return sel.ID ?? null;
    }
    static CODESMITH_AGENT_NAME = 'Codesmith Agent';
    static COCKPIT_APP_NAME = 'Component Studio';
    destroy$ = new Subject();
    appContextSubscription = null;
    cdr = inject(ChangeDetectorRef);
    navigationService = inject(NavigationService);
    constructor(State) {
        super();
        this.State = State;
    }
    get EnvironmentId() {
        return MJEnvironmentEntityExtended.DefaultEnvironmentID;
    }
    get CurrentUser() {
        return this.ProviderToUse?.CurrentUser ?? null;
    }
    async ngOnInit() {
        try {
            // Resolve default agent + cockpit app ID from in-memory caches
            // (no RunView round-trips). Both fall back to null cleanly:
            // missing agent → routes through Sage; missing app → safety
            // guard in chat-area demotes scope to 'Global'.
            await AIEngineBase.Instance.Config(false);
            const codesmith = AIEngineBase.Instance.Agents
                ?.find(a => a.Name?.trim().toLowerCase() === AIAssistantPanelComponent.CODESMITH_AGENT_NAME.toLowerCase());
            this.CodesmithAgentId = codesmith?.ID ?? null;
            if (!codesmith) {
                LogError(`AIAssistantPanel: '${AIAssistantPanelComponent.CODESMITH_AGENT_NAME}' not found in AIEngineBase cache`);
            }
            const md = this.ProviderToUse;
            const app = md.Applications?.find(a => a.Name?.trim().toLowerCase() === AIAssistantPanelComponent.COCKPIT_APP_NAME.toLowerCase());
            this.CockpitApplicationId = app?.ID ?? null;
            // Resolve MJ: Components entity ID for conversation linkage.
            const componentsEntity = md.EntityByName?.('MJ: Components');
            if (!componentsEntity) {
                LogError(`AIAssistantPanel: Entity 'MJ: Components' not found in Metadata cache — conversation linkage will be skipped.`);
            }
            this.ComponentsEntityID = componentsEntity?.ID ?? null;
            // Subscribe to the Explorer shell's app-context publisher so
            // the agent sees the same snapshot the floating overlay sees.
            this.appContextSubscription = this.navigationService.AppContextSnapshot$
                .subscribe(snapshot => {
                this.ChatAppContext = snapshot;
                this.cdr.markForCheck();
            });
            // Wire the SendErrorToAI channel — when the runtime preview
            // hits an error, push a canned "Fix this error: …" message
            // into the chat-area's pendingMessage pipe so the user
            // doesn't have to manually copy the error text.
            this.State.SendErrorToAI
                .pipe(takeUntil(this.destroy$))
                .subscribe(err => this.handleIncomingError(err));
            this.cdr.markForCheck();
        }
        catch (err) {
            LogError(`AIAssistantPanel.ngOnInit: ${err instanceof Error ? err.message : String(err)}`);
        }
    }
    ngOnDestroy() {
        this.destroy$.next();
        this.destroy$.complete();
        this.appContextSubscription?.unsubscribe();
        this.appContextSubscription = null;
    }
    /** Collapse the right pane (delegated to the parent dashboard). */
    OnCollapsePanel() {
        this.State.IsAIPanelCollapsed = true;
        this.State.StateChanged.emit();
    }
    /** Quick-action click — prefill the chat with the canned prompt. */
    OnQuickAction(action) {
        if (action.RequiresError && !this.State.CurrentError)
            return;
        let prompt = action.Prompt;
        if (action.RequiresError && this.State.CurrentError) {
            prompt += `${this.State.CurrentError.type} - ${this.State.CurrentError.message}`;
        }
        this.PendingMessage = prompt;
        this.PendingAttachments = null;
        this.cdr.markForCheck();
    }
    IsQuickActionEnabled(action) {
        return !action.RequiresError || this.State.CurrentError != null;
    }
    /** Runtime preview surfaced an error — auto-send "Fix this error: …". */
    handleIncomingError(error) {
        const details = error.technicalDetails
            ? (typeof error.technicalDetails === 'string'
                ? error.technicalDetails
                : JSON.stringify(error.technicalDetails, null, 2))
            : '';
        this.PendingMessage = `Fix this error: ${error.type} - ${error.message}${details ? '\n\nDetails:\n' + details : ''}`;
        this.PendingAttachments = null;
        this.cdr.markForCheck();
    }
    // ── chat-area event wiring ───────────────────────────────────────
    OnConversationCreated(event) {
        this.PendingMessage = event.pendingMessage ?? null;
        this.PendingAttachments = (event.pendingAttachments ?? null);
        this.ChatConversation = event.conversation;
        this.ChatConversationId = event.conversation.ID;
        this.ChatIsNewConversation = false;
        this.cdr.markForCheck();
    }
    OnPendingMessageConsumed() {
        this.PendingMessage = null;
        this.PendingAttachments = null;
        this.cdr.markForCheck();
    }
    OnOpenEntityRecord(event) {
        try {
            this.navigationService.OpenEntityRecord(event.entityName, event.compositeKey);
        }
        catch (err) {
            LogError(`AIAssistantPanel.OnOpenEntityRecord: ${err instanceof Error ? err.message : String(err)}`);
        }
    }
    OnNavigationRequest(event) {
        void this.navigationService.OpenNavItemByName(event.navItemName, event.params, event.appId);
    }
    OnTaskClicked(task) {
        try {
            const key = CompositeKey.FromID(task.ID);
            this.navigationService.OpenEntityRecord('MJ: Tasks', key);
        }
        catch (err) {
            LogError(`AIAssistantPanel.OnTaskClicked: ${err instanceof Error ? err.message : String(err)}`);
        }
    }
    OnArtifactLinkClicked(event) {
        const navItemName = event.type === 'conversation' ? 'Conversations' : 'Collections';
        const paramKey = event.type === 'conversation' ? 'conversationId' : 'collectionId';
        void this.navigationService.OpenNavItemByName(navItemName, { [paramKey]: event.id });
    }
    OnConversationRenamed(event) {
        if (this.ChatConversation && UUIDsEqual(this.ChatConversation.ID, event.conversationId)) {
            this.ChatConversation.Name = event.name;
            if (event.description !== undefined) {
                this.ChatConversation.Description = event.description;
            }
            this.cdr.markForCheck();
        }
    }
    OnThreadOpened(threadId) {
        this.ChatThreadId = threadId;
        this.cdr.markForCheck();
    }
    OnThreadClosed() {
        this.ChatThreadId = null;
        this.cdr.markForCheck();
    }
    OnPendingArtifactConsumed() {
        this.ChatPendingArtifactId = null;
        this.ChatPendingArtifactVersionNumber = null;
        this.cdr.markForCheck();
    }
    static ɵfac = function AIAssistantPanelComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AIAssistantPanelComponent)(i0.ɵɵdirectiveInject(i1.ComponentStudioStateService)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: AIAssistantPanelComponent, selectors: [["mj-ai-assistant-panel"]], standalone: false, features: [i0.ɵɵInheritDefinitionFeature], decls: 14, vars: 1, consts: [[1, "ai-assistant-panel"], [1, "panel-header"], [1, "header-title"], [1, "fa-solid", "fa-robot"], ["title", "Collapse panel", 1, "collapse-btn", 3, "click"], [1, "fa-solid", "fa-chevron-right"], [1, "quick-actions"], [1, "quick-action-btn", 3, "disabled", "title"], [1, "chat-host"], [3, "Provider", "environmentId", "currentUser", "conversationId", "conversation", "isNewConversation", "pendingMessage", "pendingAttachments", "threadId", "pendingArtifactId", "pendingArtifactVersionNumber", "overlayMode", "showExportButton", "showShareButton", "showArtifactIndicator", "appContext", "defaultAgentId", "applicationScope", "applicationId", "linkedEntityId", "linkedRecordId", "emptyStateGreeting"], [1, "chat-host__empty"], [1, "quick-action-btn", 3, "click", "disabled", "title"], [3, "conversationCreated", "pendingMessageConsumed", "openEntityRecord", "navigationRequest", "taskClicked", "artifactLinkClicked", "conversationRenamed", "threadOpened", "threadClosed", "pendingArtifactConsumed", "Provider", "environmentId", "currentUser", "conversationId", "conversation", "isNewConversation", "pendingMessage", "pendingAttachments", "threadId", "pendingArtifactId", "pendingArtifactVersionNumber", "overlayMode", "showExportButton", "showShareButton", "showArtifactIndicator", "appContext", "defaultAgentId", "applicationScope", "applicationId", "linkedEntityId", "linkedRecordId", "emptyStateGreeting"]], template: function AIAssistantPanelComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "div", 1)(2, "div", 2);
            i0.ɵɵelement(3, "i", 3);
            i0.ɵɵelementStart(4, "span");
            i0.ɵɵtext(5, "AI Assistant");
            i0.ɵɵelementEnd()();
            i0.ɵɵelementStart(6, "button", 4);
            i0.ɵɵlistener("click", function AIAssistantPanelComponent_Template_button_click_6_listener() { return ctx.OnCollapsePanel(); });
            i0.ɵɵelement(7, "i", 5);
            i0.ɵɵelementEnd()();
            i0.ɵɵelementStart(8, "div", 6);
            i0.ɵɵrepeaterCreate(9, AIAssistantPanelComponent_For_10_Template, 4, 8, "button", 7, _forTrack0);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(11, "div", 8);
            i0.ɵɵconditionalCreate(12, AIAssistantPanelComponent_Conditional_12_Template, 1, 22, "mj-conversation-chat-area", 9)(13, AIAssistantPanelComponent_Conditional_13_Template, 2, 0, "div", 10);
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            i0.ɵɵadvance(9);
            i0.ɵɵrepeater(ctx.QuickActions);
            i0.ɵɵadvance(3);
            i0.ɵɵconditional(ctx.CurrentUser ? 12 : 13);
        } }, dependencies: [i2.ConversationChatAreaComponent], styles: ["[_nghost-%COMP%] {\n  display: flex;\n  flex-direction: column;\n  height: 100%;\n}\n\n.ai-assistant-panel[_ngcontent-%COMP%] {\n  display: flex;\n  flex-direction: column;\n  height: 100%;\n  background: var(--mj-bg-surface);\n  overflow: hidden;\n}\n\n\n\n\n\n\n\n\n.panel-header[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 12px 16px;\n  border-bottom: 1px solid var(--mj-border-default);\n  background: var(--mj-bg-surface);\n  flex-shrink: 0;\n}\n\n.panel-header[_ngcontent-%COMP%]   .header-title[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  font-size: 14px;\n  font-weight: 600;\n  color: var(--mj-text-primary);\n}\n\n.panel-header[_ngcontent-%COMP%]   .header-title[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-brand-primary);\n  font-size: 16px;\n}\n\n.panel-header[_ngcontent-%COMP%]   .collapse-btn[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  width: 28px;\n  height: 28px;\n  border: none;\n  background: transparent;\n  color: var(--mj-text-secondary);\n  border-radius: 4px;\n  cursor: pointer;\n  transition: background 0.15s, color 0.15s;\n}\n\n.panel-header[_ngcontent-%COMP%]   .collapse-btn[_ngcontent-%COMP%]:hover {\n  background: var(--mj-bg-surface-sunken);\n  color: var(--mj-text-primary);\n}\n\n\n\n\n\n\n\n\n.quick-actions[_ngcontent-%COMP%] {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 6px;\n  padding: 10px 16px;\n  border-bottom: 1px solid var(--mj-border-default);\n  background: var(--mj-bg-surface-card);\n  flex-shrink: 0;\n}\n\n.quick-action-btn[_ngcontent-%COMP%] {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  padding: 6px 10px;\n  border: 1px solid var(--mj-border-default);\n  background: var(--mj-bg-surface);\n  color: var(--mj-text-primary);\n  border-radius: 4px;\n  font-size: 12px;\n  cursor: pointer;\n  transition: background 0.15s, border-color 0.15s;\n}\n\n.quick-action-btn[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-brand-primary);\n  font-size: 11px;\n}\n\n.quick-action-btn[_ngcontent-%COMP%]:hover:not(:disabled) {\n  background: var(--mj-bg-surface-hover);\n  border-color: var(--mj-border-strong);\n}\n\n.quick-action-btn[_ngcontent-%COMP%]:disabled, \n.quick-action-btn.disabled[_ngcontent-%COMP%] {\n  opacity: 0.5;\n  cursor: not-allowed;\n}\n\n\n\n\n\n\n\n\n.chat-host[_ngcontent-%COMP%] {\n  flex: 1 1 auto;\n  min-height: 0;\n  display: flex;\n  flex-direction: column;\n  overflow: hidden;\n}\n\n.chat-host[_ngcontent-%COMP%]   mj-conversation-chat-area[_ngcontent-%COMP%] {\n  flex: 1 1 auto;\n  min-height: 0;\n  display: flex;\n  flex-direction: column;\n}\n\n.chat-host__empty[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  height: 100%;\n  font-size: 13px;\n  color: var(--mj-text-muted);\n}"], changeDetection: 0 });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AIAssistantPanelComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-ai-assistant-panel', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"ai-assistant-panel\">\n  <!-- Header: title + collapse. Style + classes match the prior bespoke\n       chat so the panel chrome lines up with the rest of the cockpit. -->\n  <div class=\"panel-header\">\n    <div class=\"header-title\">\n      <i class=\"fa-solid fa-robot\"></i>\n      <span>AI Assistant</span>\n    </div>\n    <button class=\"collapse-btn\" (click)=\"OnCollapsePanel()\" title=\"Collapse panel\">\n      <i class=\"fa-solid fa-chevron-right\"></i>\n    </button>\n  </div>\n\n  <!-- Quick Actions: clicking a button stuffs the canned prompt into\n       `PendingMessage`, which the chat-area below picks up on its next\n       render cycle and sends as if the user typed it. Same mechanism the\n       SendErrorToAI handler uses. \"Fix Errors\" disables until an error\n       has actually been observed in the runtime preview. -->\n  <div class=\"quick-actions\">\n    @for (action of QuickActions; track action.Label) {\n      <button\n        class=\"quick-action-btn\"\n        [class.disabled]=\"!IsQuickActionEnabled(action)\"\n        [disabled]=\"!IsQuickActionEnabled(action)\"\n        (click)=\"OnQuickAction(action)\"\n        [title]=\"action.Label\">\n        <i class=\"fa-solid {{ action.Icon }}\"></i>\n        <span>{{ action.Label }}</span>\n      </button>\n    }\n  </div>\n\n  <!-- Embedded chat-area \u2014 same primitive the main Chat app and the Form\n       Builder cockpit use. Conversations here are scoped to the\n       Component Studio app so they don't pollute main chat; the default\n       agent is Codesmith (resolved at init from the AIEngineBase cache);\n       and the conversation-header agent picker stays enabled so the user\n       can switch on the fly. -->\n  <div class=\"chat-host\">\n    @if (CurrentUser) {\n      <mj-conversation-chat-area\n        [Provider]=\"Provider\"\n        [environmentId]=\"EnvironmentId\"\n        [currentUser]=\"CurrentUser\"\n        [conversationId]=\"ChatConversationId\"\n        [conversation]=\"ChatConversation\"\n        [isNewConversation]=\"ChatIsNewConversation\"\n        [pendingMessage]=\"PendingMessage\"\n        [pendingAttachments]=\"PendingAttachments\"\n        [threadId]=\"ChatThreadId\"\n        [pendingArtifactId]=\"ChatPendingArtifactId\"\n        [pendingArtifactVersionNumber]=\"ChatPendingArtifactVersionNumber\"\n        [overlayMode]=\"true\"\n        [showExportButton]=\"false\"\n        [showShareButton]=\"false\"\n        [showArtifactIndicator]=\"false\"\n        [appContext]=\"$any(ChatAppContext)\"\n        [defaultAgentId]=\"CodesmithAgentId\"\n        [applicationScope]=\"'Application'\"\n        [applicationId]=\"CockpitApplicationId\"\n        [linkedEntityId]=\"ComponentsEntityID\"\n        [linkedRecordId]=\"LinkedComponentID\"\n        [emptyStateGreeting]=\"'How can I help with this component?'\"\n        (conversationCreated)=\"OnConversationCreated($event)\"\n        (pendingMessageConsumed)=\"OnPendingMessageConsumed()\"\n        (openEntityRecord)=\"OnOpenEntityRecord($event)\"\n        (navigationRequest)=\"OnNavigationRequest($event)\"\n        (taskClicked)=\"OnTaskClicked($event)\"\n        (artifactLinkClicked)=\"OnArtifactLinkClicked($event)\"\n        (conversationRenamed)=\"OnConversationRenamed($event)\"\n        (threadOpened)=\"OnThreadOpened($event)\"\n        (threadClosed)=\"OnThreadClosed()\"\n        (pendingArtifactConsumed)=\"OnPendingArtifactConsumed()\">\n      </mj-conversation-chat-area>\n    } @else {\n      <div class=\"chat-host__empty\">Loading\u2026</div>\n    }\n  </div>\n</div>\n", styles: [":host {\n  display: flex;\n  flex-direction: column;\n  height: 100%;\n}\n\n.ai-assistant-panel {\n  display: flex;\n  flex-direction: column;\n  height: 100%;\n  background: var(--mj-bg-surface);\n  overflow: hidden;\n}\n\n/* ============================================================ */\n/* HEADER                                                       */\n/* ============================================================ */\n\n.panel-header {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 12px 16px;\n  border-bottom: 1px solid var(--mj-border-default);\n  background: var(--mj-bg-surface);\n  flex-shrink: 0;\n}\n\n.panel-header .header-title {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  font-size: 14px;\n  font-weight: 600;\n  color: var(--mj-text-primary);\n}\n\n.panel-header .header-title i {\n  color: var(--mj-brand-primary);\n  font-size: 16px;\n}\n\n.panel-header .collapse-btn {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  width: 28px;\n  height: 28px;\n  border: none;\n  background: transparent;\n  color: var(--mj-text-secondary);\n  border-radius: 4px;\n  cursor: pointer;\n  transition: background 0.15s, color 0.15s;\n}\n\n.panel-header .collapse-btn:hover {\n  background: var(--mj-bg-surface-sunken);\n  color: var(--mj-text-primary);\n}\n\n/* ============================================================ */\n/* QUICK ACTIONS                                                */\n/* ============================================================ */\n\n.quick-actions {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 6px;\n  padding: 10px 16px;\n  border-bottom: 1px solid var(--mj-border-default);\n  background: var(--mj-bg-surface-card);\n  flex-shrink: 0;\n}\n\n.quick-action-btn {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  padding: 6px 10px;\n  border: 1px solid var(--mj-border-default);\n  background: var(--mj-bg-surface);\n  color: var(--mj-text-primary);\n  border-radius: 4px;\n  font-size: 12px;\n  cursor: pointer;\n  transition: background 0.15s, border-color 0.15s;\n}\n\n.quick-action-btn i {\n  color: var(--mj-brand-primary);\n  font-size: 11px;\n}\n\n.quick-action-btn:hover:not(:disabled) {\n  background: var(--mj-bg-surface-hover);\n  border-color: var(--mj-border-strong);\n}\n\n.quick-action-btn:disabled,\n.quick-action-btn.disabled {\n  opacity: 0.5;\n  cursor: not-allowed;\n}\n\n/* ============================================================ */\n/* CHAT HOST                                                    */\n/* ============================================================ */\n\n.chat-host {\n  flex: 1 1 auto;\n  min-height: 0;\n  display: flex;\n  flex-direction: column;\n  overflow: hidden;\n}\n\n.chat-host mj-conversation-chat-area {\n  flex: 1 1 auto;\n  min-height: 0;\n  display: flex;\n  flex-direction: column;\n}\n\n.chat-host__empty {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  height: 100%;\n  font-size: 13px;\n  color: var(--mj-text-muted);\n}\n"] }]
    }], () => [{ type: i1.ComponentStudioStateService }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(AIAssistantPanelComponent, { className: "AIAssistantPanelComponent", filePath: "src/ComponentStudio/components/ai-assistant/ai-assistant-panel.component.ts", lineNumber: 71 }); })();
//# sourceMappingURL=ai-assistant-panel.component.js.map