import { defineComponent, ref, watchEffect, computed, openBlock, createElementBlock, normalizeClass, unref, createVNode, createCommentVNode, createElementVNode, toDisplayString, withKeys, createBlock, Fragment, renderList, renderSlot } from "vue";
import "../../../adapter-vue.mjs";
import { TUITranslateService } from "@tencentcloud/chat-uikit-engine";
import Icon from "../Icon.vue.mjs";
import selectedIcon from "../../../assets/icon/selected.svg.mjs";
import backIcon from "../../../assets/icon/back.svg.mjs";
import cancelIcon from "../../../assets/icon/cancel.svg.mjs";
import { isPC, isMobile, isUniFrameWork } from "../../../utils/env.mjs";
const _hoisted_1 = {
  key: 0,
  class: "transfer-header transfer-h5-header"
};
const _hoisted_2 = { class: "title" };
const _hoisted_3 = { class: "main" };
const _hoisted_4 = { class: "left" };
const _hoisted_5 = { class: "transfer-header" };
const _hoisted_6 = ["value", "placeholder"];
const _hoisted_7 = ["placeholder", "value"];
const _hoisted_8 = { class: "transfer-left-main" };
const _hoisted_9 = { class: "transfer-list" };
const _hoisted_10 = {
  key: 1,
  class: "icon-unselected"
};
const _hoisted_11 = { class: "select-all" };
const _hoisted_12 = ["onClick"];
const _hoisted_13 = ["src"];
const _hoisted_14 = { class: "name" };
const _hoisted_15 = { key: 0 };
const _hoisted_16 = { class: "right" };
const _hoisted_17 = {
  key: 0,
  class: "transfer-header"
};
const _hoisted_18 = {
  key: 1,
  class: "transfer-list"
};
const _hoisted_19 = {
  key: 0,
  class: "transfer-text"
};
const _hoisted_20 = { class: "transfer-list-item-content" };
const _hoisted_21 = ["src"];
const _hoisted_22 = {
  key: 0,
  class: "name"
};
const _hoisted_23 = ["onClick"];
const _hoisted_24 = { class: "transfer-right-footer" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    list: {
      type: Array,
      default: () => []
    },
    selectedList: {
      type: Array,
      default: () => []
    },
    isSearch: {
      type: Boolean,
      default: true
    },
    isRadio: {
      type: Boolean,
      default: false
    },
    isCustomItem: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ""
    },
    type: {
      type: String,
      default: ""
    },
    resultShow: {
      type: Boolean,
      default: true
    },
    total: {
      type: Number,
      default: 0
    },
    isHiddenBackIcon: {
      type: Boolean,
      default: false
    }
  },
  emits: ["search", "submit", "cancel", "getMore"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const transferList = ref([]);
    const transferTotal = ref(0);
    const transferSelectedList = ref([]);
    const isTransferSearch = ref(true);
    const isTransferCustomItem = ref(false);
    const transferTitle = ref("");
    const searchValue = ref("");
    watchEffect(() => {
      if (props.isCustomItem) {
        for (let index = 0; index < props.list.length; index++) {
          if (props.list[index].conversationID.indexOf("@TIM#SYSTEM") > -1) {
            props.list.splice(index, 1);
          }
          transferList.value = props.list;
        }
      } else {
        transferList.value = props.list;
      }
      transferTotal.value = props.total ? props.total : props.list.length;
      transferSelectedList.value = props.selectedList && props.selectedList.length > 0 ? props.selectedList : transferSelectedList.value;
      isTransferSearch.value = props.isSearch;
      isTransferCustomItem.value = props.isCustomItem;
      transferTitle.value = props.title;
    });
    const emit = __emit;
    const optional = computed(
      () => transferList.value.filter((item) => !item.isDisabled)
    );
    const handleInput = (e) => {
      searchValue.value = e.target.value || e.detail.value;
      emit("search", searchValue.value);
    };
    const selected = (item) => {
      if (item.isDisabled) {
        return;
      }
      let list = transferSelectedList.value;
      const index = list.indexOf(item);
      if (index > -1) {
        return transferSelectedList.value.splice(index, 1);
      }
      if (props.isRadio) {
        list = [];
      }
      list.push(item);
      transferSelectedList.value = list;
    };
    const selectedAll = () => {
      if (transferSelectedList.value.length === optional.value.length) {
        transferSelectedList.value = [];
      } else {
        transferSelectedList.value = [...optional.value];
      }
    };
    const submit = () => {
      emit("submit", transferSelectedList.value);
      searchValue.value = "";
    };
    const cancel = () => {
      emit("cancel");
      searchValue.value = "";
    };
    const getMore = () => {
      emit("getMore");
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: normalizeClass(["transfer", [!unref(isPC) ? "transfer-h5" : "", unref(isMobile) ? "transfer-h5-wechat" : ""]])
      }, [
        !unref(isPC) ? (openBlock(), createElementBlock("header", _hoisted_1, [
          !props.isHiddenBackIcon ? (openBlock(), createElementBlock("div", {
            key: 0,
            onClick: cancel
          }, [
            createVNode(Icon, {
              class: "icon",
              file: unref(backIcon),
              width: "18px",
              height: "18px"
            }, null, 8, ["file"])
          ])) : createCommentVNode("", true),
          createElementVNode("span", _hoisted_2, toDisplayString(unref(transferTitle)), 1),
          _cache[0] || (_cache[0] = createElementVNode("span", { class: "space" }, null, -1))
        ])) : createCommentVNode("", true),
        createElementVNode("main", _hoisted_3, [
          createElementVNode("div", _hoisted_4, [
            createElementVNode("header", _hoisted_5, [
              unref(isPC) && unref(isTransferSearch) ? (openBlock(), createElementBlock("input", {
                key: 0,
                type: "text",
                value: unref(searchValue),
                placeholder: unref(TUITranslateService).t("component.请输入userID"),
                enterkeyhint: "search",
                class: normalizeClass([unref(isUniFrameWork) ? "left-uniapp-input" : ""]),
                onKeyup: withKeys(handleInput, ["enter"])
              }, null, 42, _hoisted_6)) : createCommentVNode("", true),
              !unref(isPC) && unref(isTransferSearch) ? (openBlock(), createElementBlock("input", {
                key: 1,
                type: "text",
                placeholder: unref(TUITranslateService).t("component.请输入userID"),
                enterkeyhint: "search",
                value: unref(searchValue),
                class: normalizeClass([unref(isUniFrameWork) ? "left-uniapp-input" : ""]),
                onBlur: handleInput,
                onConfirm: handleInput
              }, null, 42, _hoisted_7)) : createCommentVNode("", true)
            ]),
            createElementVNode("main", _hoisted_8, [
              createElementVNode("ul", _hoisted_9, [
                unref(optional).length > 1 && !__props.isRadio ? (openBlock(), createElementBlock("li", {
                  key: 0,
                  class: "transfer-list-item",
                  onClick: selectedAll
                }, [
                  unref(transferSelectedList).length === unref(optional).length ? (openBlock(), createBlock(Icon, {
                    key: 0,
                    file: unref(selectedIcon),
                    width: "18px",
                    height: "18px"
                  }, null, 8, ["file"])) : (openBlock(), createElementBlock("i", _hoisted_10)),
                  createElementVNode("span", _hoisted_11, toDisplayString(unref(TUITranslateService).t("component.全选")), 1)
                ])) : createCommentVNode("", true),
                (openBlock(true), createElementBlock(Fragment, null, renderList(unref(transferList), (item) => {
                  return openBlock(), createElementBlock("li", {
                    key: item.userID,
                    class: "transfer-list-item",
                    onClick: ($event) => selected(item)
                  }, [
                    unref(transferSelectedList).indexOf(item) > -1 ? (openBlock(), createBlock(Icon, {
                      key: 0,
                      file: unref(selectedIcon),
                      class: normalizeClass([item.isDisabled && "disabled"]),
                      width: "18px",
                      height: "18px"
                    }, null, 8, ["file", "class"])) : (openBlock(), createElementBlock("i", {
                      key: 1,
                      class: normalizeClass([item.isDisabled && "disabled", "icon-unselected"])
                    }, null, 2)),
                    !unref(isTransferCustomItem) ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
                      createElementVNode("img", {
                        class: "avatar",
                        src: item.avatar || "https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png",
                        onerror: "this.onerror=null;this.src='https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png'"
                      }, null, 8, _hoisted_13),
                      createElementVNode("span", _hoisted_14, toDisplayString(item.nick || item.userID), 1),
                      item.isDisabled ? (openBlock(), createElementBlock("span", _hoisted_15, "（" + toDisplayString(unref(TUITranslateService).t("component.已在群中")) + "）", 1)) : createCommentVNode("", true)
                    ], 64)) : renderSlot(_ctx.$slots, "left", {
                      key: 3,
                      data: item
                    }, void 0, true)
                  ], 8, _hoisted_12);
                }), 128)),
                unref(transferTotal) > unref(transferList).length ? (openBlock(), createElementBlock("li", {
                  key: 1,
                  class: "transfer-list-item more",
                  onClick: getMore
                }, toDisplayString(unref(TUITranslateService).t("component.查看更多")), 1)) : createCommentVNode("", true)
              ])
            ])
          ]),
          createElementVNode("div", _hoisted_16, [
            unref(isPC) ? (openBlock(), createElementBlock("header", _hoisted_17, toDisplayString(unref(transferTitle)), 1)) : createCommentVNode("", true),
            __props.resultShow ? (openBlock(), createElementBlock("ul", _hoisted_18, [
              unref(transferSelectedList).length > 0 && unref(isPC) ? (openBlock(), createElementBlock("p", _hoisted_19, toDisplayString(unref(TUITranslateService).t("component.已选中")) + toDisplayString(unref(transferSelectedList).length) + toDisplayString(unref(TUITranslateService).t("component.人")), 1)) : createCommentVNode("", true),
              (openBlock(true), createElementBlock(Fragment, null, renderList(unref(transferSelectedList), (item, index) => {
                return openBlock(), createElementBlock("li", {
                  key: index,
                  class: "transfer-list-item space-between"
                }, [
                  createElementVNode("aside", _hoisted_20, [
                    !unref(isTransferCustomItem) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
                      createElementVNode("img", {
                        class: "avatar",
                        src: item.avatar || "https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png",
                        onerror: "this.onerror=null;this.src='https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png'"
                      }, null, 8, _hoisted_21),
                      unref(isPC) ? (openBlock(), createElementBlock("span", _hoisted_22, toDisplayString(item.nick || item.userID), 1)) : createCommentVNode("", true)
                    ], 64)) : renderSlot(_ctx.$slots, "right", {
                      key: 1,
                      data: item
                    }, void 0, true)
                  ]),
                  unref(isPC) ? (openBlock(), createElementBlock("span", {
                    key: 0,
                    onClick: ($event) => selected(item)
                  }, [
                    createVNode(Icon, {
                      file: unref(cancelIcon),
                      width: "18px",
                      height: "18px"
                    }, null, 8, ["file"])
                  ], 8, _hoisted_23)) : createCommentVNode("", true)
                ]);
              }), 128))
            ])) : createCommentVNode("", true),
            createElementVNode("footer", _hoisted_24, [
              createElementVNode("button", {
                class: "btn btn-cancel",
                onClick: cancel
              }, toDisplayString(unref(TUITranslateService).t("component.取消")), 1),
              unref(transferSelectedList).length > 0 ? (openBlock(), createElementBlock("button", {
                key: 0,
                class: "btn",
                onClick: submit
              }, toDisplayString(unref(TUITranslateService).t("component.完成")), 1)) : (openBlock(), createElementBlock("button", {
                key: 1,
                class: "btn btn-no",
                onClick: submit
              }, toDisplayString(unref(TUITranslateService).t("component.完成")), 1))
            ])
          ])
        ])
      ], 2);
    };
  }
});
export {
  _sfc_main as default
};
