"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TabFactory = exports.McpServerTabButtonId = exports.ExportTabBarButtonId = void 0;
const mynah_ui_1 = require("@aws/mynah-ui");
const disclaimer_1 = require("../texts/disclaimer");
const history_1 = require("../features/history");
const pairProgramming_1 = require("../texts/pairProgramming");
const modelSelection_1 = require("../texts/modelSelection");
exports.ExportTabBarButtonId = 'export';
exports.McpServerTabButtonId = 'mcp_init';
class TabFactory {
    defaultTabData;
    quickActionCommands;
    bannerMessage;
    history = false;
    export = false;
    agenticMode = false;
    mcp = false;
    modelSelectionEnabled = false;
    initialTabId;
    static generateUniqueId() {
        // from https://github.com/aws/mynah-ui/blob/a3799f47ca4b7c02850264e328539a40709a6858/src/helper/guid.ts#L6
        const firstPart = (Math.random() * 46656) | 0;
        const secondPart = (Math.random() * 46656) | 0;
        return `000${firstPart.toString(36)}`.slice(-3) + `000${secondPart.toString(36)}`.slice(-3);
    }
    constructor(defaultTabData, quickActionCommands, bannerMessage) {
        this.defaultTabData = defaultTabData;
        this.quickActionCommands = quickActionCommands;
        this.bannerMessage = bannerMessage;
        this.initialTabId = TabFactory.generateUniqueId();
    }
    createTab(disclaimerCardActive) {
        const tabData = {
            ...this.getDefaultTabData(),
            ...(disclaimerCardActive ? { promptInputStickyCard: disclaimer_1.disclaimerCard } : {}),
            promptInputOptions: this.agenticMode
                ? [
                    pairProgramming_1.pairProgrammingPromptInput,
                    ...(this.modelSelectionEnabled ? [modelSelection_1.modelSelectionForRegion['us-east-1']] : []),
                ]
                : [],
            cancelButtonWhenLoading: this.agenticMode, // supported for agentic chat only
        };
        return tabData;
    }
    getChatItems(needWelcomeMessages, pairProgrammingCardActive, chatMessages) {
        return [
            ...(this.bannerMessage ? [this.getBannerMessage()] : []),
            ...(needWelcomeMessages
                ? [
                    ...(this.agenticMode && pairProgrammingCardActive ? [pairProgramming_1.programmerModeCard] : []),
                    {
                        type: mynah_ui_1.ChatItemType.ANSWER,
                        body: `Hi, I'm Amazon Q. I can answer your software development questions. 
                        Ask me to explain, debug, or optimize your code. 
                        You can enter \`/\` to see a list of quick actions.`,
                    },
                    ...(!this.agenticMode
                        ? [
                            {
                                type: mynah_ui_1.ChatItemType.ANSWER,
                                followUp: this.getWelcomeBlock(),
                            },
                        ]
                        : []),
                ]
                : chatMessages
                    ? chatMessages
                    : []),
        ];
    }
    updateQuickActionCommands(quickActionCommands) {
        this.quickActionCommands = [...(this.quickActionCommands ?? []), ...quickActionCommands];
    }
    enableHistory() {
        this.history = true;
    }
    enableExport() {
        this.export = true;
    }
    enableAgenticMode() {
        this.agenticMode = true;
    }
    enableMcp() {
        this.mcp = true;
    }
    enableModelSelection() {
        this.modelSelectionEnabled = true;
    }
    getDefaultTabData() {
        const tabData = {
            ...this.defaultTabData,
            ...(this.quickActionCommands ? { quickActionCommands: this.quickActionCommands } : {}),
        };
        tabData.tabBarButtons = this.getTabBarButtons();
        return tabData;
    }
    setInfoMessages(messages) {
        if (messages?.length) {
            // For now this messages array is only populated with banner data hence we use the first item
            this.bannerMessage = messages[0];
        }
    }
    getBannerMessage() {
        if (this.bannerMessage) {
            return {
                type: mynah_ui_1.ChatItemType.ANSWER,
                status: 'info',
                ...this.bannerMessage,
            };
        }
        return undefined;
    }
    getTabBarButtons() {
        const tabBarButtons = [...(this.defaultTabData.tabBarButtons ?? [])];
        if (this.mcp) {
            tabBarButtons.push({
                id: exports.McpServerTabButtonId,
                icon: mynah_ui_1.MynahIcons.TOOLS,
                description: 'Configure MCP servers',
            });
        }
        if (this.history) {
            tabBarButtons.push({
                id: history_1.ChatHistory.TabBarButtonId,
                icon: mynah_ui_1.MynahIcons.HISTORY,
                description: 'View chat history',
            });
        }
        if (this.export) {
            tabBarButtons.push({
                id: exports.ExportTabBarButtonId,
                icon: mynah_ui_1.MynahIcons.EXTERNAL,
                description: 'Export chat',
            });
        }
        return tabBarButtons.length ? tabBarButtons : undefined;
    }
    // Legacy welcome messages block
    getWelcomeBlock() {
        return {
            text: 'Try Examples:',
            options: [
                {
                    pillText: 'Explain selected code',
                    prompt: 'Explain selected code',
                    type: 'init-prompt',
                },
                {
                    pillText: 'How can Amazon Q help me?',
                    type: 'help',
                },
            ],
        };
    }
}
exports.TabFactory = TabFactory;
//# sourceMappingURL=tabFactory.js.map