import { defineComponent, useSlots, computed, ref, resolveComponent, createBlock, openBlock, mergeProps, toHandlers, unref, withCtx, renderSlot, createElementBlock, normalizeProps, Fragment, createCommentVNode, createVNode } from 'vue';
import { imageViewerEmits, ElIcon } from 'element-plus';
import '../../../../utils/index.mjs';
import '../../../../hooks/index.mjs';
import { imageViewerEmits as imageViewerEmits$1, imageViewerProps } from './imageViewer.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';
import { getGmExports } from '../../../../utils/src/elementPlus/exports.mjs';

var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "GmImageViewer"
  },
  __name: "ImageViewer",
  props: imageViewerProps,
  emits: imageViewerEmits$1,
  setup(__props, { expose: __expose, emit: __emit }) {
    const slots = useSlots();
    const props = __props;
    const emit = __emit;
    const elEvents = getGmEvent(imageViewerEmits, emit);
    const { downloadByUrl } = useDownload();
    const bindProps = computed(() => {
      const { downloadMode, ...rest } = props;
      return rest;
    });
    const download = async (urlOrIndex, filename) => {
      let url;
      if (typeof urlOrIndex === "number") {
        const list = props.urlList;
        url = list?.[urlOrIndex] || "";
      } else {
        url = urlOrIndex;
      }
      if (!url) {
        console.warn("[GmImageViewer] 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 });
      }
    };
    const elRef = ref();
    const exposeNames = ["setActiveItem"];
    const { exposeFns } = getGmExports(elRef, exposeNames);
    __expose({
      ...exposeFns,
      download
    });
    return (_ctx, _cache) => {
      const _component_el_image_viewer = resolveComponent("el-image-viewer");
      return openBlock(), createBlock(
        _component_el_image_viewer,
        mergeProps({
          ref_key: "elRef",
          ref: elRef
        }, bindProps.value, toHandlers(unref(elEvents))),
        {
          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 */
            ))
          ]),
          _: 3
          /* FORWARDED */
        },
        16
        /* FULL_PROPS */
      );
    };
  }
});

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