var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m")
        throw new TypeError("Private method is not writable");
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _GxIdeScChatContainer_chatContainerRef, _GxIdeScChatContainer_chatWelcomeRef, _GxIdeScChatContainer_chChatRef, _GxIdeScChatContainer_chatCallbacks, _GxIdeScChatContainer_copyConversationCallbackHandler, _GxIdeScChatContainer_deleteConversationCallbackHandler, _GxIdeScChatContainer_suggestedPrompRequestedCallbackHandler;
import { Host, h } from "@stencil/core";
import { renderItem as mercuryChatRenderItem } from "@genexus/mercury";
import { sendContainerLayout as mercurySendContainerLayout } from "@genexus/mercury";
import { codeFixerRecord } from "./models";
const CSS_BUNDLES = [
    "resets/box-sizing",
    "utils/elevation",
    "components/chat",
    "components/markdown-viewer"
];
import { chatCallbacksWithChatRef, chatTranslations } from "./callbacks";
export class GxIdeScChatContainer {
    constructor() {
        _GxIdeScChatContainer_chatContainerRef.set(this, void 0);
        _GxIdeScChatContainer_chatWelcomeRef.set(this, void 0);
        _GxIdeScChatContainer_chChatRef.set(this, void 0);
        _GxIdeScChatContainer_chatCallbacks.set(this, void 0);
        _GxIdeScChatContainer_copyConversationCallbackHandler.set(this, () => {
            __classPrivateFieldGet(this, _GxIdeScChatContainer_chatContainerRef, "f").showCopyConversationMessage();
        });
        _GxIdeScChatContainer_deleteConversationCallbackHandler.set(this, () => { });
        _GxIdeScChatContainer_suggestedPrompRequestedCallbackHandler.set(this, async (prompt) => {
            let assistantFinalResponse;
            if (prompt.toLowerCase().includes("transaction")) {
                assistantFinalResponse =
                    'To create a transaction in GeneXus, start by opening your KB (Knowledge Base) and selecting "Transaction" from the "New Object" options. Give it a name and define its attributes, starting with a primary key followed by the related data fields. GeneXus will automatically infer the data structure and relationships based on how you define the attributes and their nesting. Once saved, it generates the necessary database tables and forms for inserting, updating, and deleting records. You can then run the application to test the transaction directly in your browser.';
            }
            else if (prompt.toLowerCase().includes("entity")) {
                assistantFinalResponse =
                    'In GeneXus, creating an entity usually means defining a Transaction object that represents a real-world concept like "Customer" or "Product." To do this, create a new Transaction, name it after the entity, and define its attributes—starting with a unique identifier (like CustomerId) and then adding other fields (like CustomerName, CustomerEmail). GeneXus treats this Transaction as an entity and uses it to generate the corresponding table and interface automatically.';
            }
            else {
                assistantFinalResponse =
                    "Sorry, I didn’t catch that—mind rephrasing it? 😅";
            }
            const userPrompt = {
                id: "1",
                role: "user",
                content: prompt
            };
            __classPrivateFieldGet(this, _GxIdeScChatContainer_chChatRef, "f").addNewMessage(userPrompt);
            setTimeout(() => {
                __classPrivateFieldGet(this, _GxIdeScChatContainer_chChatRef, "f").addNewMessage({
                    id: `${new Date().getTime()}`,
                    role: "assistant",
                    content: "Analyzing",
                    status: "waiting"
                });
                setTimeout(() => {
                    __classPrivateFieldGet(this, _GxIdeScChatContainer_chChatRef, "f").updateLastMessage({
                        role: "assistant",
                        content: "Processing with Chat with LLMs",
                        status: "waiting"
                    }, "replace");
                    setTimeout(() => {
                        __classPrivateFieldGet(this, _GxIdeScChatContainer_chChatRef, "f").updateLastMessage({
                            role: "assistant",
                            content: "Getting information",
                            status: "waiting"
                        }, "replace");
                        __classPrivateFieldGet(this, _GxIdeScChatContainer_chChatRef, "f").updateLastMessage({
                            role: "assistant",
                            content: assistantFinalResponse,
                            status: "complete"
                        }, "replace");
                    }, 1500);
                }, 1500);
            }, 100);
        });
        this.mode = "messages-sample";
        this.generatingResponse = false;
        this.loadingState = "all-records-loaded";
        this.showAdditionalContent = false;
        this.conversationCopied = false;
        this.assistantStatus = "Getting Data";
        this.chatItems = [];
    }
    /**
     * It will exit the wellcome screen and remove it from the dom.
     */
    async exitWelcome() {
        // hand exitWelcome to gx-ide-chat-welcome
        __classPrivateFieldGet(this, _GxIdeScChatContainer_chatWelcomeRef, "f").exitWelcome();
    }
    componentDidLoad() {
        setTimeout(() => {
            this.assistantStatus = "Creating Data Base..";
        }, 1000);
    }
    componentDidRender() {
        if (!__classPrivateFieldGet(this, _GxIdeScChatContainer_chatCallbacks, "f") && __classPrivateFieldGet(this, _GxIdeScChatContainer_chChatRef, "f")) {
            __classPrivateFieldSet(this, _GxIdeScChatContainer_chatCallbacks, chatCallbacksWithChatRef(__classPrivateFieldGet(this, _GxIdeScChatContainer_chChatRef, "f")), "f");
        }
    }
    async componentWillLoad() {
        if (this.mode === "messages-sample") {
            this.chatItems = codeFixerRecord;
        }
        else if (this.mode === "welcome") {
            this.chatItems = [];
        }
        else if (this.mode === "empty") {
            this.chatItems = [
                {
                    id: "1",
                    role: "assistant",
                    status: "complete",
                    content: "Hello! I am your assistant.",
                    metadata: "14:56"
                }
            ];
        }
    }
    render() {
        return (h(Host, null, h("ch-theme", { model: CSS_BUNDLES }), h("gx-ide-chat-container", { chatTitle: "GeneXus Assistant", copyConversationCallback: __classPrivateFieldGet(this, _GxIdeScChatContainer_copyConversationCallbackHandler, "f"), deleteConversationCallback: __classPrivateFieldGet(this, _GxIdeScChatContainer_deleteConversationCallbackHandler, "f"), ref: el => (__classPrivateFieldSet(this, _GxIdeScChatContainer_chatContainerRef, el, "f")), class: "elevation-1" }, h("ch-chat", { callbacks: __classPrivateFieldGet(this, _GxIdeScChatContainer_chatCallbacks, "f"), class: "chat", waitingResponse: this.generatingResponse, loadingState: this.loadingState, renderItem: mercuryChatRenderItem, items: this.chatItems, showAdditionalContent: false, sendContainerLayout: mercurySendContainerLayout, translations: chatTranslations, ref: (el) => (__classPrivateFieldSet(this, _GxIdeScChatContainer_chChatRef, el, "f")), markdownTheme: "components/markdown-viewer" }, h("gx-ide-chat-welcome", { ref: el => (__classPrivateFieldSet(this, _GxIdeScChatContainer_chatWelcomeRef, el, "f")), slot: "empty-chat", suggestedPrompRequestedCallback: __classPrivateFieldGet(this, _GxIdeScChatContainer_suggestedPrompRequestedCallbackHandler, "f") }), h("div", { slot: "additional-content" }, "Custom content that is rendered when the chat renders content")))));
    }
    static get is() { return "gx-ide-sc-chat-container"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["chat-showcase.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["chat-showcase.css"]
        };
    }
    static get properties() {
        return {
            "mode": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "\"welcome\" | \"messages-sample\" | \"empty\"",
                    "resolved": "\"empty\" | \"messages-sample\" | \"welcome\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If true, the chat items length will be 0, since this is a requirement for dipslaying the ch-chat\n\"empty-chat\" slot that welcome screen uses to display."
                },
                "attribute": "mode",
                "reflect": false,
                "defaultValue": "\"messages-sample\""
            }
        };
    }
    static get states() {
        return {
            "generatingResponse": {},
            "loadingState": {},
            "showAdditionalContent": {},
            "conversationCopied": {},
            "assistantStatus": {},
            "chatItems": {}
        };
    }
    static get methods() {
        return {
            "exitWelcome": {
                "complexType": {
                    "signature": "() => Promise<void>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "It will exit the wellcome screen and remove it from the dom.",
                    "tags": []
                }
            }
        };
    }
}
_GxIdeScChatContainer_chatContainerRef = new WeakMap(), _GxIdeScChatContainer_chatWelcomeRef = new WeakMap(), _GxIdeScChatContainer_chChatRef = new WeakMap(), _GxIdeScChatContainer_chatCallbacks = new WeakMap(), _GxIdeScChatContainer_copyConversationCallbackHandler = new WeakMap(), _GxIdeScChatContainer_deleteConversationCallbackHandler = new WeakMap(), _GxIdeScChatContainer_suggestedPrompRequestedCallbackHandler = new WeakMap();
//# sourceMappingURL=chat.showcase.js.map
