import { defineComponent, ref, openBlock, createBlock, unref, withCtx, createElementVNode, normalizeClass } from "vue";
import TUIChatEngine, { TUIStore, StoreName, TUIChatService } from "@tencentcloud/chat-uikit-engine";
import { TUIGlobal } from "@tencentcloud/universal-api";
import "../../../../adapter-vue.mjs";
import { isUniFrameWork, isPC, isWeChat } from "../../../../utils/env.mjs";
import ToolbarItemContainer from "../toolbar-item-container/index.vue.mjs";
import videoIconLight from "../../../../assets/icon/video-light.svg.mjs";
import videoIconDark from "../../../../assets/icon/video-dark.svg.mjs";
import videoUniIcon from "../../../../assets/icon/video-uni.png.mjs";
import cameraUniIcon from "../../../../assets/icon/camera-uni.png.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",
  props: {
    // Video source, only valid for uni-app version, web version only supports selecting videos from files
    // album: Select from files
    // camera: Take a video using the camera
    videoSourceType: {
      type: String,
      default: "album"
    }
  },
  setup(__props) {
    const props = __props;
    const inputRef = ref();
    const currentConversation = ref();
    TUIStore.watch(StoreName.CONV, {
      currentConversation: (conversation) => {
        currentConversation.value = conversation;
      }
    });
    const handleIcon = () => {
      if (isUniFrameWork) {
        switch (props.videoSourceType) {
          case "album":
            return videoUniIcon;
          case "camera":
            return cameraUniIcon;
          default:
            return videoUniIcon;
        }
      } else {
        const videoIcon = ChatConfig.getTheme() === "dark" ? videoIconDark : videoIconLight;
        return videoIcon;
      }
    };
    const handleTitle = () => {
      if (isUniFrameWork && props.videoSourceType === "camera") {
        return "录制";
      } else {
        return "视频";
      }
    };
    const onIconClick = () => {
      var _a, _b, _c, _d, _e;
      if (isUniFrameWork) {
        if (isWeChat && ((_a = TUIGlobal) == null ? void 0 : _a.chooseMedia)) {
          (_b = TUIGlobal) == null ? void 0 : _b.chooseMedia({
            mediaType: ["video"],
            count: 1,
            sourceType: [props.videoSourceType],
            maxDuration: 60,
            success: function(res) {
              sendVideoMessage(res);
            }
          });
        } else {
          (_c = TUIGlobal) == null ? void 0 : _c.chooseVideo({
            count: 1,
            sourceType: [props.videoSourceType],
            compressed: false,
            success: function(res) {
              sendVideoMessage(res);
            }
          });
        }
      } else {
        ((_d = inputRef == null ? void 0 : inputRef.value) == null ? void 0 : _d.click) && ((_e = inputRef == null ? void 0 : inputRef.value) == null ? void 0 : _e.click());
      }
    };
    const sendVideoInWeb = (e) => {
      var _a, _b;
      if (((_b = (_a = e == null ? void 0 : e.target) == null ? void 0 : _a.files) == null ? void 0 : _b.length) <= 0) {
        return;
      }
      sendVideoMessage(e == null ? void 0 : e.target);
      e.target.value = "";
    };
    const sendVideoMessage = (file) => {
      var _a, _b, _c, _d, _e;
      if (!file) {
        return;
      }
      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: {
          file
        },
        needReadReceipt: isEnabledMessageReadReceiptGlobal()
      };
      const offlinePushInfoCreateParams = {
        conversation: currentConversation.value,
        payload: options.payload,
        messageType: TUIChatEngine.TYPES.MSG_VIDEO
      };
      const sendMessageOptions = {
        offlinePushInfo: OfflinePushInfoManager.create(offlinePushInfoCreateParams)
      };
      TUIChatService.sendVideoMessage(options, sendMessageOptions);
    };
    return (_ctx, _cache) => {
      return openBlock(), createBlock(ToolbarItemContainer, {
        iconFile: handleIcon(),
        title: handleTitle(),
        needDialog: false,
        iconWidth: unref(isUniFrameWork) ? "32px" : "20px",
        iconHeight: unref(isUniFrameWork) ? props.videoSourceType === "album" ? "20px" : "25px" : "18px",
        onOnIconClick: onIconClick
      }, {
        default: withCtx(() => [
          createElementVNode("div", {
            class: normalizeClass(["video-upload", !unref(isPC) && "video-upload-h5"])
          }, [
            createElementVNode("input", {
              ref_key: "inputRef",
              ref: inputRef,
              title: "视频",
              type: "file",
              "data-type": "video",
              accept: "video/*",
              onChange: sendVideoInWeb
            }, null, 544)
          ], 2)
        ]),
        _: 1
      }, 8, ["iconFile", "title", "iconWidth", "iconHeight"]);
    };
  }
});
export {
  _sfc_main as default
};
