"use strict";
const common_vendor = require("../../../../../common/vendor.js");
require("../../../../adapter-vue.js");
require("../../emoji-config/index.js");
const TUIKit_utils_env = require("../../../../utils/env.js");
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "message-text",
  props: {
    content: { default: () => ({}) },
    messageItem: { default: () => ({}) },
    enableURLHighlight: { type: Boolean, default: false }
  },
  setup(__props) {
    const props = __props;
    const processedContent = common_vendor.ref([]);
    common_vendor.watch(
      () => props.messageItem,
      (newValue, oldValue) => {
        var _a, _b, _c, _d, _e, _f;
        if ((newValue == null ? void 0 : newValue.ID) === (oldValue == null ? void 0 : oldValue.ID)) {
          return;
        }
        if (props.enableURLHighlight) {
          common_vendor.ss.reportFeature(208);
        }
        if (props.messageItem.getMessageContent) {
          processedContent.value = (_a = props.messageItem.getMessageContent()) == null ? void 0 : _a.text;
        } else {
          processedContent.value = (_c = (_b = common_vendor.Jt.getMessageModel(props.messageItem.ID)) == null ? void 0 : _b.getMessageContent()) == null ? void 0 : _c.text;
        }
        processedContent.value = processedContent.value || ((_d = props.content) == null ? void 0 : _d.text);
        if (!((_e = processedContent.value) == null ? void 0 : _e.length)) {
          processedContent.value = [];
          return;
        }
        processedContent.value = (_f = processedContent.value.map((item) => {
          if (item.name === "img" && (item == null ? void 0 : item.type) === "custom") {
            {
              common_vendor.index.__f__("warn", "at TUIKit/components/TUIChat/message-list/message-elements/message-text.vue:87", "CUSTOM_BASIC_EMOJI_URL is required for custom emoji.");
              return item;
            }
          }
          if (props.enableURLHighlight && item.name === "text" && item.text) {
            if (!common_vendor.A$1) {
              common_vendor.index.__f__("warn", "at TUIKit/components/TUIChat/message-list/message-elements/message-text.vue:103", "parseTextAndValidateUrls not found. Please update @tencentcloud/universal-api to 2.3.7 or higher.");
              return item;
            }
            const segments = common_vendor.A$1(item.text);
            if (segments.length) {
              return segments.map((segment) => ({
                name: segment.type,
                text: segment.text,
                url: segment.url
              }));
            }
          }
          return item;
        })) == null ? void 0 : _f.flat();
      },
      {
        deep: true,
        immediate: true
      }
    );
    function navigateToUrl(url) {
      if (url) {
        if (TUIKit_utils_env.isUniFrameWork) {
          common_vendor.i.navigateTo({
            url: `/pages/views/webview?url=${url}`
            // Assuming you have a webview page to handle external URLs
          });
        } else {
          common_vendor.i.open(url, "_blank");
        }
      }
    }
    return (_ctx, _cache) => {
      return {
        a: common_vendor.f(common_vendor.unref(processedContent), (item, index, i0) => {
          return common_vendor.e({
            a: item.name === "text"
          }, item.name === "text" ? {
            b: common_vendor.t(item.text)
          } : item.name === "url" ? {
            d: common_vendor.t(item.text),
            e: common_vendor.o$1(($event) => navigateToUrl(item.url), index)
          } : {
            f: item.src,
            g: item.emojiKey
          }, {
            c: item.name === "url",
            h: index
          });
        }),
        b: common_vendor.n(common_vendor.unref(TUIKit_utils_env.isPC) && "text-select")
      };
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-e1772b65"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-list/message-elements/message-text.js.map
