import { createElementVNode, createTextVNode, defineComponent, useModel, ref, resolveComponent, createElementBlock, openBlock, Fragment, createCommentVNode, createVNode, mergeProps, withCtx, renderSlot, withModifiers, unref, mergeModels } from 'vue';
import { genFileId } from 'element-plus';
import { getGmExports } from '../../../../utils/src/elementPlus/exports.mjs';
import { GmMessage } from '../../plugins/message/index.mjs';
import { Download, UploadFilled } from '@element-plus/icons-vue';
import { importDialogEmits, importDialogProps } from './importDialog.mjs';

const _hoisted_1 = { class: "" };
const _hoisted_2 = { class: "gm-mb-2 gm-bg-[#f5f5f5] gm-p-4" };
const _hoisted_3 = /* @__PURE__ */ createElementVNode(
  "p",
  { class: "gm-mb-3 gm-text-[13px]" },
  "\u4E0B\u8F7D\u5BFC\u5165\u6A21\u677F\uFF0C\u6839\u636E\u6A21\u677F\u63D0\u793A\u5B8C\u5584\u5185\u5BB9",
  -1
  /* HOISTED */
);
const _hoisted_4 = /* @__PURE__ */ createElementVNode(
  "div",
  { class: "el-upload__text" },
  [
    /* @__PURE__ */ createTextVNode("\u5C06\u6587\u4EF6\u62D6\u5230\u6B64\u5904\uFF0C\u6216 "),
    /* @__PURE__ */ createElementVNode("em", null, "\u70B9\u51FB\u4E0A\u4F20")
  ],
  -1
  /* HOISTED */
);
const _hoisted_5 = /* @__PURE__ */ createElementVNode(
  "div",
  { class: "gm-text-[#999]" },
  "\u9650\u52361\u4E2A\u6587\u4EF6\uFF0C\u65B0\u6587\u4EF6\u5C06\u8986\u76D6\u65E7\u6587\u4EF6",
  -1
  /* HOISTED */
);
const _hoisted_6 = { class: "dialog-footer" };
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "GmImportDialog"
  },
  __name: "ImportDialog",
  props: /* @__PURE__ */ mergeModels(importDialogProps, {
    "fileList": { default: () => [] },
    "fileListModifiers": {}
  }),
  emits: /* @__PURE__ */ mergeModels(importDialogEmits, ["update:fileList"]),
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const fileList = useModel(__props, "fileList");
    const uploadRef = ref();
    const handleExceed = (files, uploadFiles) => {
      uploadRef.value.clearFiles();
      const file = files[0];
      file.uid = genFileId();
      uploadRef.value.handleStart(file);
      props.onExceed?.(files, uploadFiles);
    };
    const submitUpload = () => {
      if (fileList.value.length === 0) {
        return GmMessage.error("\u8BF7\u9009\u62E9\u6587\u4EF6");
      }
      uploadRef.value.submit();
      emit("importClick");
    };
    const dialogVisible = ref(false);
    const openDialog = () => {
      dialogVisible.value = true;
    };
    function closeDialog() {
      dialogVisible.value = false;
      reset();
    }
    function reset() {
      fileList.value = [];
      uploadRef.value?.clearFiles();
    }
    const uploadLoading = ref(false);
    const httpRequest = (options) => {
      uploadLoading.value = true;
      return props.httpRequest(options);
    };
    function handleSuccess(response, uploadFile, uploadFiles) {
      uploadLoading.value = false;
      return props.onSuccess(response, uploadFile, uploadFiles);
    }
    const handleError = (error, uploadFile, uploadFiles) => {
      const file = uploadFile.raw;
      if (props.errorReselect && file) {
        file.uid = genFileId();
        uploadRef.value?.handleStart(file);
      }
      uploadLoading.value = false;
      return props.onError(error, uploadFile, uploadFiles);
    };
    const exposeNames = ["abort", "submit", "clearFiles", "handleStart", "handleRemove"];
    const { exposeFns } = getGmExports(uploadRef, exposeNames);
    __expose({
      openDialog,
      closeDialog,
      reset,
      ...exposeFns
    });
    return (_ctx, _cache) => {
      const _component_gm_button = resolveComponent("gm-button");
      const _component_el_icon = resolveComponent("el-icon");
      const _component_gm_upload = resolveComponent("gm-upload");
      const _component_gm_dialog = resolveComponent("gm-dialog");
      return openBlock(), createElementBlock(
        Fragment,
        null,
        [
          createCommentVNode(" \u5BFC\u5165\u5BF9\u8BDD\u6846 "),
          createVNode(_component_gm_dialog, mergeProps(_ctx.dialogProps, {
            modelValue: dialogVisible.value,
            "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => dialogVisible.value = $event)
          }), {
            footer: withCtx(() => [
              createElementVNode("div", _hoisted_6, [
                createVNode(_component_gm_button, {
                  type: "primary",
                  loading: uploadLoading.value,
                  onClick: submitUpload
                }, {
                  default: withCtx(() => [
                    createTextVNode("\u5BFC \u5165")
                  ]),
                  _: 1
                  /* STABLE */
                }, 8, ["loading"]),
                createVNode(_component_gm_button, { onClick: closeDialog }, {
                  default: withCtx(() => [
                    createTextVNode("\u53D6 \u6D88")
                  ]),
                  _: 1
                  /* STABLE */
                })
              ])
            ]),
            default: withCtx(() => [
              createElementVNode("div", _hoisted_1, [
                createElementVNode("div", _hoisted_2, [
                  _hoisted_3,
                  createVNode(_component_gm_button, {
                    icon: unref(Download),
                    onClick: _cache[0] || (_cache[0] = withModifiers(($event) => emit("downloadTemplate"), ["stop"]))
                  }, {
                    default: withCtx(() => [
                      createTextVNode(" \u4E0B\u8F7D\u6A21\u677F ")
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["icon"])
                ]),
                renderSlot(_ctx.$slots, "default"),
                createVNode(_component_gm_upload, {
                  ref_key: "uploadRef",
                  ref: uploadRef,
                  "file-list": fileList.value,
                  "onUpdate:fileList": _cache[1] || (_cache[1] = ($event) => fileList.value = $event),
                  action: "",
                  limit: 1,
                  drag: "",
                  accept: _ctx.accept,
                  "http-request": httpRequest,
                  "on-exceed": handleExceed,
                  "on-success": handleSuccess,
                  "on-error": handleError,
                  "on-remove": _ctx.onRemove,
                  "before-upload": _ctx.beforeUpload,
                  "auto-upload": false,
                  class: "gmUploadEl gm-mb-5"
                }, {
                  default: withCtx(() => [
                    createVNode(_component_el_icon, { class: "el-icon--upload" }, {
                      default: withCtx(() => [
                        createVNode(unref(UploadFilled))
                      ]),
                      _: 1
                      /* STABLE */
                    }),
                    _hoisted_4,
                    _hoisted_5
                  ]),
                  _: 1
                  /* STABLE */
                }, 8, ["file-list", "accept", "on-remove", "before-upload"])
              ])
            ]),
            _: 3
            /* FORWARDED */
          }, 16, ["modelValue"])
        ],
        2112
        /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
      );
    };
  }
});

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