'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var elementPlus = require('element-plus');
require('../../../../utils/index.js');
require('../../../../hooks/index.js');
var image = require('./image.js');
var iconsVue = require('@element-plus/icons-vue');
var event = require('../../../../utils/src/elementPlus/event.js');
var index = require('../../../../hooks/base/useDownload/index.js');

var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "GmImage"
  },
  __name: "Image",
  props: image.imageProps,
  emits: image.imageEmits,
  setup(__props, { expose: __expose, emit: __emit }) {
    const slots = vue.useSlots();
    const props = __props;
    const emit = __emit;
    const elEvents = event.getGmEvent(elementPlus.imageEmits, emit);
    const { downloadByUrl } = index.useDownload();
    const bindProps = vue.computed(() => ({
      ...props,
      showProgress: props.showProgress
    }));
    const download = async (urlOrIndex, filename) => {
      let url;
      if (typeof urlOrIndex === "number") {
        const list = props.previewSrcList;
        url = list?.[urlOrIndex] || "";
      } else {
        url = urlOrIndex;
      }
      if (!url) {
        console.warn("[GmImage] download: \u65E0\u6548\u7684 URL");
        return;
      }
      const finalFilename = filename || index.getUrlFilename(url);
      if (props.downloadMode === "link") {
        window.open(url, "_blank");
      } else {
        await downloadByUrl(url, { filename: finalFilename });
      }
    };
    __expose({
      download
    });
    return (_ctx, _cache) => {
      const _component_el_image = vue.resolveComponent("el-image");
      return vue.openBlock(), vue.createBlock(
        _component_el_image,
        vue.mergeProps({ ref: "elRef" }, bindProps.value, vue.toHandlers(vue.unref(elEvents))),
        vue.createSlots({
          toolbar: vue.withCtx((toolbarProps) => [
            vue.unref(slots).toolbar ? vue.renderSlot(_ctx.$slots, "toolbar", vue.normalizeProps(vue.mergeProps({ key: 0 }, { ...toolbarProps, download }))) : (vue.openBlock(), vue.createElementBlock(
              vue.Fragment,
              { key: 1 },
              [
                vue.createCommentVNode(" \u9ED8\u8BA4\u5DE5\u5177\u680F\uFF1A\u5F53\u7528\u6237\u672A\u4F20 toolbar slot \u65F6\u663E\u793A "),
                vue.createVNode(vue.unref(elementPlus.ElIcon), {
                  onClick: toolbarProps.prev
                }, {
                  default: vue.withCtx(() => [
                    vue.createVNode(vue.unref(iconsVue.ArrowLeftBold))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                vue.createVNode(vue.unref(elementPlus.ElIcon), {
                  onClick: toolbarProps.next
                }, {
                  default: vue.withCtx(() => [
                    vue.createVNode(vue.unref(iconsVue.ArrowRightBold))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                vue.createVNode(vue.unref(elementPlus.ElIcon), {
                  onClick: ($event) => toolbarProps.actions("zoomOut")
                }, {
                  default: vue.withCtx(() => [
                    vue.createVNode(vue.unref(iconsVue.ZoomOut))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                vue.createVNode(vue.unref(elementPlus.ElIcon), {
                  onClick: ($event) => toolbarProps.actions("zoomIn")
                }, {
                  default: vue.withCtx(() => [
                    vue.createVNode(vue.unref(iconsVue.ZoomIn))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                vue.createVNode(vue.unref(elementPlus.ElIcon), {
                  onClick: ($event) => toolbarProps.actions("anticlockwise")
                }, {
                  default: vue.withCtx(() => [
                    vue.createVNode(vue.unref(iconsVue.RefreshLeft))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                vue.createVNode(vue.unref(elementPlus.ElIcon), {
                  onClick: ($event) => toolbarProps.actions("clockwise")
                }, {
                  default: vue.withCtx(() => [
                    vue.createVNode(vue.unref(iconsVue.RefreshRight))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                vue.createVNode(vue.unref(elementPlus.ElIcon), {
                  onClick: ($event) => download(toolbarProps.activeIndex)
                }, {
                  default: vue.withCtx(() => [
                    vue.createVNode(vue.unref(iconsVue.Download))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"])
              ],
              64
              /* STABLE_FRAGMENT */
            ))
          ]),
          _: 2
          /* DYNAMIC */
        }, [
          vue.unref(slots).placeholder ? {
            name: "placeholder",
            fn: vue.withCtx(() => [
              vue.renderSlot(_ctx.$slots, "placeholder")
            ]),
            key: "0"
          } : void 0,
          vue.unref(slots).error ? {
            name: "error",
            fn: vue.withCtx(() => [
              vue.renderSlot(_ctx.$slots, "error")
            ]),
            key: "1"
          } : void 0,
          vue.unref(slots).viewer ? {
            name: "viewer",
            fn: vue.withCtx(() => [
              vue.renderSlot(_ctx.$slots, "viewer")
            ]),
            key: "2"
          } : void 0
        ]),
        1040
        /* FULL_PROPS, DYNAMIC_SLOTS */
      );
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=Image.vue2.js.map
