"use strict";
const common_vendor = require("../../../../../common/vendor.js");
require("../../../../adapter-vue.js");
const TUIKit_utils_env = require("../../../../utils/env.js");
const common_assets = require("../../../../../common/assets.js");
const TUIKit_components_TUIChat_utils_utils = require("../../utils/utils.js");
const TUIKit_components_TUIChat_offlinePushInfoManager_index = require("../../offlinePushInfoManager/index.js");
const TUIKit_components_TUIChat_config = require("../../config.js");
if (!Math) {
  ToolbarItemContainer();
}
const ToolbarItemContainer = () => "../toolbar-item-container/index.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  props: {
    // Image source: only valid for uni-app version, web version only supports selecting images from the album.
    // album: Select from album
    // camera: Take a photo using the camera
    imageSourceType: {
      type: String,
      default: "album"
    }
  },
  setup(__props) {
    const props = __props;
    const inputRef = common_vendor.ref();
    const currentConversation = common_vendor.ref();
    const theme = TUIKit_components_TUIChat_config.ChatConfig.getTheme();
    const IMAGE_TOOLBAR_SHOW_MAP = {
      web_album: {
        icon: theme === "dark" ? common_assets.imageIconDark : common_assets.imageIconLight,
        title: "图片"
      },
      uni_album: {
        icon: common_assets.imageUniIcon,
        title: "图片"
      },
      uni_camera: {
        icon: common_assets.cameraUniIcon,
        title: "拍照"
      }
    };
    common_vendor.Jt.watch(common_vendor.o.CONV, {
      currentConversation: (conversation) => {
        currentConversation.value = conversation;
      }
    });
    const imageToolbarForShow = common_vendor.computed(() => {
      if (TUIKit_utils_env.isUniFrameWork) {
        return props.imageSourceType === "camera" ? IMAGE_TOOLBAR_SHOW_MAP["uni_camera"] : IMAGE_TOOLBAR_SHOW_MAP["uni_album"];
      } else {
        return IMAGE_TOOLBAR_SHOW_MAP["web_album"];
      }
    });
    const onIconClick = () => {
      var _a, _b, _c, _d;
      if (TUIKit_utils_env.isUniFrameWork) {
        if (TUIKit_utils_env.isWeChat && ((_a = common_vendor.i) == null ? void 0 : _a.chooseMedia)) {
          (_b = common_vendor.i) == null ? void 0 : _b.chooseMedia({
            count: 1,
            mediaType: ["image"],
            sizeType: ["original", "compressed"],
            sourceType: [props.imageSourceType],
            // Use camera or select from album.
            success: function(res) {
              sendImageMessage(res);
            }
          });
        } else {
          (_c = common_vendor.i) == null ? void 0 : _c.chooseImage({
            count: 1,
            sourceType: [props.imageSourceType],
            // Use camera or select from album.
            success: function(res) {
              sendImageMessage(res);
            }
          });
        }
      } else {
        if ((_d = inputRef.value) == null ? void 0 : _d.click) {
          inputRef.value.click();
        }
      }
    };
    const sendImageInWeb = (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;
      }
      sendImageMessage(e == null ? void 0 : e.target);
      e.target.value = "";
    };
    const sendImageMessage = (files) => {
      var _a, _b, _c, _d, _e;
      if (!files) {
        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: files
        },
        needReadReceipt: TUIKit_components_TUIChat_utils_utils.isEnabledMessageReadReceiptGlobal()
      };
      const offlinePushInfoCreateParams = {
        conversation: currentConversation.value,
        payload: options.payload,
        messageType: common_vendor.qt.TYPES.MSG_IMAGE
      };
      const sendMessageOptions = {
        offlinePushInfo: TUIKit_components_TUIChat_offlinePushInfoManager_index.OfflinePushInfoManager.create(offlinePushInfoCreateParams)
      };
      common_vendor.Qt.sendImageMessage(options, sendMessageOptions);
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: !common_vendor.unref(TUIKit_utils_env.isUniFrameWork)
      }, !common_vendor.unref(TUIKit_utils_env.isUniFrameWork) ? {
        b: common_vendor.o$1(sendImageInWeb),
        c: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) && "image-upload-h5")
      } : {}, {
        d: common_vendor.o$1(onIconClick),
        e: common_vendor.p({
          iconFile: common_vendor.unref(imageToolbarForShow).icon,
          title: common_vendor.unref(imageToolbarForShow).title,
          iconWidth: common_vendor.unref(TUIKit_utils_env.isUniFrameWork) ? "32px" : "20px",
          iconHeight: common_vendor.unref(TUIKit_utils_env.isUniFrameWork) ? "25px" : "18px",
          needDialog: false
        })
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2d15f470"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-input-toolbar/image-upload/index.js.map
