import { h } from "@stencil/core";
export class AiChat {
    el;
    /**
     * 聊天消息列表
     */
    messages = [];
    /**
     * 是否显示时间戳
     */
    showTimestamp = true;
    /**
     * 是否显示用户头像
     */
    showUserAvatar = true;
    /**
     * 是否显示AI头像
     */
    showAiAvatar = true;
    /**
     * 用户头像URL
     */
    userAvatar = '';
    /**
     * AI头像URL
     */
    aiAvatar = '';
    /**
     * 自定义渲染器映射
     */
    customRenderers = {};
    /**
     * 是否显示输入框
     */
    showInput = true;
    /**
     * 输入框占位符
     */
    inputPlaceholder = '输入消息...';
    /**
     * 是否禁用输入
     */
    inputDisabled = false;
    /**
     * 最大输入长度
     */
    maxInputLength = 1000;
    /**
     * 是否支持多行输入
     */
    multilineInput = true;
    /**
     * 消息点击事件
     */
    messageClick;
    /**
     * 消息长按事件
     */
    messageLongPress;
    /**
     * 消息发送事件
     */
    messageSend;
    scrollToBottom = true;
    messagesChanged() {
        this.scrollToBottom = true;
    }
    componentDidUpdate() {
        if (this.scrollToBottom) {
            this.scrollToBottom = false;
            this.scrollToBottomOfChat();
        }
    }
    scrollToBottomOfChat() {
        const chatContainer = this.el.shadowRoot?.querySelector('.chat-container');
        if (chatContainer) {
            chatContainer.scrollTop = chatContainer.scrollHeight;
        }
    }
    handleMessageClick = (message) => {
        this.messageClick.emit(message);
    };
    handleMessageLongPress = (message) => {
        this.messageLongPress.emit(message);
    };
    handleMessageSend = (event) => {
        // 阻止事件冒泡，避免重复触发
        event.stopPropagation();
        this.messageSend.emit(event.detail);
    };
    renderMessage(message) {
        const isUser = message.isUser;
        const messageClass = `message ${isUser ? 'user-message' : 'ai-message'}`;
        return (h("div", { class: messageClass, onClick: () => this.handleMessageClick(message), onTouchStart: () => {
                let timer;
                timer = setTimeout(() => {
                    this.handleMessageLongPress(message);
                }, 500);
                const handleTouchEnd = () => {
                    clearTimeout(timer);
                    document.removeEventListener('touchend', handleTouchEnd);
                };
                document.addEventListener('touchend', handleTouchEnd);
            } }, !isUser && this.showAiAvatar && (h("div", { class: "avatar ai-avatar" }, this.aiAvatar ? (h("img", { src: this.aiAvatar, alt: "AI" })) : (h("div", { class: "default-avatar" }, "AI")))), h("div", { class: "message-content" }, h("div", { class: "message-bubble" }, this.renderMessageContent(message)), this.showTimestamp && message.timestamp && (h("div", { class: "message-time" }, new Date(message.timestamp).toLocaleTimeString()))), isUser && this.showUserAvatar && (h("div", { class: "avatar user-avatar" }, this.userAvatar ? (h("img", { src: this.userAvatar, alt: "User" })) : (h("div", { class: "default-avatar" }, "U"))))));
    }
    renderMessageContent(message) {
        const { type, content, customRenderer } = message;
        // 检查是否有自定义渲染器
        if (customRenderer && this.customRenderers[customRenderer]) {
            const CustomComponent = this.customRenderers[customRenderer];
            return h(CustomComponent, { content: content });
        }
        // 根据类型渲染不同内容
        switch (type) {
            case 'text':
                return h("text-renderer", { content: content });
            case 'markdown':
                return h("markdown-renderer", { content: content });
            case 'echarts':
                return h("echarts-renderer", { content: content });
            default:
                return h("text-renderer", { content: content });
        }
    }
    render() {
        return (h("div", { key: 'bae58a6e2656977b66b940b935cebd0f39837203', class: "ai-chat" }, h("div", { key: '88fb1e09d5ae43096a05f3ec4fff9ee00f7b23b7', class: "chat-container" }, this.messages.map(message => (h("div", { key: message.id }, this.renderMessage(message))))), this.showInput && (h("message-input", { key: 'ae8fc39efcd7529c49ea20805b67e8a687c6ec93', placeholder: this.inputPlaceholder, disabled: this.inputDisabled, maxLength: this.maxInputLength, multiline: this.multilineInput, onMessageSend: this.handleMessageSend }))));
    }
    static get is() { return "ai-chat"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["./ai-chat.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["ai-chat.css"]
        };
    }
    static get properties() {
        return {
            "messages": {
                "type": "unknown",
                "attribute": "messages",
                "mutable": false,
                "complexType": {
                    "original": "ChatMessage[]",
                    "resolved": "ChatMessage[]",
                    "references": {
                        "ChatMessage": {
                            "location": "local",
                            "path": "/Users/huangxingyuan/code/Fe/curson/stenci-ai-chat/src/components/ai-chat/ai-chat.tsx",
                            "id": "src/components/ai-chat/ai-chat.tsx::ChatMessage"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u804A\u5929\u6D88\u606F\u5217\u8868"
                },
                "getter": false,
                "setter": false,
                "defaultValue": "[]"
            },
            "showTimestamp": {
                "type": "boolean",
                "attribute": "show-timestamp",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u662F\u5426\u663E\u793A\u65F6\u95F4\u6233"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "showUserAvatar": {
                "type": "boolean",
                "attribute": "show-user-avatar",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u662F\u5426\u663E\u793A\u7528\u6237\u5934\u50CF"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "showAiAvatar": {
                "type": "boolean",
                "attribute": "show-ai-avatar",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u662F\u5426\u663E\u793AAI\u5934\u50CF"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "userAvatar": {
                "type": "string",
                "attribute": "user-avatar",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u7528\u6237\u5934\u50CFURL"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            },
            "aiAvatar": {
                "type": "string",
                "attribute": "ai-avatar",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "AI\u5934\u50CFURL"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            },
            "customRenderers": {
                "type": "unknown",
                "attribute": "custom-renderers",
                "mutable": false,
                "complexType": {
                    "original": "{ [key: string]: string }",
                    "resolved": "{ [key: string]: string; }",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u81EA\u5B9A\u4E49\u6E32\u67D3\u5668\u6620\u5C04"
                },
                "getter": false,
                "setter": false,
                "defaultValue": "{}"
            },
            "showInput": {
                "type": "boolean",
                "attribute": "show-input",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u662F\u5426\u663E\u793A\u8F93\u5165\u6846"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "inputPlaceholder": {
                "type": "string",
                "attribute": "input-placeholder",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u8F93\u5165\u6846\u5360\u4F4D\u7B26"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'\u8F93\u5165\u6D88\u606F...'"
            },
            "inputDisabled": {
                "type": "boolean",
                "attribute": "input-disabled",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u662F\u5426\u7981\u7528\u8F93\u5165"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "maxInputLength": {
                "type": "number",
                "attribute": "max-input-length",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u6700\u5927\u8F93\u5165\u957F\u5EA6"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "1000"
            },
            "multilineInput": {
                "type": "boolean",
                "attribute": "multiline-input",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u662F\u5426\u652F\u6301\u591A\u884C\u8F93\u5165"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            }
        };
    }
    static get states() {
        return {
            "scrollToBottom": {}
        };
    }
    static get events() {
        return [{
                "method": "messageClick",
                "name": "messageClick",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "\u6D88\u606F\u70B9\u51FB\u4E8B\u4EF6"
                },
                "complexType": {
                    "original": "ChatMessage",
                    "resolved": "ChatMessage",
                    "references": {
                        "ChatMessage": {
                            "location": "local",
                            "path": "/Users/huangxingyuan/code/Fe/curson/stenci-ai-chat/src/components/ai-chat/ai-chat.tsx",
                            "id": "src/components/ai-chat/ai-chat.tsx::ChatMessage"
                        }
                    }
                }
            }, {
                "method": "messageLongPress",
                "name": "messageLongPress",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "\u6D88\u606F\u957F\u6309\u4E8B\u4EF6"
                },
                "complexType": {
                    "original": "ChatMessage",
                    "resolved": "ChatMessage",
                    "references": {
                        "ChatMessage": {
                            "location": "local",
                            "path": "/Users/huangxingyuan/code/Fe/curson/stenci-ai-chat/src/components/ai-chat/ai-chat.tsx",
                            "id": "src/components/ai-chat/ai-chat.tsx::ChatMessage"
                        }
                    }
                }
            }, {
                "method": "messageSend",
                "name": "messageSend",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "\u6D88\u606F\u53D1\u9001\u4E8B\u4EF6"
                },
                "complexType": {
                    "original": "{ content: string; timestamp: number }",
                    "resolved": "{ content: string; timestamp: number; }",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "messages",
                "methodName": "messagesChanged"
            }];
    }
}
//# sourceMappingURL=ai-chat.js.map
