"use strict";
const TUIKit_tuiCustomerServicePlugin_adapterVue = require("../../adapter-vue.js");
const TUIKit_tuiCustomerServicePlugin_constant = require("../../constant.js");
const common_vendor = require("../../../../common/vendor.js");
const { computed, ref, watchEffect } = TUIKit_tuiCustomerServicePlugin_adapterVue.vue;
const _sfc_main = {
  props: {
    ratingTemplate: {
      type: Object,
      default: () => ({})
    }
  },
  emits: ["sendMessage"],
  setup(props, { emit }) {
    const hasReply = ref(false);
    const sessionId = ref("");
    const selectValue = ref(-1);
    const hoverValue = ref(-1);
    const hasExpire = ref(false);
    const desc = computed(() => {
      var _a;
      return (_a = props.ratingTemplate) == null ? void 0 : _a.menu.map((item) => item.content);
    });
    const numberList = computed(() => {
      var _a;
      return (_a = props.ratingTemplate) == null ? void 0 : _a.menu.map((item, index) => index);
    });
    watchEffect(() => {
      sessionId.value = props.ratingTemplate.sessionId || "";
      if (props.ratingTemplate.selected != void 0) {
        for (let i = 0; i < props.ratingTemplate.menu.length; i++) {
          if (props.ratingTemplate.menu[i].id == props.ratingTemplate.selected.id) {
            hasReply.value = true;
            selectValue.value = i;
            break;
          }
        }
      }
      const timestamp = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
      if (timestamp > props.ratingTemplate.expireTime) {
        hasExpire.value = true;
      }
    });
    const setValue = (val) => {
      if (!hasReply.value) {
        selectValue.value = val;
      }
    };
    const setHoverValue = (value) => {
      if (!hasReply.value) {
        hoverValue.value = value;
      }
    };
    const submitRatingStar = () => {
      if (selectValue.value >= 0) {
        const submitData = {
          data: JSON.stringify({
            src: TUIKit_tuiCustomerServicePlugin_constant.CUSTOM_MESSAGE_SRC.MENU_SELECTED,
            menuSelected: {
              id: props.ratingTemplate.menu[selectValue.value].id,
              content: props.ratingTemplate.menu[selectValue.value].content,
              sessionId: sessionId.value
            },
            customerServicePlugin: 0
          })
        };
        hasReply.value = true;
        emit("sendMessage", submitData);
      }
    };
    return {
      props,
      hasReply,
      sessionId,
      selectValue,
      hoverValue,
      hasExpire,
      desc,
      numberList,
      setValue,
      setHoverValue,
      submitRatingStar
    };
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: common_vendor.t($setup.props.ratingTemplate.head),
    b: common_vendor.f($setup.numberList, (item, index, i0) => {
      return {
        a: common_vendor.t(item + 1),
        b: index,
        c: !(index !== $setup.selectValue && index !== $setup.hoverValue) ? 1 : "",
        d: index !== $setup.selectValue && index !== $setup.hoverValue ? 1 : "",
        e: index === 0 ? "0px" : "20px",
        f: common_vendor.o$1(($event) => $setup.setValue(index), index),
        g: common_vendor.o$1(($event) => $setup.setHoverValue(index), index),
        h: common_vendor.o$1(($event) => $setup.setHoverValue(-1), index)
      };
    }),
    c: "5px",
    d: common_vendor.t($setup.hoverValue === -1 ? $setup.selectValue === -1 ? "如果满意请给好评哦～" : $setup.desc[$setup.selectValue] : $setup.desc[$setup.hoverValue]),
    e: "10px",
    f: "10px",
    g: $setup.hasReply || $setup.hasExpire,
    h: common_vendor.o$1((...args) => $setup.submitRatingStar && $setup.submitRatingStar(...args)),
    i: $setup.hasReply
  }, $setup.hasReply ? {
    j: common_vendor.t($setup.props.ratingTemplate.tail),
    k: "20px"
  } : {});
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-1a21fdf4"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/tui-customer-service-plugin/components/message-rating/message-rating-number.js.map
