import { defineComponent, useSlots, computed, resolveComponent, createBlock, openBlock, mergeProps, toHandlers, unref, createSlots, withCtx, renderSlot, createElementBlock, normalizeProps, Fragment, createCommentVNode, createVNode } from 'vue';
import { imageEmits, ElIcon } from 'element-plus';
import '../../../../utils/index.mjs';
import '../../../../hooks/index.mjs';
import { imageEmits as imageEmits$1, imageProps } from './image.mjs';
import { ArrowLeftBold, ArrowRightBold, ZoomOut, ZoomIn, RefreshLeft, RefreshRight, Download } from '@element-plus/icons-vue';
import { getGmEvent } from '../../../../utils/src/elementPlus/event.mjs';
import { useDownload, getUrlFilename } from '../../../../hooks/base/useDownload/index.mjs';

var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "GmImage"
  },
  __name: "Image",
  props: imageProps,
  emits: imageEmits$1,
  setup(__props, { expose: __expose, emit: __emit }) {
    const slots = useSlots();
    const props = __props;
    const emit = __emit;
    const elEvents = getGmEvent(imageEmits, emit);
    const { downloadByUrl } = useDownload();
    const bindProps = 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 || 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 = resolveComponent("el-image");
      return openBlock(), createBlock(
        _component_el_image,
        mergeProps({ ref: "elRef" }, bindProps.value, toHandlers(unref(elEvents))),
        createSlots({
          toolbar: withCtx((toolbarProps) => [
            unref(slots).toolbar ? renderSlot(_ctx.$slots, "toolbar", normalizeProps(mergeProps({ key: 0 }, { ...toolbarProps, download }))) : (openBlock(), createElementBlock(
              Fragment,
              { key: 1 },
              [
                createCommentVNode(" \u9ED8\u8BA4\u5DE5\u5177\u680F\uFF1A\u5F53\u7528\u6237\u672A\u4F20 toolbar slot \u65F6\u663E\u793A "),
                createVNode(unref(ElIcon), {
                  onClick: toolbarProps.prev
                }, {
                  default: withCtx(() => [
                    createVNode(unref(ArrowLeftBold))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                createVNode(unref(ElIcon), {
                  onClick: toolbarProps.next
                }, {
                  default: withCtx(() => [
                    createVNode(unref(ArrowRightBold))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                createVNode(unref(ElIcon), {
                  onClick: ($event) => toolbarProps.actions("zoomOut")
                }, {
                  default: withCtx(() => [
                    createVNode(unref(ZoomOut))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                createVNode(unref(ElIcon), {
                  onClick: ($event) => toolbarProps.actions("zoomIn")
                }, {
                  default: withCtx(() => [
                    createVNode(unref(ZoomIn))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                createVNode(unref(ElIcon), {
                  onClick: ($event) => toolbarProps.actions("anticlockwise")
                }, {
                  default: withCtx(() => [
                    createVNode(unref(RefreshLeft))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                createVNode(unref(ElIcon), {
                  onClick: ($event) => toolbarProps.actions("clockwise")
                }, {
                  default: withCtx(() => [
                    createVNode(unref(RefreshRight))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"]),
                createVNode(unref(ElIcon), {
                  onClick: ($event) => download(toolbarProps.activeIndex)
                }, {
                  default: withCtx(() => [
                    createVNode(unref(Download))
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["onClick"])
              ],
              64
              /* STABLE_FRAGMENT */
            ))
          ]),
          _: 2
          /* DYNAMIC */
        }, [
          unref(slots).placeholder ? {
            name: "placeholder",
            fn: withCtx(() => [
              renderSlot(_ctx.$slots, "placeholder")
            ]),
            key: "0"
          } : void 0,
          unref(slots).error ? {
            name: "error",
            fn: withCtx(() => [
              renderSlot(_ctx.$slots, "error")
            ]),
            key: "1"
          } : void 0,
          unref(slots).viewer ? {
            name: "viewer",
            fn: withCtx(() => [
              renderSlot(_ctx.$slots, "viewer")
            ]),
            key: "2"
          } : void 0
        ]),
        1040
        /* FULL_PROPS, DYNAMIC_SLOTS */
      );
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=Image.vue2.mjs.map
