import { defineComponent, openBlock, createElementBlock, unref, createVNode, createElementVNode, toDisplayString } from "vue";
import { TUITranslateService } from "@tencentcloud/chat-uikit-engine";
import Icon from "../../../common/Icon.vue.mjs";
import fileIconLight from "../../../../assets/icon/file-light.svg.mjs";
const _hoisted_1 = ["title"];
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "message-file",
  props: {
    content: { default: () => ({}) },
    messageItem: { default: () => ({}) }
  },
  setup(__props) {
    const props = __props;
    const download = () => {
      if (props.messageItem.hasRiskContent) {
        return;
      }
      const option = {
        mode: "cors",
        headers: new Headers({
          "Content-Type": "application/x-www-form-urlencoded"
        })
      };
      if (window == null ? void 0 : window.fetch) {
        fetch(props.content.url, option).then((res) => res.blob()).then((blob) => {
          const a = document.createElement("a");
          const url = window.URL.createObjectURL(blob);
          a.href = url;
          a.download = props.content.name;
          a.click();
        });
      } else {
        const a = document.createElement("a");
        a.href = props.content.url;
        a.target = "_blank";
        a.download = props.content.name;
        a.click();
      }
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: "file-message-montainer",
        title: unref(TUITranslateService).t("TUIChat.单击下载"),
        onClick: download
      }, [
        createVNode(Icon, {
          file: unref(fileIconLight),
          class: "file-icon"
        }, null, 8, ["file"]),
        createElementVNode("div", null, [
          createElementVNode("div", null, toDisplayString(props.content.name), 1),
          createElementVNode("div", null, toDisplayString(props.content.size), 1)
        ])
      ], 8, _hoisted_1);
    };
  }
});
export {
  _sfc_main as default
};
