import { defineComponent, ref, openBlock, createBlock, unref, withCtx, createElementVNode, normalizeClass } from "vue";
import TUIChatEngine, { TUIStore, StoreName, TUIChatService } from "@tencentcloud/chat-uikit-engine";
import "../../../../adapter-vue.mjs";
import ToolbarItemContainer from "../toolbar-item-container/index.vue.mjs";
import fileIconLight from "../../../../assets/icon/file-light.svg.mjs";
import fileIconDark from "../../../../assets/icon/file-dark.svg.mjs";
import { isUniFrameWork, isPC } from "../../../../utils/env.mjs";
import { isEnabledMessageReadReceiptGlobal } from "../../utils/utils.mjs";
import OfflinePushInfoManager from "../../offlinePushInfoManager/index.mjs";
import ChatConfig from "../../config.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    const fileIcon = ChatConfig.getTheme() === "dark" ? fileIconDark : fileIconLight;
    const inputRef = ref();
    const currentConversation = ref();
    TUIStore.watch(StoreName.CONV, {
      currentConversation: (conversation) => {
        currentConversation.value = conversation;
      }
    });
    const onIconClick = () => {
      var _a, _b;
      if (isUniFrameWork) {
        return;
      } else {
        ((_a = inputRef == null ? void 0 : inputRef.value) == null ? void 0 : _a.click) && ((_b = inputRef == null ? void 0 : inputRef.value) == null ? void 0 : _b.click());
      }
    };
    const sendFileMessage = (e) => {
      var _a, _b, _c, _d, _e, _f, _g;
      if (((_b = (_a = e == null ? void 0 : e.target) == null ? void 0 : _a.files) == null ? void 0 : _b.length) <= 0) {
        return;
      }
      const options = {
        to: ((_d = (_c = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _c.groupProfile) == null ? void 0 : _d.groupID) || ((_f = (_e = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _e.userProfile) == null ? void 0 : _f.userID),
        conversationType: (_g = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _g.type,
        payload: {
          file: e == null ? void 0 : e.target
        },
        needReadReceipt: isEnabledMessageReadReceiptGlobal()
      };
      const offlinePushInfoCreateParams = {
        conversation: currentConversation.value,
        payload: options.payload,
        messageType: TUIChatEngine.TYPES.MSG_FILE
      };
      const sendMessageOptions = {
        offlinePushInfo: OfflinePushInfoManager.create(offlinePushInfoCreateParams)
      };
      TUIChatService.sendFileMessage(options, sendMessageOptions);
      e.target.value = "";
    };
    return (_ctx, _cache) => {
      return openBlock(), createBlock(ToolbarItemContainer, {
        iconFile: unref(fileIcon),
        title: "文件",
        iconWidth: unref(isUniFrameWork) ? "32px" : "20px",
        iconHeight: unref(isUniFrameWork) ? "25px" : "18px",
        needDialog: false,
        onOnIconClick: onIconClick
      }, {
        default: withCtx(() => [
          createElementVNode("div", {
            class: normalizeClass(["file-upload", !unref(isPC) && "file-upload-h5"])
          }, [
            createElementVNode("input", {
              ref_key: "inputRef",
              ref: inputRef,
              title: "文件",
              type: "file",
              "data-type": "file",
              accept: "*",
              onChange: sendFileMessage
            }, null, 544)
          ], 2)
        ]),
        _: 1
      }, 8, ["iconFile", "iconWidth", "iconHeight"]);
    };
  }
});
export {
  _sfc_main as default
};
