"use strict";
const TUIKit_tuiCustomerServicePlugin_adapterVue = require("../adapter-vue.js");
const common_vendor = require("../../../common/vendor.js");
const { ref, watchEffect, onBeforeUnmount, onMounted } = TUIKit_tuiCustomerServicePlugin_adapterVue.vue;
const _sfc_main = {
  props: {
    payload: {
      type: Object,
      default: () => ({})
    }
  },
  setup(props) {
    const content = ref("");
    const displayedContent = ref("");
    const isFinished = ref(false);
    let intervalId = null;
    let currentIndex = 0;
    const updateDisplayedContent = () => {
      if (intervalId) {
        window.clearInterval(intervalId);
      }
      intervalId = window.setInterval(() => {
        if (currentIndex < content.value.length) {
          displayedContent.value += content.value[currentIndex];
          currentIndex++;
        } else {
          window.clearInterval(intervalId);
          intervalId = null;
        }
      }, 50);
    };
    onMounted(() => {
      var _a, _b;
      content.value = ((_b = (_a = props == null ? void 0 : props.payload) == null ? void 0 : _a.chunks) == null ? void 0 : _b.join("")) ?? "";
      displayedContent.value = content.value;
      currentIndex = content.value.length;
    });
    watchEffect(() => {
      var _a, _b;
      const newContent = ((_b = (_a = props == null ? void 0 : props.payload) == null ? void 0 : _a.chunks) == null ? void 0 : _b.join("")) ?? "";
      if (newContent.length > currentIndex) {
        content.value = newContent;
        updateDisplayedContent();
      }
    });
    watchEffect(() => {
      var _a;
      isFinished.value = ((_a = props == null ? void 0 : props.payload) == null ? void 0 : _a.isFinished) === 1;
    });
    onBeforeUnmount(() => {
      if (intervalId) {
        window.clearInterval(intervalId);
      }
    });
    return {
      content,
      props,
      isFinished,
      displayedContent
    };
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: common_vendor.t($setup.displayedContent),
    b: !$setup.isFinished
  }, !$setup.isFinished ? {} : {});
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-35feeb52"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/TUIKit/tui-customer-service-plugin/components/message-stream.js.map
