"use strict";
const common_vendor = require("../../../../../common/vendor.js");
const TUIKit_components_TUIChat_config = require("../../config.js");
const common_assets = require("../../../../../common/assets.js");
const components_generateMsgId = require("../../../../../components/generateMsgId.js");
const TUIKit_components_TUIChat_utils_utils = require("../../utils/utils.js");
const TUIKit_components_TUIChat_offlinePushInfoManager_index = require("../../offlinePushInfoManager/index.js");
const stores_counter = require("../../../../../stores/counter.js");
const components_request = require("../../../../../components/request.js");
const components_TimeFormatting = require("../../../../../components/TimeFormatting.js");
if (!Array) {
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  _easycom_uni_popup2();
}
const _easycom_uni_popup = () => "../../../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (ToolbarItemContainer + _easycom_uni_popup)();
}
const ToolbarItemContainer = () => "../toolbar-item-container/index.js";
const _sfc_main = {
  __name: "CustomMessage",
  emits: ["onDialogPopupShowOrHide"],
  setup(__props, { emit: __emit }) {
    const counter = stores_counter.useCounterStore();
    const evaluateIcon = TUIKit_components_TUIChat_config.ChatConfig.getTheme() === "dark" ? common_assets.InvitationDark : common_assets.InvitationLight;
    const emits = __emit;
    const onDialogShow = () => {
      emits("onDialogPopupShowOrHide", true);
    };
    const onDialogClose = () => {
      emits("onDialogPopupShowOrHide", false);
    };
    const currentConversation = common_vendor.ref();
    const mylist = common_vendor.ref([]);
    const youlist = common_vendor.ref([]);
    common_vendor.Jt.watch(common_vendor.o.CONV, {
      currentConversation: (conversation) => {
        currentConversation.value = conversation;
        components_request.request({
          url: "pk/queryMyCanUsePkData",
          method: "POST",
          data: {
            userId: counter.myitem.id
          },
          userInfo: true
        }).then((res) => {
          if (res.code === 200) {
            common_vendor.index.__f__("log", "at TUIKit/components/TUIChat/message-input-toolbar/evaluate/CustomMessage.vue:226", "mylist", res.data);
            mylist.value = res.data;
          }
        });
        components_request.request({
          url: "pk/listUninvitedPublishedAnchorsByUserId",
          method: "POST",
          data: {
            userId: currentConversation.value.userProfile.userID
          },
          userInfo: true
        }).then((res) => {
          if (res.code === 200) {
            common_vendor.index.__f__("log", "at TUIKit/components/TUIChat/message-input-toolbar/evaluate/CustomMessage.vue:240", "youlist", res.data);
            youlist.value = res.data;
          }
        });
      }
    });
    const list = common_vendor.ref([]);
    const popup = common_vendor.ref();
    function onyourChoose() {
      popup.value.open("center");
      list.value = youlist.value;
    }
    function onmyChoose() {
      popup.value.open("center");
      list.value = mylist.value;
    }
    const myselectedId = common_vendor.ref(null);
    const youselectedId = common_vendor.ref(null);
    const youselectedindex = common_vendor.ref(null);
    const myselectedindex = common_vendor.ref(null);
    function Select(item, index) {
      if (list.value == mylist.value) {
        myselectedId.value = item;
        myselectedindex.value = index;
      } else if (list.value == youlist.value) {
        youselectedId.value = item;
        youselectedindex.value = index;
      }
    }
    function close() {
      popup.value.close();
      if (list.value == mylist.value) {
        myselectedId.value = null;
        myselectedindex.value = null;
      } else if (list.value == youlist.value) {
        youselectedId.value = null;
        youselectedindex.value = null;
      }
    }
    const myinfodata = common_vendor.ref(null);
    const youselfdata = common_vendor.ref(null);
    function invite() {
      if (list.value == mylist.value) {
        if (myselectedindex.value == null) {
          common_vendor.index.showToast({
            title: "请选择您要邀请的对手",
            icon: "none",
            duration: 3e3
          });
          return;
        } else {
          myinfodata.value = list.value[myselectedindex.value];
          popup.value.close();
        }
      } else if (list.value == youlist.value) {
        if (youselectedindex.value == null) {
          common_vendor.index.showToast({
            title: "请选择您要参与的PK信息",
            icon: "none",
            duration: 3e3
          });
          return;
        } else {
          youselfdata.value = list.value[youselectedindex.value];
          popup.value.close();
        }
      }
    }
    const container = common_vendor.ref();
    function onClose() {
      var _a;
      (_a = container == null ? void 0 : container.value) == null ? void 0 : _a.toggleDialogDisplay(false);
    }
    const popups = common_vendor.ref();
    const submitEvaluate = () => {
      popups.value.open("center");
    };
    function closeHint() {
      popups.value.close();
    }
    const inviteHint = () => {
      components_request.request({
        url: "pk/createPkRecord",
        method: "POST",
        data: {
          pkIdA: youselfdata.value.id,
          pkIdB: myinfodata.value.id,
          userIdA: youselfdata.value.senderId,
          userIdB: myinfodata.value.senderId,
          pkTime: youselfdata.value.pkTime,
          pkNumber: youselfdata.value.pkNumber,
          anchorIdA: youselfdata.value.anchorId,
          anchorIdB: myinfodata.value.anchorId,
          anchorIconA: youselfdata.value.anchorIcon,
          anchorIconB: myinfodata.value.anchorIcon,
          piIdA: youselfdata.value.id,
          piIdB: myinfodata.value.id
        },
        userInfo: true
      }).then((res) => {
        var _a, _b, _c, _d, _e, _f;
        if (res.code === 200) {
          const keyid = components_generateMsgId.generateMsgId();
          const payload = {
            data: JSON.stringify({
              businessID: "pk",
              keyid,
              myitem: myinfodata.value.id,
              pkIdA: youselfdata.value.id,
              pkIdB: myinfodata.value.id,
              userIdA: youselfdata.value.senderId,
              userIdB: myinfodata.value.senderId,
              pkTime: youselfdata.value.pkTime,
              pkNumber: youselfdata.value.pkNumber,
              id: res.data.id,
              link: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/pk.png",
              btnDisplay: true
            }),
            description: "邀请参加PK",
            extension: "邀请参加PK"
          };
          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: TUIKit_components_TUIChat_utils_utils.isEnabledMessageReadReceiptGlobal()
          };
          const offlinePushInfoCreateParams = {
            conversation: currentConversation.value,
            payload: options.payload,
            messageType: common_vendor.qt.TYPES.MSG_CUSTOM
          };
          const sendMessageOptions = {
            offlinePushInfo: TUIKit_components_TUIChat_offlinePushInfoManager_index.OfflinePushInfoManager.create(offlinePushInfoCreateParams)
          };
          common_vendor.Qt.sendCustomMessage(options, sendMessageOptions).then((res2) => {
            components_request.request({
              url: "chat/add",
              method: "POST",
              data: {
                messageInfo: JSON.stringify(res2.data.message),
                keyId: keyid
              },
              userInfo: true
            });
          });
          myinfodata.value = null;
          youselfdata.value = null;
          currentConversation.value = null;
          myselectedId.value = null;
          myselectedindex.value = null;
          youselectedId.value = null;
          youselectedindex.value = null;
          list.value = [];
          (_f = container == null ? void 0 : container.value) == null ? void 0 : _f.toggleDialogDisplay(false);
        } else {
          common_vendor.index.showToast({
            title: res.msg,
            icon: "none",
            duration: 3e3
          });
        }
      });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o$1(onClose),
        b: youselfdata.value == null
      }, youselfdata.value == null ? {} : {
        c: youselfdata.value.anchorIcon,
        d: common_vendor.t(youselfdata.value.anchorId),
        e: common_vendor.t(common_vendor.unref(components_TimeFormatting.TimeFormatting)(youselfdata.value.pkTime)),
        f: common_vendor.t(youselfdata.value.coin)
      }, {
        g: common_vendor.o$1(onyourChoose),
        h: myinfodata.value == null
      }, myinfodata.value == null ? {} : {
        i: myinfodata.value.anchorIcon,
        j: common_vendor.t(myinfodata.value.anchorId),
        k: common_vendor.t(common_vendor.unref(components_TimeFormatting.TimeFormatting)(myinfodata.value.pkTime)),
        l: common_vendor.t(myinfodata.value.coin)
      }, {
        m: common_vendor.o$1(onmyChoose),
        n: common_vendor.o$1(submitEvaluate),
        o: common_vendor.sr(container, "241228dc-0", {
          "k": "container"
        }),
        p: common_vendor.o$1(onDialogShow),
        q: common_vendor.o$1(onDialogClose),
        r: common_vendor.p({
          iconFile: common_vendor.unref(evaluateIcon),
          title: "邀请",
          needBottomPopup: true,
          iconWidth: _ctx.isUniFrameWork ? "36px" : "30px",
          iconHeight: _ctx.isUniFrameWork ? "36px" : "30px"
        }),
        s: list.value.length !== 0
      }, list.value.length !== 0 ? {
        t: common_vendor.f(list.value, (item, index, i0) => {
          return {
            a: item.anchorIcon,
            b: common_vendor.t(list.value == mylist.value ? item.anchorId : item.disPlayId),
            c: common_vendor.t(common_vendor.unref(components_TimeFormatting.TimeFormatting)(item.pkTime)),
            d: common_vendor.t(item.coin),
            e: common_vendor.o$1(($event) => Select(item.id, index), index),
            f: myselectedId.value === item.id || youselectedId.value === item.id ? "#b8ff8c74" : "#ffffff",
            g: index
          };
        })
      } : {}, {
        v: list.value.length === 0
      }, list.value.length === 0 ? {} : {}, {
        w: common_vendor.o$1(($event) => invite()),
        x: common_vendor.o$1(($event) => close()),
        y: common_vendor.sr(popup, "241228dc-1", {
          "k": "popup"
        }),
        z: common_vendor.p({
          type: "center",
          ["border-radius"]: "10px 10px 0 0"
        }),
        A: common_vendor.o$1(inviteHint),
        B: common_vendor.o$1(closeHint),
        C: common_vendor.sr(popups, "241228dc-2", {
          "k": "popups"
        }),
        D: common_vendor.p({
          type: "center",
          ["border-radius"]: "10px 10px 0 0"
        })
      });
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-241228dc"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-input-toolbar/evaluate/CustomMessage.js.map
