"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TabFactory = exports.ShowLogsTabBarButtonId = 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");
const utils_1 = require("../utils");
exports.ExportTabBarButtonId = 'export';
exports.McpServerTabButtonId = 'mcp_init';
exports.ShowLogsTabBarButtonId = 'show_logs';
class TabFactory {
    defaultTabData;
    quickActionCommands;
    bannerMessage;
    history = false;
    export = false;
    agenticMode = false;
    mcp = false;
    modelSelectionEnabled = false;
    reroute = false;
    codeReviewInChat = false;
    showLogs = 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.modelSelection] : [])]
                : [],
            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: `<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 200px 0 20px 0;">

<div style="font-size: 24px; margin-bottom: 12px;"><strong>Amazon Q</strong></div>
<div style="background: rgba(128, 128, 128, 0.15); border: 1px solid rgba(128, 128, 128, 0.25); border-radius: 8px; padding: 8px; margin: 4px 0; text-align: center;">
<div style="font-size: 14px; margin-bottom: 4px;"><strong>Did you know?</strong></div>
<div>${this.getRandomTip()}</div>
</div>

Select code & ask me to explain, debug or optimize it, or type \`/\` for quick actions

</div>`,
                        canBeVoted: false,
                    },
                ]
                : chatMessages
                    ? chatMessages.map(msg => (0, utils_1.chatMessageToChatItem)(msg, this.agenticMode))
                    : []),
        ];
    }
    updateQuickActionCommands(quickActionCommands) {
        this.quickActionCommands = [...(this.quickActionCommands ?? []), ...quickActionCommands];
    }
    enableHistory() {
        this.history = true;
    }
    enableExport() {
        this.export = true;
    }
    enableShowLogs() {
        this.showLogs = true;
    }
    enableAgenticMode() {
        this.agenticMode = true;
    }
    enableMcp() {
        this.mcp = true;
    }
    enableModelSelection() {
        this.modelSelectionEnabled = true;
    }
    enableReroute() {
        this.reroute = true;
    }
    enableCodeReviewInChat() {
        this.codeReviewInChat = true;
    }
    isRerouteEnabled() {
        return this.reroute;
    }
    isCodeReviewInChatEnabled() {
        return this.codeReviewInChat;
    }
    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;
    }
    getRandomTip() {
        const hints = [
            'You can now see logs with 1-Click!',
            'MCP is available in Amazon Q!',
            'Pinned context is always included in future chat messages',
            'Create and add Saved Prompts using the @ context menu',
            'Compact your conversation with /compact',
            'Ask Q to review your code and see results in the code issues panel!',
        ];
        const randomIndex = Math.floor(Math.random() * hints.length);
        return hints[randomIndex];
    }
    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',
            });
        }
        if (this.showLogs) {
            tabBarButtons.push({
                id: exports.ShowLogsTabBarButtonId,
                icon: mynah_ui_1.MynahIcons.FILE,
                description: 'Show logs',
            });
        }
        return tabBarButtons.length ? tabBarButtons : undefined;
    }
}
exports.TabFactory = TabFactory;
//# sourceMappingURL=tabFactory.js.map