"use strict";
const common_vendor = require("../../common/vendor.js");
require("../../common/libraries/request.js");
const common_store_useWeAppAuthStore = require("../../common/store/useWeAppAuthStore.js");
require("../../common/store/useWorkStore.js");
const pages_ai_method = require("./method.js");
const pages_ai_model = require("./model.js");
const common_libraries_userUserLogin = require("../../common/libraries/userUserLogin.js");
require("../../gen/Apis.js");
require("../../common/libraries/setTabBar.js");
require("../../common/libraries/apiLoading.js");
require("../../common/libraries/upload.js");
if (!Array) {
  const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  const _easycom_hs_empty2 = common_vendor.resolveComponent("hs-empty");
  const _easycom_hs_button2 = common_vendor.resolveComponent("hs-button");
  (_easycom_uni_icons2 + _easycom_hs_empty2 + _easycom_hs_button2)();
}
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_hs_empty = () => "../../components/hs-empty/hs-empty.js";
const _easycom_hs_button = () => "../../components/hs-button/hs-button.js";
if (!Math) {
  (MyHeaderPrologue + _easycom_uni_icons + _easycom_hs_empty + _easycom_hs_button)();
}
const MyHeaderPrologue = () => "./components/HeaderPrologue.js";
const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "chat",
  setup(__props) {
    common_vendor.dayjs.extend(common_vendor.relativeTime);
    common_vendor.dayjs.locale("zh-cn");
    const auth = common_store_useWeAppAuthStore.useWeAppAuthStore();
    const userLoginStatus = common_vendor.ref(false);
    const inputMessage = common_vendor.ref("");
    const isInputFocused = common_vendor.ref(false);
    const messages = common_vendor.ref([]);
    const loading = common_vendor.ref(false);
    const loadingText = common_vendor.ref("正在输入中...");
    let socketTask = null;
    let isConnected = common_vendor.ref(false);
    const currentPage = common_vendor.ref(1);
    const pageSize = common_vendor.ref(10);
    const hasMore = common_vendor.ref(true);
    const isLoadingHistory = common_vendor.ref(false);
    const conversationId = common_vendor.ref("");
    const currentOffset = common_vendor.ref(0);
    const quickQuestionsData = common_vendor.ref({});
    const lastMessageContent = common_vendor.ref("");
    const goToPageLogin = () => {
      common_vendor.index.navigateTo({
        url: "/pages/login"
      });
    };
    const scrollToBottom = () => {
      common_vendor.nextTick$1(() => {
        common_vendor.index.pageScrollTo({
          scrollTop: 999999,
          duration: 300
        });
      });
    };
    const getHistoryMessages = async (page = 1) => {
      var _a, _b, _c;
      const userPhone = (_b = (_a = auth.data) == null ? void 0 : _a.user) == null ? void 0 : _b.phone;
      if (!userPhone) {
        console.log("用户未登录，无法获取历史记录");
        return;
      }
      if (isLoadingHistory.value) {
        return;
      }
      try {
        isLoadingHistory.value = true;
        const offset = (page - 1) * pageSize.value;
        currentOffset.value = offset;
        const response = await ((_c = pages_ai_method.method) == null ? void 0 : _c.customRequest("public/customer/init", {
          platform: "property",
          platform_user_id: userPhone,
          //userPhone
          limit: pageSize.value,
          offset
        }));
        if (response.statusCode === 200) {
          const result = response.data;
          let historyMessages = [];
          if (result.conversation && result.conversation.id) {
            conversationId.value = result.conversation.id;
            console.log("获取到会话ID:", conversationId.value);
          } else if (result.conversation_id) {
            conversationId.value = result.conversation_id;
            console.log("获取到会话ID:", conversationId.value);
          } else if (result.conversations && result.conversations.id) {
            conversationId.value = result.conversations.id;
            console.log("获取到会话ID:", conversationId.value);
          }
          if (result.messages && Array.isArray(result.messages)) {
            historyMessages = result.messages.map((item) => {
              const message = {
                role: item.sender_type === "customer" ? "user" : "ai",
                content: item.message || item.content || "",
                created_at: item.created_at || item.timestamp || new Date().toISOString()
              };
              if (item.message_type) {
                message.message_type = item.message_type;
              }
              let imageUrlData = null;
              if (item.image_url && Array.isArray(item.image_url)) {
                imageUrlData = item.image_url;
              } else if (item.images && Array.isArray(item.images)) {
                imageUrlData = item.images;
              } else if (item.metadata && item.metadata.image_url && Array.isArray(item.metadata.image_url)) {
                imageUrlData = item.metadata.image_url;
              }
              if (imageUrlData) {
                message.image_url = imageUrlData;
                message.images = imageUrlData;
              }
              if (item.metadata) {
                message.metadata = item.metadata;
              }
              return message;
            });
            console.log("从messages字段获取到历史记录:", historyMessages.length);
          } else if (result.data && Array.isArray(result.data)) {
            historyMessages = result.data.map((item) => {
              const message = {
                role: item.sender_type === "customer" ? "user" : "ai",
                content: item.message || item.content || "",
                created_at: item.created_at || item.timestamp || new Date().toISOString()
              };
              if (item.message_type) {
                message.message_type = item.message_type;
              }
              let imageUrlData = null;
              if (item.image_url && Array.isArray(item.image_url)) {
                imageUrlData = item.image_url;
              } else if (item.images && Array.isArray(item.images)) {
                imageUrlData = item.images;
              } else if (item.metadata && item.metadata.image_url && Array.isArray(item.metadata.image_url)) {
                imageUrlData = item.metadata.image_url;
              }
              if (imageUrlData) {
                message.image_url = imageUrlData;
                message.images = imageUrlData;
              }
              if (item.metadata) {
                message.metadata = item.metadata;
              }
              return message;
            });
            console.log("从data字段获取到历史记录:", historyMessages.length);
          } else if (result.list && Array.isArray(result.list)) {
            historyMessages = result.list.map((item) => {
              const message = {
                role: item.sender_type === "customer" ? "user" : "ai",
                content: item.message || item.content || "",
                created_at: item.created_at || item.timestamp || new Date().toISOString()
              };
              if (item.message_type) {
                message.message_type = item.message_type;
              }
              let imageUrlData = null;
              if (item.image_url && Array.isArray(item.image_url)) {
                imageUrlData = item.image_url;
              } else if (item.images && Array.isArray(item.images)) {
                imageUrlData = item.images;
              } else if (item.metadata && item.metadata.image_url && Array.isArray(item.metadata.image_url)) {
                imageUrlData = item.metadata.image_url;
              }
              if (imageUrlData) {
                message.image_url = imageUrlData;
                message.images = imageUrlData;
              }
              if (item.metadata) {
                message.metadata = item.metadata;
              }
              return message;
            });
            console.log("从list字段获取到历史记录:", historyMessages.length);
          }
          if (page === 1) {
            if (historyMessages.length > 0) {
              messages.value = historyMessages;
              console.log("第一页历史记录已加载，总共", historyMessages.length, "条消息");
            } else {
              console.log("没有历史记录");
              messages.value = [];
            }
          } else {
            if (historyMessages.length > 0) {
              setTimeout(() => {
                messages.value.unshift(...historyMessages);
                console.log(
                  "加载更多历史记录，新增",
                  historyMessages.length,
                  "条消息，总共",
                  messages.value.length,
                  "条"
                );
              }, 300);
            }
          }
          const totalItems = result.total || result.count || result.total_count || 0;
          hasMore.value = totalItems > messages.value.length;
          currentPage.value = page;
          if (page === 1) {
            setTimeout(() => {
              scrollToBottom();
            }, 100);
            console.log("[Customer] 历史记录加载完成，开始建立WebSocket连接");
            initWebSocket();
          }
        } else {
          console.error("获取历史记录失败，状态码:", response.statusCode);
        }
      } catch (error) {
        console.error("获取历史记录异常:", error);
      } finally {
        isLoadingHistory.value = false;
      }
    };
    common_vendor.onPullDownRefresh(async () => {
      if (isLoadingHistory.value || !hasMore.value) {
        console.log("正在加载或没有更多数据");
        common_vendor.index.stopPullDownRefresh();
        return;
      }
      console.log("触发下拉分页，加载更多历史记录");
      const nextPage = currentPage.value + 1;
      try {
        await getHistoryMessages(nextPage);
        await new Promise((resolve) => setTimeout(resolve, 500));
      } catch (error) {
        console.error("加载历史记录失败:", error);
      } finally {
        common_vendor.index.stopPullDownRefresh();
      }
    });
    const initWebSocket = () => {
      var _a;
      if (socketTask) {
        return;
      }
      try {
        const wsUrl = `${(_a = pages_ai_model.useModel) == null ? void 0 : _a.WS_BASE_URL}/ws/socket.io/?EIO=4&transport=websocket`;
        socketTask = common_vendor.index.connectSocket({
          url: wsUrl,
          header: {
            "content-type": "application/json"
          }
        });
        common_vendor.index.onSocketOpen((res) => {
          isConnected.value = true;
          const connectPacket = '40/customer,{"jwt":""}';
          common_vendor.index.sendSocketMessage({
            data: connectPacket,
            success: () => {
              if (conversationId.value) {
                setTimeout(() => {
                  const joinMessage = `42/customer,["join_conversation",{"conversation_id":"${conversationId.value}"}]`;
                  console.log("[Customer] 加入会话房间:", joinMessage);
                  common_vendor.index.sendSocketMessage({
                    data: joinMessage,
                    success: () => {
                      console.log("[Customer] 成功加入会话房间");
                    },
                    fail: (error) => {
                      console.error("[Customer] 加入会话房间失败:", error);
                    }
                  });
                }, 200);
              }
            },
            fail: (error) => {
              console.error("[Customer] Socket.IO连接包发送失败:", error);
            }
          });
        });
        common_vendor.index.onSocketError((error) => {
          console.error("[Customer] WebSocket error:", error);
          isConnected.value = false;
          socketTask = null;
        });
        common_vendor.index.onSocketClose((res) => {
          console.log("[Customer] WebSocket disconnected", res);
          isConnected.value = false;
          socketTask = null;
        });
        common_vendor.index.onSocketMessage((res) => {
          const data = res.data;
          if (typeof data === "string") {
            if (data.startsWith("42/customer,")) {
              const payload = data.substring("42/customer,".length);
              try {
                const parsedData = JSON.parse(payload);
                console.log("解析Socket.IO事件:", parsedData);
                handleSocketEvent(parsedData);
              } catch (e) {
                console.error("解析Socket.IO数据失败:", e, "原始数据:", payload);
              }
            } else if (data.startsWith("40/customer")) {
              console.log("Socket.IO连接确认");
            } else if (data.startsWith("2")) {
              common_vendor.index.sendSocketMessage({
                data: "3"
              });
            } else if (data.startsWith("0")) {
              console.log("Socket.IO握手成功");
            } else {
              try {
                const jsonData = JSON.parse(data);
                console.log("解析JSON消息:", jsonData);
                handleJsonMessage(jsonData);
              } catch (e) {
                console.log("非JSON格式的字符串消息:", data);
              }
            }
          } else if (typeof data === "object") {
            console.log("收到对象类型消息:", data);
            handleObjectMessage(data);
          } else {
            console.log("收到其他类型消息，类型:", typeof data);
          }
        });
      } catch (error) {
        console.error("初始化Socket.IO异常:", error);
        isConnected.value = false;
        socketTask = null;
      }
    };
    const handleSocketEvent = (parsedData) => {
      if (Array.isArray(parsedData) && parsedData.length >= 2) {
        const eventType = parsedData[0];
        const eventData = parsedData[1];
        console.log("[Customer] Socket.IO事件类型:", eventType, "事件数据:", eventData);
        if (eventType === "new_message") {
          processMessage(eventData);
        } else if (eventType === "join_conversation_response") {
          console.log("[Customer] Joined room:", eventData);
        } else if (eventType === "message") {
          processMessage(eventData);
        } else if (eventType === "typing") {
          processTypingIndicator(eventData);
        } else {
          console.log("[Customer] 未处理的Socket.IO事件类型:", eventType);
        }
      }
    };
    const handleJsonMessage = (jsonData) => {
      console.log("[Customer] 处理JSON消息:", jsonData);
      if (jsonData.type === "message" || jsonData.event === "new_message") {
        processMessage(jsonData.data || jsonData);
      } else if (jsonData.type === "typing" || jsonData.event === "typing") {
        processTypingIndicator(jsonData.data || jsonData);
      } else if (jsonData.message || jsonData.content) {
        processMessage(jsonData);
      } else {
        console.log("[Customer] 未识别的JSON消息结构:", jsonData);
      }
    };
    const handleObjectMessage = (objData) => {
      console.log("[Customer] 处理对象消息:", objData);
      if (objData.message || objData.content || objData.text) {
        processMessage(objData);
      } else if (objData.is_typing !== void 0) {
        processTypingIndicator(objData);
      } else {
        console.log("[Customer] 未识别的对象消息结构:", objData);
      }
    };
    const processTypingIndicator = (typingData) => {
      if (typingData.is_typing && typingData.user_type === "staff") {
        loading.value = true;
        loadingText.value = "客服正在输入...";
      } else {
        loading.value = false;
      }
    };
    const processMessage = (messageData) => {
      if (messageData.sender_type === "customer" || messageData.role === "user") {
        return;
      }
      let messageContent = "";
      if (typeof messageData === "string") {
        messageContent = messageData;
      } else {
        messageContent = messageData.message || messageData.content || messageData.text || messageData.body || "收到回复";
      }
      if (typeof messageContent === "string") {
        messageContent = messageContent.replace(/↵/g, "\n").replace(/\\n/g, "\n");
      }
      console.log("[Customer] 收到新消息内容:", messageContent);
      if (messageContent === lastMessageContent.value) {
        console.log("[Customer] 消息与HTTP返回的消息相同，跳过显示");
        lastMessageContent.value = "";
        return;
      }
      loading.value = false;
      const newMessage = {
        role: "ai",
        content: messageContent,
        created_at: messageData.created_at || messageData.timestamp || messageData.time || new Date().toISOString()
      };
      if (messageData.suggested_questions && Array.isArray(messageData.suggested_questions) && messageData.suggested_questions.length > 0) {
        newMessage.quickQuestions = messageData.suggested_questions;
      } else if (messageData.quickQuestions && Array.isArray(messageData.quickQuestions) && messageData.quickQuestions.length > 0) {
        newMessage.quickQuestions = messageData.quickQuestions;
      }
      if (messageData.need_confirmation !== void 0) {
        newMessage.needConfirmation = messageData.need_confirmation;
      }
      if (messageData.confirmation_type !== void 0) {
        newMessage.confirmationType = messageData.confirmation_type;
      }
      messages.value.push(newMessage);
      scrollToBottom();
    };
    const handleQuickQuestion = (question) => {
      inputMessage.value = question;
      handleSendMessage();
    };
    const handleQuickFast = (name) => {
      handleQuickAction({ message: name });
    };
    const handleQuickAction = (action) => {
      inputMessage.value = action.message;
      handleSendMessage();
    };
    const handleConfirmation = (message, confirmation) => {
      if (message.selectedConfirmation !== void 0) {
        return;
      }
      message.selectedConfirmation = confirmation;
      setTimeout(() => {
        inputMessage.value = confirmation;
        handleSendMessage();
      }, 300);
    };
    const handleSendMessage = async () => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
      const message = inputMessage.value.trim();
      const hasImages = ((_c = (_b = (_a = pages_ai_model.useModel) == null ? void 0 : _a.selectedImages) == null ? void 0 : _b.value) == null ? void 0 : _c.length) > 0;
      if (!message && !hasImages || loading.value)
        return;
      const userPhone = (_e = (_d = auth.data) == null ? void 0 : _d.user) == null ? void 0 : _e.phone;
      const projectId = (_g = (_f = auth.data) == null ? void 0 : _f.selected_house) == null ? void 0 : _g.asset_projects_id;
      const projectName = (_i = (_h = auth.data) == null ? void 0 : _h.selected_house) == null ? void 0 : _i.full_name;
      if (!userPhone || !projectId) {
        common_vendor.index.showToast({
          title: "请先登录并绑定房屋",
          icon: "none"
        });
        return;
      }
      if (!isConnected.value) {
        initWebSocket();
        await new Promise((resolve) => setTimeout(resolve, 1e3));
      }
      const uploadedImages = ((_k = (_j = pages_ai_model.useModel) == null ? void 0 : _j.selectedImages) == null ? void 0 : _k.value) || [];
      let messageType = "text";
      if (hasImages && message) {
        messageType = "mixed";
      } else if (hasImages && !message) {
        messageType = "image";
      }
      const userMessage = {
        role: "user",
        content: message || "",
        // 纯图片时传空字符串
        created_at: new Date().toISOString(),
        message_type: messageType,
        image_url: uploadedImages.length > 0 ? uploadedImages : void 0,
        images: uploadedImages.length > 0 ? uploadedImages : void 0
      };
      messages.value.push(userMessage);
      inputMessage.value = "";
      pages_ai_model.useModel.selectedImages.value = [];
      scrollToBottom();
      if (message && message.includes("查询")) {
        loadingText.value = "正在查询中请稍后...";
      } else {
        loadingText.value = "正在输入中...";
      }
      loading.value = true;
      try {
        const response = await ((_l = pages_ai_method.method) == null ? void 0 : _l.customRequest("public/chat", {
          platform: "property",
          message: message || "",
          // 纯图片时传空字符串
          tenant_project_id: projectId,
          message_type: messageType,
          tenant_project_name: projectName || "",
          conversation_id: conversationId.value,
          image_url: uploadedImages.length > 0 ? uploadedImages : void 0
        }));
        if (response.statusCode === 200) {
          const result = response.data;
          console.log("[Customer] HTTP接口响应数据:", result);
          let httpReplyMessage = null;
          let suggestedQuestions = [];
          let needConfirmation = false;
          let confirmationType = null;
          if (result.reply && typeof result.reply === "string") {
            httpReplyMessage = result.reply;
            suggestedQuestions = result.suggested_questions || [];
            needConfirmation = result.need_confirmation || false;
            confirmationType = result.confirmation_type || null;
          } else if (result.reply && result.reply.message) {
            httpReplyMessage = result.reply.message;
            suggestedQuestions = result.reply.suggested_questions || result.suggested_questions || [];
            needConfirmation = result.reply.need_confirmation || result.need_confirmation || false;
            confirmationType = result.reply.confirmation_type || result.confirmation_type || null;
          } else if (result.reply && result.reply.content) {
            httpReplyMessage = result.reply.content;
            suggestedQuestions = result.reply.suggested_questions || result.suggested_questions || [];
            needConfirmation = result.reply.need_confirmation || result.need_confirmation || false;
            confirmationType = result.reply.confirmation_type || result.confirmation_type || null;
          } else if (result.message) {
            httpReplyMessage = result.message;
            suggestedQuestions = result.suggested_questions || [];
            needConfirmation = result.need_confirmation || false;
            confirmationType = result.confirmation_type || null;
          } else if (result.content) {
            httpReplyMessage = result.content;
            suggestedQuestions = result.suggested_questions || [];
            needConfirmation = result.need_confirmation || false;
            confirmationType = result.confirmation_type || null;
          } else if (result.answer) {
            httpReplyMessage = result.answer;
            suggestedQuestions = result.suggested_questions || [];
            needConfirmation = result.need_confirmation || false;
            confirmationType = result.confirmation_type || null;
          } else if (result.response) {
            httpReplyMessage = result.response;
            suggestedQuestions = result.suggested_questions || [];
            needConfirmation = result.need_confirmation || false;
            confirmationType = result.confirmation_type || null;
          } else if (typeof result === "string") {
            httpReplyMessage = result;
          }
          if (httpReplyMessage) {
            console.log("[Customer] HTTP接口返回回答消息:", httpReplyMessage);
            console.log("[Customer] 建议问题:", suggestedQuestions);
            console.log("[Customer] 需要确认:", needConfirmation, "确认类型:", confirmationType);
            let formattedMessage = httpReplyMessage;
            if (typeof formattedMessage === "string") {
              formattedMessage = formattedMessage.replace(/↵/g, "\n").replace(/\\n/g, "\n");
            }
            lastMessageContent.value = formattedMessage;
            loading.value = false;
            messages.value.push({
              role: "ai",
              content: formattedMessage,
              created_at: new Date().toISOString(),
              quickQuestions: suggestedQuestions.length > 0 ? suggestedQuestions : void 0,
              needConfirmation,
              confirmationType
            });
            scrollToBottom();
          } else {
            console.log("[Customer] 消息发送成功，等待WebSocket回复");
          }
        } else {
          throw new Error("请求失败");
        }
      } catch (error) {
        console.error("发送消息失败:", error);
        common_vendor.index.showToast({
          title: "发送失败，请稍后重试",
          icon: "none"
        });
        messages.value.push({
          role: "ai",
          content: "抱歉，网络连接出现问题，请稍后再试。"
        });
        loading.value = false;
        scrollToBottom();
      }
    };
    common_vendor.onUnmounted(() => {
      if (socketTask || isConnected.value) {
        common_vendor.index.closeSocket();
        socketTask = null;
        isConnected.value = false;
        console.log("页面卸载，WebSocket连接已关闭");
      }
    });
    common_vendor.onLoad(async (op) => {
      var _a, _b, _c;
      await ((_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.appContext.config.globalProperties.$onLaunched);
      if ((_b = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _b.getLoginStatus()) {
        userLoginStatus.value = true;
        quickQuestionsData.value = await ((_c = pages_ai_method.method) == null ? void 0 : _c.getQuickQuestions());
        getHistoryMessages(1);
        if (op == null ? void 0 : op.message) {
          handleQuickAction(op);
        }
      } else {
        userLoginStatus.value = false;
        messages.value = [];
      }
    });
    return (_ctx, _cache) => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
      return common_vendor.e({
        a: userLoginStatus.value
      }, userLoginStatus.value ? common_vendor.e({
        b: common_vendor.o(handleQuickFast),
        c: common_vendor.f(messages.value, (message, index, i0) => {
          var _a2, _b2;
          return common_vendor.e({
            a: message.role === "ai"
          }, message.role === "ai" ? {} : {}, {
            b: message.image_url && message.image_url.length > 0
          }, message.image_url && message.image_url.length > 0 ? {
            c: common_vendor.f(message.image_url, (image, imgIndex, i1) => {
              return {
                a: image,
                b: common_vendor.o(($event) => {
                  var _a3;
                  return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.previewImage(image, message.image_url);
                }, imgIndex),
                c: imgIndex
              };
            }),
            d: message.image_url.length === 1 ? "widthFix" : "aspectFill",
            e: message.image_url.length === 1 ? 1 : ""
          } : message.images && message.images.length > 0 ? {
            g: common_vendor.f(message.images, (image, imgIndex, i1) => {
              return {
                a: image,
                b: common_vendor.o(($event) => {
                  var _a3;
                  return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.previewImage(image, message.images);
                }, imgIndex),
                c: imgIndex
              };
            }),
            h: message.images.length === 1 ? "widthFix" : "aspectFill",
            i: message.images.length === 1 ? 1 : ""
          } : message.metadata && message.metadata.image_url && message.metadata.image_url.length > 0 ? {
            k: common_vendor.f(message.metadata.image_url, (image, imgIndex, i1) => {
              return {
                a: image,
                b: common_vendor.o(($event) => {
                  var _a3;
                  return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.previewImage(image, message.metadata.image_url);
                }, imgIndex),
                c: imgIndex
              };
            }),
            l: message.metadata.image_url.length === 1 ? "widthFix" : "aspectFill",
            m: message.metadata.image_url.length === 1 ? 1 : ""
          } : {}, {
            f: message.images && message.images.length > 0,
            j: message.metadata && message.metadata.image_url && message.metadata.image_url.length > 0,
            n: message.content && message.content.trim()
          }, message.content && message.content.trim() ? {
            o: common_vendor.f((_a2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a2.formatMessageContent(message.content), (line, lineIndex, i1) => {
              return {
                a: common_vendor.t(line),
                b: "text-" + lineIndex
              };
            })
          } : {}, {
            p: message.quickQuestions && message.quickQuestions.length > 0
          }, message.quickQuestions && message.quickQuestions.length > 0 ? {
            q: common_vendor.f(message.quickQuestions, (question, qIndex, i1) => {
              return {
                a: common_vendor.t(question),
                b: qIndex,
                c: common_vendor.o(($event) => handleQuickQuestion(question), qIndex)
              };
            })
          } : {}, {
            r: message.needConfirmation
          }, message.needConfirmation ? {
            s: message.selectedConfirmation === "是" ? 1 : "",
            t: message.selectedConfirmation !== void 0 ? 1 : "",
            v: common_vendor.o(($event) => handleConfirmation(message, "是"), index),
            w: message.selectedConfirmation === "否" ? 1 : "",
            x: message.selectedConfirmation !== void 0 ? 1 : "",
            y: common_vendor.o(($event) => handleConfirmation(message, "否"), index)
          } : {}, {
            z: message.created_at && !message.quickQuestions
          }, message.created_at && !message.quickQuestions ? common_vendor.e({
            A: message.role === "ai"
          }, message.role === "ai" ? {
            B: common_vendor.o(($event) => {
              var _a3;
              return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.copyMessage(message.content);
            }, index)
          } : {}, {
            C: common_vendor.t((_b2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _b2.formatTime(message.created_at)),
            D: message.role === "user"
          }, message.role === "user" ? {
            E: common_vendor.o(($event) => {
              var _a3;
              return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.copyMessage(message.content);
            }, index)
          } : {}) : {}, {
            F: index,
            G: `msg-${index}`,
            H: common_vendor.n(message.role === "user" ? "user-message" : "ai-message")
          });
        }),
        d: loading.value
      }, loading.value ? {
        e: common_vendor.t(loadingText.value)
      } : {}, {
        f: ((_c = (_b = (_a = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _a.selectedImages) == null ? void 0 : _b.value) == null ? void 0 : _c.length) > 0
      }, ((_f = (_e = (_d = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _d.selectedImages) == null ? void 0 : _e.value) == null ? void 0 : _f.length) > 0 ? common_vendor.e({
        g: common_vendor.f((_h = (_g = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _g.selectedImages) == null ? void 0 : _h.value, (image, index, i0) => {
          return {
            a: image,
            b: "25c36616-1-" + i0,
            c: common_vendor.o(($event) => {
              var _a2;
              return (_a2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a2.removeImage(index);
            }, index),
            d: index
          };
        }),
        h: common_vendor.p({
          type: "closeempty",
          size: "14",
          color: "#fff"
        }),
        i: ((_k = (_j = (_i = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _i.selectedImages) == null ? void 0 : _j.value) == null ? void 0 : _k.length) < 9
      }, ((_n = (_m = (_l = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _l.selectedImages) == null ? void 0 : _m.value) == null ? void 0 : _n.length) < 9 ? {
        j: common_vendor.p({
          type: "plus",
          size: "30",
          color: "#999"
        }),
        k: common_vendor.o(($event) => {
          var _a2;
          return (_a2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a2.chooseImage();
        })
      } : {}) : {}, {
        l: common_vendor.o(($event) => isInputFocused.value = true),
        m: common_vendor.o(($event) => isInputFocused.value = false),
        n: common_vendor.o(handleSendMessage),
        o: inputMessage.value,
        p: common_vendor.o(($event) => inputMessage.value = $event.detail.value),
        q: !inputMessage.value.trim() && !isInputFocused.value && ((_q = (_p = (_o = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _o.selectedImages) == null ? void 0 : _p.value) == null ? void 0 : _q.length) === 0
      }, !inputMessage.value.trim() && !isInputFocused.value && ((_t = (_s = (_r = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _r.selectedImages) == null ? void 0 : _s.value) == null ? void 0 : _t.length) === 0 ? {
        r: common_vendor.p({
          type: "camera",
          size: "24",
          color: "#666"
        }),
        s: common_vendor.o(($event) => {
          var _a2;
          return (_a2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a2.chooseImage();
        })
      } : {}, {
        t: (inputMessage.value.trim() || isInputFocused.value || ((_w = (_v = (_u = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _u.selectedImages) == null ? void 0 : _v.value) == null ? void 0 : _w.length) > 0) && !loading.value
      }, (inputMessage.value.trim() || isInputFocused.value || ((_z = (_y = (_x = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _x.selectedImages) == null ? void 0 : _y.value) == null ? void 0 : _z.length) > 0) && !loading.value ? {
        v: common_vendor.p({
          type: "paperplane-filled",
          size: "20",
          color: "#fff"
        }),
        w: common_vendor.o(handleSendMessage)
      } : {}, {
        x: loading.value
      }, loading.value ? {
        y: common_vendor.p({
          type: "spinner-cycle",
          size: "20",
          color: "#ccc"
        })
      } : {}) : {
        z: common_vendor.p({
          height: "20vh",
          baseStyle: {
            paddingTop: "35%"
          },
          text: "登录体验更多功能"
        }),
        A: common_vendor.o(goToPageLogin),
        B: common_vendor.p({
          label: "去登录",
          size: "md",
          type: "primary"
        })
      });
    };
  }
});
_sfc_defineComponent.__runtimeHooks = 1;
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_defineComponent, [["__file", "/Users/zsq/Sources/github/2025property-pay/pay-customer/src/pages/ai/chat.vue"]]);
wx.createPage(MiniProgramPage);
