import { defineComponent, ref, computed, openBlock, createBlock, unref, withCtx, createElementVNode, normalizeClass, toDisplayString, createElementBlock, withModifiers, createCommentVNode, Fragment, renderList, withDirectives, isRef, vModelText, createTextVNode } from "vue";
import TUIChatEngine, { TUIStore, StoreName, TUITranslateService, TUIChatService } from "@tencentcloud/chat-uikit-engine";
import "../../../../adapter-vue.mjs";
import ToolbarItemContainer from "../toolbar-item-container/index.vue.mjs";
import evaluateIconLight from "../../../../assets/icon/evalute-light.svg.mjs";
import evaluateIconDark from "../../../../assets/icon/evalute-dark.svg.mjs";
import Link from "../../../../utils/documentLink.mjs";
import Icon from "../../../common/Icon.vue.mjs";
import starIcon from "../../../../assets/icon/star.png.mjs";
import starLightIcon from "../../../../assets/icon/star-light.png.mjs";
import { CHAT_MSG_CUSTOM_TYPE } from "../../../../constant.mjs";
import { isUniFrameWork, isPC, isH5 } from "../../../../utils/env.mjs";
import { isEnabledMessageReadReceiptGlobal } from "../../utils/utils.mjs";
import OfflinePushInfoManager from "../../offlinePushInfoManager/index.mjs";
import ChatConfig from "../../config.mjs";
const _hoisted_1 = ["onClick"];
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    starTotal: {
      type: Number,
      default: 5
    }
  },
  emits: ["onDialogPopupShowOrHide"],
  setup(__props, { emit: __emit }) {
    const evaluateIcon = ChatConfig.getTheme() === "dark" ? evaluateIconDark : evaluateIconLight;
    const props = __props;
    const emits = __emit;
    const container = ref();
    const starList = ref(props.starTotal);
    const currentStarIndex = ref(-1);
    const comment = ref("");
    const currentConversation = ref();
    TUIStore.watch(StoreName.CONV, {
      currentConversation: (conversation) => {
        currentConversation.value = conversation;
      }
    });
    const isEvaluateValid = computed(() => comment.value.length || currentStarIndex.value >= 0);
    const onDialogShow = () => {
      emits("onDialogPopupShowOrHide", true);
    };
    const onDialogClose = () => {
      resetEvaluate();
      emits("onDialogPopupShowOrHide", false);
    };
    const openLink = () => {
      var _a, _b;
      if (isPC || isH5) {
        window.open((_b = (_a = Link) == null ? void 0 : _a.customMessage) == null ? void 0 : _b.url);
      }
    };
    const closeDialog = () => {
      var _a;
      (_a = container == null ? void 0 : container.value) == null ? void 0 : _a.toggleDialogDisplay(false);
    };
    const resetEvaluate = () => {
      currentStarIndex.value = -1;
      comment.value = "";
    };
    const selectStar = (starIndex) => {
      if (currentStarIndex.value === starIndex) {
        currentStarIndex.value = currentStarIndex.value - 1;
      } else {
        currentStarIndex.value = starIndex;
      }
    };
    const submitEvaluate = () => {
      var _a, _b, _c, _d, _e, _f;
      if (currentStarIndex.value < 0 && !comment.value.length) {
        return;
      }
      const payload = {
        data: JSON.stringify({
          businessID: CHAT_MSG_CUSTOM_TYPE.EVALUATE,
          version: 1,
          score: currentStarIndex.value + 1,
          comment: comment.value
        }),
        description: "对本次的服务评价",
        extension: "对本次的服务评价"
      };
      const options = {
        to: ((_b = (_a = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _a.groupProfile) == null ? void 0 : _b.groupID) || ((_d = (_c = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _c.userProfile) == null ? void 0 : _d.userID),
        conversationType: (_e = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _e.type,
        payload,
        needReadReceipt: isEnabledMessageReadReceiptGlobal()
      };
      const offlinePushInfoCreateParams = {
        conversation: currentConversation.value,
        payload: options.payload,
        messageType: TUIChatEngine.TYPES.MSG_CUSTOM
      };
      const sendMessageOptions = {
        offlinePushInfo: OfflinePushInfoManager.create(offlinePushInfoCreateParams)
      };
      TUIChatService.sendCustomMessage(options, sendMessageOptions);
      (_f = container == null ? void 0 : container.value) == null ? void 0 : _f.toggleDialogDisplay(false);
    };
    return (_ctx, _cache) => {
      return openBlock(), createBlock(ToolbarItemContainer, {
        ref_key: "container",
        ref: container,
        iconFile: unref(evaluateIcon),
        title: "评价",
        needBottomPopup: true,
        iconWidth: unref(isUniFrameWork) ? "26px" : "20px",
        iconHeight: unref(isUniFrameWork) ? "26px" : "20px",
        onOnDialogShow: onDialogShow,
        onOnDialogClose: onDialogClose
      }, {
        default: withCtx(() => [
          createElementVNode("div", {
            class: normalizeClass(["evaluate", !unref(isPC) && "evaluate-h5"])
          }, [
            createElementVNode("div", {
              class: normalizeClass(["evaluate-header", !unref(isPC) && "evaluate-h5-header"])
            }, [
              createElementVNode("div", {
                class: normalizeClass([
                  "evaluate-header-content",
                  !unref(isPC) && "evaluate-h5-header-content"
                ])
              }, toDisplayString(unref(TUITranslateService).t("Evaluate.请对本次服务进行评价")), 3),
              !unref(isPC) ? (openBlock(), createElementBlock("div", {
                key: 0,
                class: normalizeClass([
                  "evaluate-header-close",
                  !unref(isPC) && "evaluate-h5-header-close"
                ]),
                onClick: withModifiers(closeDialog, ["stop"])
              }, toDisplayString(unref(TUITranslateService).t("关闭")), 3)) : createCommentVNode("", true)
            ], 2),
            createElementVNode("div", {
              class: normalizeClass(["evaluate-content", !unref(isPC) && "evaluate-h5-content"])
            }, [
              createElementVNode("ul", {
                class: normalizeClass([
                  "evaluate-content-list",
                  !unref(isPC) && "evaluate-h5-content-list"
                ])
              }, [
                (openBlock(true), createElementBlock(Fragment, null, renderList(unref(starList), (item, index) => {
                  return openBlock(), createElementBlock("li", {
                    key: index,
                    class: normalizeClass([
                      "evaluate-content-list-item",
                      !unref(isPC) && "evaluate-h5-content-list-item"
                    ]),
                    onClick: withModifiers(($event) => selectStar(index), ["stop"])
                  }, [
                    index <= unref(currentStarIndex) ? (openBlock(), createBlock(Icon, {
                      key: 0,
                      file: unref(starLightIcon),
                      width: unref(isPC) ? "20px" : "30px",
                      height: unref(isPC) ? "20px" : "30px"
                    }, null, 8, ["file", "width", "height"])) : (openBlock(), createBlock(Icon, {
                      key: 1,
                      file: unref(starIcon),
                      width: unref(isPC) ? "20px" : "30px",
                      height: unref(isPC) ? "20px" : "30px"
                    }, null, 8, ["file", "width", "height"]))
                  ], 10, _hoisted_1);
                }), 128))
              ], 2),
              withDirectives(createElementVNode("textarea", {
                "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(comment) ? comment.value = $event : null),
                class: normalizeClass([
                  "evaluate-content-text",
                  !unref(isPC) && "evaluate-h5-content-text"
                ])
              }, null, 2), [
                [vModelText, unref(comment)]
              ]),
              createElementVNode("div", {
                class: normalizeClass([
                  "evaluate-content-button",
                  !unref(isPC) && "evaluate-h5-content-button"
                ])
              }, [
                createElementVNode("button", {
                  class: normalizeClass(["btn", unref(isEvaluateValid) ? "btn-valid" : "btn-invalid"]),
                  onClick: submitEvaluate
                }, toDisplayString(unref(TUITranslateService).t("Evaluate.提交评价")), 3)
              ], 2)
            ], 2),
            createElementVNode("div", {
              class: normalizeClass(["evaluate-adv", !unref(isPC) && "evaluate-h5-adv"])
            }, [
              createTextVNode(toDisplayString(unref(TUITranslateService).t("Evaluate.服务评价工具")) + " " + toDisplayString("(" + unref(TUITranslateService).t("Evaluate.使用")) + " ", 1),
              createElementVNode("a", {
                onClick: _cache[1] || (_cache[1] = ($event) => openLink(unref(Link).customMessage))
              }, toDisplayString(unref(TUITranslateService).t(`Evaluate.${unref(Link).customMessage.label}`)), 1),
              createTextVNode(" " + toDisplayString(unref(TUITranslateService).t("Evaluate.搭建") + ")"), 1)
            ], 2)
          ], 2)
        ]),
        _: 1
      }, 8, ["iconFile", "iconWidth", "iconHeight"]);
    };
  }
});
export {
  _sfc_main as default
};
