"use strict";
const common_vendor = require("../../../../common/vendor.js");
require("../../../adapter-vue.js");
const TUIKit_utils_env = require("../../../utils/env.js");
const TUIKit_components_TUIContact_utils_index = require("../utils/index.js");
const TUIKit_components_TUIContact_contactInfo_contactInfoConfig = require("./contact-info-config.js");
const common_assets = require("../../../../common/assets.js");
const TUIKit_constant = require("../../../constant.js");
const TUIKit_components_TUIChat_utils_utils = require("../../TUIChat/utils/utils.js");
if (!Math) {
  (Icon + SwitchBar)();
}
const Icon = () => "../../common/Icon.js";
const SwitchBar = () => "../../common/SwitchBar/index.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  emits: ["switchConversation"],
  setup(__props, { emit: __emit }) {
    const emits = __emit;
    const contactInfoData = common_vendor.ref({});
    const contactInfoBasicList = common_vendor.ref([]);
    const contactInfoMoreList = common_vendor.ref([]);
    const contactInfoButtonList = common_vendor.ref([]);
    const setEditing = (item) => {
      item.editing = true;
    };
    const isGroup = common_vendor.computed(
      () => {
        var _a;
        return ((_a = contactInfoData.value) == null ? void 0 : _a.groupID) ? true : false;
      }
    );
    const isApplication = common_vendor.computed(() => {
      return TUIKit_components_TUIContact_utils_index.isApplicationType(contactInfoData == null ? void 0 : contactInfoData.value);
    });
    const isBothFriend = common_vendor.ref(false);
    const isGroupMember = common_vendor.computed(() => {
      var _a, _b;
      return ((_b = (_a = contactInfoData.value) == null ? void 0 : _a.selfInfo) == null ? void 0 : _b.userID) ? true : false;
    });
    const isInBlackList = common_vendor.computed(() => {
      var _a;
      return !isGroup.value && ((_a = blackList.value) == null ? void 0 : _a.findIndex(
        (item) => {
          var _a2;
          return (item == null ? void 0 : item.userID) === ((_a2 = contactInfoData.value) == null ? void 0 : _a2.userID);
        }
      )) >= 0;
    });
    const blackList = common_vendor.ref([]);
    common_vendor.onMounted(() => {
      common_vendor.Jt.watch(common_vendor.o.CUSTOM, {
        currentContactInfo: onCurrentContactInfoUpdated
      });
      common_vendor.Jt.watch(common_vendor.o.USER, {
        userBlacklist: onUserBlacklistUpdated
      });
    });
    common_vendor.onUnmounted(() => {
      common_vendor.Jt.unwatch(common_vendor.o.CUSTOM, {
        currentContactInfo: onCurrentContactInfoUpdated
      });
      common_vendor.Jt.unwatch(common_vendor.o.USER, {
        userBlacklist: onUserBlacklistUpdated
      });
    });
    const resetContactInfoUIData = () => {
      contactInfoData.value = {};
      contactInfoBasicList.value = [];
      contactInfoMoreList.value = [];
      contactInfoButtonList.value = [];
    };
    const resetContactSearchingUIData = () => {
      var _a, _b;
      common_vendor.Jt.update(common_vendor.o.CUSTOM, "currentContactInfo", {});
      common_vendor.Jt.update(common_vendor.o.CUSTOM, "currentContactSearchingStatus", false);
      ((_a = common_vendor.i) == null ? void 0 : _a.closeSearching) && ((_b = common_vendor.i) == null ? void 0 : _b.closeSearching());
    };
    const onContactInfoEmitSubmit = (item) => {
      item.editSubmitHandler && item.editSubmitHandler({
        item,
        contactInfoData: contactInfoData.value,
        isBothFriend: isBothFriend.value,
        isInBlackList: isInBlackList.value
      });
    };
    const onContactInfoButtonClicked = (item) => {
      item.onClick && item.onClick({
        contactInfoData: contactInfoData.value,
        contactInfoMoreList: contactInfoMoreList.value
      });
      if (item.key === "enterGroupConversation" || item.key === "enterC2CConversation") {
        emits("switchConversation", contactInfoData.value);
        resetContactSearchingUIData();
      }
    };
    const generateMoreInfo = async () => {
      var _a, _b, _c, _d, _e;
      if (!isApplication.value) {
        if (!isGroup.value && !isBothFriend.value && !isInBlackList.value || isGroup.value && !isGroupMember.value && ((_a = contactInfoData.value) == null ? void 0 : _a.type) !== ((_c = (_b = common_vendor.qt) == null ? void 0 : _b.TYPES) == null ? void 0 : _c.GRP_AVCHATROOM)) {
          TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig.setWords.data = "";
          contactInfoMoreList.value.push(TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig.setWords);
        }
        if (!isGroup.value && !isInBlackList.value) {
          TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig.setRemark.data = ((_d = contactInfoData.value) == null ? void 0 : _d.remark) || "";
          TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig.setRemark.editing = false;
          contactInfoMoreList.value.push(TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig.setRemark);
        }
        if (!isGroup.value && (isBothFriend.value || isInBlackList.value)) {
          TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig.blackList.data = isInBlackList.value || false;
          contactInfoMoreList.value.push(TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig.blackList);
        }
      } else {
        TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig.displayWords.data = ((_e = contactInfoData.value) == null ? void 0 : _e.wording) || "";
        contactInfoMoreList.value.push(TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig.displayWords);
      }
    };
    const generateButton = () => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
      if (isInBlackList.value) {
        return;
      }
      if (isApplication.value) {
        if (((_a = contactInfoData.value) == null ? void 0 : _a.type) === ((_c = (_b = common_vendor.qt) == null ? void 0 : _b.TYPES) == null ? void 0 : _c.SNS_APPLICATION_SENT_TO_ME)) {
          (_d = contactInfoButtonList == null ? void 0 : contactInfoButtonList.value) == null ? void 0 : _d.push(
            TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.refuseFriendApplication
          );
          (_e = contactInfoButtonList == null ? void 0 : contactInfoButtonList.value) == null ? void 0 : _e.push(
            TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.acceptFriendApplication
          );
        }
      } else {
        if (isGroup.value && isGroupMember.value) {
          switch ((_g = (_f = contactInfoData.value) == null ? void 0 : _f.selfInfo) == null ? void 0 : _g.role) {
            case "Owner":
              (_h = contactInfoButtonList == null ? void 0 : contactInfoButtonList.value) == null ? void 0 : _h.push(TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.dismissGroup);
              break;
            default:
              (_i = contactInfoButtonList == null ? void 0 : contactInfoButtonList.value) == null ? void 0 : _i.push(TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.quitGroup);
              break;
          }
          (_j = contactInfoButtonList == null ? void 0 : contactInfoButtonList.value) == null ? void 0 : _j.push(
            TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.enterGroupConversation
          );
        } else if (!isGroup.value && isBothFriend.value) {
          (_k = contactInfoButtonList == null ? void 0 : contactInfoButtonList.value) == null ? void 0 : _k.push(TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.deleteFriend);
          (_l = contactInfoButtonList == null ? void 0 : contactInfoButtonList.value) == null ? void 0 : _l.push(
            TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.enterC2CConversation
          );
        } else {
          if (isGroup.value) {
            (_p = contactInfoButtonList == null ? void 0 : contactInfoButtonList.value) == null ? void 0 : _p.push(
              ((_m = contactInfoData.value) == null ? void 0 : _m.type) === ((_o = (_n = common_vendor.qt) == null ? void 0 : _n.TYPES) == null ? void 0 : _o.GRP_AVCHATROOM) ? TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.joinAVChatGroup : TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.joinGroup
            );
          } else {
            (_q = contactInfoButtonList == null ? void 0 : contactInfoButtonList.value) == null ? void 0 : _q.push(TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig.addFriend);
          }
        }
      }
    };
    function onUserBlacklistUpdated(userBlacklist) {
      blackList.value = userBlacklist;
    }
    async function onCurrentContactInfoUpdated(contactInfo) {
      var _a;
      if (contactInfoData.value && contactInfo && JSON.stringify(contactInfoData.value) === JSON.stringify(contactInfo)) {
        return;
      }
      resetContactInfoUIData();
      contactInfoData.value = TUIKit_components_TUIChat_utils_utils.deepCopy(contactInfo) || {};
      if (!contactInfoData.value || ((_a = Object.keys(contactInfoData.value)) == null ? void 0 : _a.length) === 0) {
        return;
      }
      contactInfoBasicList.value = TUIKit_components_TUIContact_utils_index.generateContactInfoBasic(
        contactInfoData.value
      );
      isBothFriend.value = await TUIKit_components_TUIContact_utils_index.isFriend(contactInfoData.value);
      generateMoreInfo();
      generateButton();
      if (contactInfo.infoKeyList) {
        contactInfoMoreList.value = contactInfo.infoKeyList.map((key) => {
          return TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactMoreInfoConfig[key];
        });
      }
      if (contactInfo.btnKeyList) {
        contactInfoButtonList.value = contactInfo.btnKeyList.map((key) => {
          return TUIKit_components_TUIContact_contactInfo_contactInfoConfig.contactButtonConfig[key];
        });
      }
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: typeof common_vendor.unref(contactInfoData) === "object" && Object.keys(common_vendor.unref(contactInfoData)).length
      }, typeof common_vendor.unref(contactInfoData) === "object" && Object.keys(common_vendor.unref(contactInfoData)).length ? common_vendor.e({
        b: !common_vendor.unref(TUIKit_utils_env.isPC)
      }, !common_vendor.unref(TUIKit_utils_env.isPC) ? {
        c: common_vendor.p({
          file: common_vendor.unref(common_assets.backIcon)
        }),
        d: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-header-icon"),
        e: common_vendor.o$1(resetContactSearchingUIData),
        f: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIContact.添加好友/群聊")),
        g: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-header-title"),
        h: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-header")
      } : {}, {
        i: common_vendor.t(common_vendor.unref(TUIKit_components_TUIContact_utils_index.generateContactInfoName)(common_vendor.unref(contactInfoData))),
        j: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-basic-text-name"),
        k: common_vendor.f(common_vendor.unref(contactInfoBasicList), (item, k0, i0) => {
          return {
            a: common_vendor.t(`${common_vendor.unref(common_vendor.Wt).t(`TUIContact.${item.label}`)}:
          ${item.data}`),
            b: item.label
          };
        }),
        l: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-basic-text-other"),
        m: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-basic-text"),
        n: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-basic-avatar"),
        o: common_vendor.unref(TUIKit_components_TUIContact_utils_index.generateAvatar)(common_vendor.unref(contactInfoData)),
        p: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-basic"),
        q: common_vendor.unref(contactInfoMoreList)[0]
      }, common_vendor.unref(contactInfoMoreList)[0] ? {
        r: common_vendor.f(common_vendor.unref(contactInfoMoreList), (item, k0, i0) => {
          return common_vendor.e({
            a: common_vendor.t(`${common_vendor.unref(common_vendor.Wt).t(`TUIContact.${item.label}`)}`),
            b: !item.editing
          }, !item.editing ? common_vendor.e({
            c: common_vendor.t(item.data),
            d: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-more-item-content-text-data"),
            e: item.editable
          }, item.editable ? {
            f: "e2a6c8d8-1-" + i0,
            g: common_vendor.p({
              file: common_vendor.unref(common_assets.editIcon),
              width: "14px",
              height: "14px"
            }),
            h: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-more-item-content-text-icon"),
            i: common_vendor.o$1(($event) => setEditing(item), item.key)
          } : {}, {
            j: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-more-item-content-text")
          }) : item.editType === common_vendor.unref(TUIKit_constant.CONTACT_INFO_MORE_EDIT_TYPE).INPUT ? {
            l: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-more-item-content-input"),
            m: common_vendor.o$1(($event) => onContactInfoEmitSubmit(item), item.key),
            n: common_vendor.o$1(($event) => onContactInfoEmitSubmit(item), item.key),
            o: item.data,
            p: common_vendor.o$1(($event) => item.data = $event.detail.value, item.key)
          } : item.editType === common_vendor.unref(TUIKit_constant.CONTACT_INFO_MORE_EDIT_TYPE).TEXTAREA ? {
            r: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-more-item-content-textarea"),
            s: item.data,
            t: common_vendor.o$1(($event) => item.data = $event.detail.value, item.key)
          } : item.editType === common_vendor.unref(TUIKit_constant.CONTACT_INFO_MORE_EDIT_TYPE).SWITCH ? {
            w: "e2a6c8d8-2-" + i0,
            x: common_vendor.p({
              value: item.data
            }),
            y: common_vendor.o$1(($event) => onContactInfoEmitSubmit(item), item.key)
          } : {}, {
            k: item.editType === common_vendor.unref(TUIKit_constant.CONTACT_INFO_MORE_EDIT_TYPE).INPUT,
            q: item.editType === common_vendor.unref(TUIKit_constant.CONTACT_INFO_MORE_EDIT_TYPE).TEXTAREA,
            v: item.editType === common_vendor.unref(TUIKit_constant.CONTACT_INFO_MORE_EDIT_TYPE).SWITCH,
            z: item.key,
            A: common_vendor.n(item.labelPosition === common_vendor.unref(TUIKit_constant.CONTACT_INFO_LABEL_POSITION).TOP ? "tui-contact-info-more-item-top" : "tui-contact-info-more-item-left")
          });
        }),
        s: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-more-item-label"),
        t: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-more-item-content"),
        v: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-more-item"),
        w: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-more")
      } : {}, {
        x: common_vendor.f(common_vendor.unref(contactInfoButtonList), (item, k0, i0) => {
          return {
            a: common_vendor.t(common_vendor.unref(common_vendor.Wt).t(`TUIContact.${item.label}`)),
            b: item.key,
            c: common_vendor.n(item.type === common_vendor.unref(TUIKit_constant.CONTACT_INFO_BUTTON_TYPE).CANCEL ? `tui-contact-info-button-item-cancel` : `tui-contact-info-button-item-submit`),
            d: common_vendor.o$1(($event) => onContactInfoButtonClicked(item), item.key)
          };
        }),
        y: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-button-item"),
        z: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5-button"),
        A: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "tui-contact-info-h5")
      }) : {});
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-e2a6c8d8"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIContact/contact-info/index.js.map
