/**
 * ldesign v0.2.3
 * (c) 2022年9月24日 swimly
 * @license MIT
 */

'use strict';

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

var findIndex = require('lodash/findIndex');
var isFunction = require('lodash/isFunction');
var without = require('lodash/without');
var iconsVue = require('@ldesign/icons-vue');
var defineProperty56324511 = require('../../chunks/defineProperty-56324511.js');
var log = require('../../chunks/log.js');
var utils = require('../../chunks/utils.js');
var utils_mixins = require('../../utils/mixins.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var components_upload_dragger = require('./dragger.js');
var components_upload_image = require('./image.js');
var components_upload_flowList = require('./flow-list.js');
var components_button_index = require('../button/index.js');
var components_dialog_index = require('../dialog/index.js');
var components_upload_singleFile = require('./single-file.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_upload_props = require('./props.js');
var utils_event = require('../../utils/event.js');
require('vue');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/with-install.js');
require('../loading/plugin.js');
require('../button/button.js');
require('../button/props.js');
require('../../utils/ripple.js');
require('../dialog/dialog.js');
require('lodash/isNumber');
require('lodash/throttle');
require('../dialog/mixins/action.js');
require('../../chunks/helper.js');
require('lodash/isObject');
require('../dialog/props.js');
require('../../hooks/use-destroy-onclose.js');
require('../dialog/stack.js');
require('../../utils/helper.js');
require('../dialog/plugin.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var findIndex__default = /*#__PURE__*/_interopDefaultLegacy(findIndex);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
var without__default = /*#__PURE__*/_interopDefaultLegacy(without);

/**
 * LDesignUtility v0.2.1
 * (c) 2022 undefined
 * @license MIT
 */

function ownKeys(object, enumerableOnly) {
  var keys = Object.keys(object);

  if (Object.getOwnPropertySymbols) {
    var symbols = Object.getOwnPropertySymbols(object);
    enumerableOnly && (symbols = symbols.filter(function (sym) {
      return Object.getOwnPropertyDescriptor(object, sym).enumerable;
    })), keys.push.apply(keys, symbols);
  }

  return keys;
}

function _objectSpread(target) {
  for (var i = 1; i < arguments.length; i++) {
    var source = null != arguments[i] ? arguments[i] : {};
    i % 2 ? ownKeys(Object(source), true).forEach(function (key) {
      defineProperty56324511._defineProperty(target, key, source[key]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
      Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
    });
  }

  return target;
}

function xhr(_ref) {
  var {
    method = "POST",
    action,
    withCredentials = false,
    headers = {},
    data = {},
    file,
    files = [],
    name = "file",
    useMockProgress = true,
    formatRequest,
    onError,
    onProgress,
    onSuccess
  } = _ref;
  var innerFiles = files || [];
  var percent = 0;
  var xhr2 = new XMLHttpRequest();

  if (withCredentials) {
    xhr2.withCredentials = true;
  }

  var timer1;
  var timer2;

  if (useMockProgress && files[0].status === "progress") {
    var timer22 = setTimeout(() => {
      timer1 = setInterval(() => {
        if (!percent && percent < 100) {
          percent += 10;
          onProgress({
            percent,
            file,
            files: innerFiles.map(file2 => _objectSpread(_objectSpread({}, file2), {}, {
              percent
            })),
            type: "mock"
          });
        } else {
          clearInterval(timer1);
        }
      }, 300);
      clearTimeout(timer22);
    }, 300);
  }

  var requestData = {};

  if (data) {
    var extraData = typeof data === "function" ? data(file) : data;
    Object.assign(requestData, extraData);
  }

  innerFiles.forEach((file2, index) => {
    var fileField = innerFiles.length > 1 ? "".concat(name, "[").concat(index, "]") : name;
    requestData[fileField] = file2.raw;
    requestData[name] = file2.raw;
  });

  if (formatRequest) {
    requestData = formatRequest(requestData);
  }

  var formData = new FormData();
  Object.keys(requestData).forEach(key => {
    formData.append(key, requestData[key]);
  });
  xhr2.open(method, action, true);
  Object.keys(headers).forEach(key => {
    xhr2.setRequestHeader(key, headers[key]);
  });

  xhr2.onerror = event => {
    onError({
      event,
      file,
      files: innerFiles
    });
    clearInterval(timer1);
    clearTimeout(timer2);
  };

  if (xhr2.upload) {
    xhr2.upload.onprogress = event => {
      var realPercent = 0;

      if (event.total > 0) {
        realPercent = Math.round(event.loaded / event.total * 100);
      }

      percent = Math.max(realPercent, percent);
      onProgress({
        event,
        percent,
        file,
        files: innerFiles.map(file2 => _objectSpread(_objectSpread({}, file2), {}, {
          percent
        })),
        type: "real"
      });
    };
  }

  xhr2.onload = event => {
    var response;
    var isFail = xhr2.status < 200 || xhr2.status >= 300;

    if (isFail) {
      return onError({
        event,
        file,
        files: innerFiles,
        response
      });
    }

    var text = xhr2.responseText || xhr2.response;

    try {
      response = JSON.parse(text);
    } catch (e) {
      response = text;
    }

    clearInterval(timer1);
    clearTimeout(timer2);
    onSuccess({
      event,
      file,
      files: innerFiles,
      response
    });
  };

  xhr2.send(formData);
  return xhr2;
}

var _Upload = utils_mixins["default"](components_configProvider_configReceiver["default"]("upload"), components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LUpload",
  components: {
    LDragger: components_upload_dragger["default"],
    LSingleFile: components_upload_singleFile["default"],
    LImageCard: components_upload_image["default"],
    LFlowList: components_upload_flowList["default"],
    LDialog: components_dialog_index.Dialog,
    LButton: components_button_index.Button
  },
  model: {
    prop: "files",
    event: "change"
  },
  props: { ...components_upload_props["default"]
  },

  data() {
    return {
      formDisabled: void 0,
      dragActive: false,
      loadingFile: null,
      toUploadFiles: [],
      errorMsg: "",
      showImageViewDialog: false,
      showImageViewUrl: "",
      xhrReq: null
    };
  },

  computed: {
    isSingleRequest() {
      return !this.multiple || this.isBatchUpload;
    },

    tDisabled() {
      return this.formDisabled || this.disabled;
    },

    showTips() {
      if (this.theme === "file") {
        const hasNoFile = (!this.files || !this.files.length) && !this.loadingFile;
        return this.tips && hasNoFile;
      }

      return Boolean(this.tips);
    },

    showCustomDisplay() {
      return this.theme === "custom";
    },

    showSingleDisplay() {
      return !this.draggable && ["file", "file-input"].includes(this.theme);
    },

    showImgCard() {
      return !this.draggable && this.theme === "image";
    },

    singleDraggable() {
      return !this.multiple && this.draggable && ["file", "file-input", "image"].includes(this.theme);
    },

    showUploadList() {
      return this.multiple && ["file-flow", "image-flow"].includes(this.theme);
    },

    showImgDialog() {
      return ["image", "image-flow", "custom"].includes(this.theme);
    },

    showErrorMsg() {
      return !!this.errorMsg;
    },

    tipsClasses() {
      return [`${this.componentName}__tips`, `${this.classPrefix}-size-s`];
    },

    errorClasses() {
      return this.tipsClasses.concat(`${this.componentName}__tips-error`);
    },

    uploadInOneRequest() {
      return this.multiple && this.uploadAllFilesInOneRequest;
    },

    canBatchUpload() {
      return this.uploadInOneRequest && this.isBatchUpload;
    },

    uploadListTriggerText() {
      var _this$locale, _this$locale$triggerU, _this$toUploadFiles, _this$files;

      let uploadText = ((_this$locale = this.locale) === null || _this$locale === void 0 ? void 0 : (_this$locale$triggerU = _this$locale.triggerUploadText) === null || _this$locale$triggerU === void 0 ? void 0 : _this$locale$triggerU.fileInput) || this.global.triggerUploadText.fileInput;

      if (((_this$toUploadFiles = this.toUploadFiles) === null || _this$toUploadFiles === void 0 ? void 0 : _this$toUploadFiles.length) > 0 || ((_this$files = this.files) === null || _this$files === void 0 ? void 0 : _this$files.length) > 0) {
        var _this$files2;

        if (this.theme === "file-input" || ((_this$files2 = this.files) === null || _this$files2 === void 0 ? void 0 : _this$files2.length) > 0 && this.canBatchUpload) {
          var _this$locale2, _this$locale2$trigger;

          uploadText = ((_this$locale2 = this.locale) === null || _this$locale2 === void 0 ? void 0 : (_this$locale2$trigger = _this$locale2.triggerUploadText) === null || _this$locale2$trigger === void 0 ? void 0 : _this$locale2$trigger.reupload) || this.global.triggerUploadText.reupload;
        } else {
          var _this$locale3, _this$locale3$trigger;

          uploadText = ((_this$locale3 = this.locale) === null || _this$locale3 === void 0 ? void 0 : (_this$locale3$trigger = _this$locale3.triggerUploadText) === null || _this$locale3$trigger === void 0 ? void 0 : _this$locale3$trigger.continueUpload) || this.global.triggerUploadText.continueUpload;
        }
      }

      return uploadText;
    }

  },
  methods: {
    emitChangeEvent(files, ctx) {
      utils_event.emitEvent(this, "change", files, ctx);
    },

    emitRemoveEvent(ctx) {
      utils_event.emitEvent(this, "remove", ctx);
    },

    handlePreviewImg(event, file) {
      if (!file || !file.url) return log.log.error("Uploader", "Preview Error file");
      this.showImageViewUrl = file.url;
      this.showImageViewDialog = true;
      const previewCtx = {
        file,
        e: event
      };
      utils_event.emitEvent(this, "preview", previewCtx);
    },

    handleChange(event) {
      const {
        files
      } = event.target;
      if (this.tDisabled) return;
      this.uploadFiles(files);
      utils_event.emitEvent(this, "select-change", utils.formatFiles(Array.from(files), this.format));
      this.$refs.input.value = "";
    },

    handleDragChange(files) {
      if (this.tDisabled) return;
      this.uploadFiles(files);
      utils_event.emitEvent(this, "select-change", utils.formatFiles(Array.from(files), this.format));
    },

    handleSingleRemove(_ref) {
      let {
        e,
        file
      } = _ref;
      const changeCtx = {
        trigger: "remove"
      };
      if (this.loadingFile) this.loadingFile = null;
      this.errorMsg = "";
      this.emitChangeEvent([], changeCtx);
      this.emitRemoveEvent({
        e,
        file
      });
    },

    handleMultipleRemove(options) {
      const changeCtx = {
        trigger: "remove",
        ...options
      };
      let files;

      if (!this.canBatchUpload) {
        files = this.files.concat();
        files.splice(options.index, 1);
      } else {
        files = [];
        options.files = this.files.concat();
      }

      this.emitChangeEvent(files, changeCtx);
      this.emitRemoveEvent(options);
    },

    handleListRemove(context) {
      const {
        file,
        e
      } = context;
      const index = findIndex__default["default"](this.toUploadFiles, o => o.name === (file === null || file === void 0 ? void 0 : file.name));

      if (index >= 0) {
        this.toUploadFiles.splice(index, 1);
        this.emitRemoveEvent({
          e,
          file,
          index
        });
      } else {
        const index2 = findIndex__default["default"](this.files, o => o.name === (file === null || file === void 0 ? void 0 : file.name));
        this.handleMultipleRemove({
          e,
          index: index2,
          file
        });
      }
    },

    uploadFiles(files) {
      var _this$files3;

      if (this.canBatchUpload && ((_this$files3 = this.files) === null || _this$files3 === void 0 ? void 0 : _this$files3.length) > 0) {
        const context = {
          trigger: "batch-clear"
        };
        this.emitChangeEvent([], context);
      }

      let tmpFiles = [...files];

      if (this.max) {
        tmpFiles = tmpFiles.slice(0, this.max - this.toUploadFiles.length - this.files.length);

        if (tmpFiles.length !== files.length) {
          console.warn(`TDesign Upload Warn: you can only upload ${this.max} files`);
        }
      }

      tmpFiles.forEach(fileRaw => {
        let file = fileRaw;

        if (typeof this.format === "function") {
          file = this.format(fileRaw);
        }

        const uploadFile = {
          raw: fileRaw,
          lastModified: fileRaw.lastModified,
          name: fileRaw.name,
          size: fileRaw.size,
          type: fileRaw.type,
          percent: 0,
          status: "waiting",
          ...file
        };
        const reader = new FileReader();
        reader.readAsDataURL(fileRaw);

        reader.onload = event => {
          uploadFile.url = event.target.result;
        };

        this.handleBeforeUpload(file).then(canUpload => {
          if (!canUpload) return;
          const newFiles = this.toUploadFiles.concat();

          if (this.allowUploadDuplicateFile || !this.toUploadFiles.find(file2 => file2.name === uploadFile.name)) {
            newFiles.push(uploadFile);
          }

          this.toUploadFiles = newFiles;
          this.loadingFile = uploadFile;

          if (this.autoUpload) {
            this.upload(uploadFile);
          }
        });
      });
    },

    async upload(currentFiles, index) {
      const innerFiles = Array.isArray(currentFiles) ? currentFiles : [currentFiles];

      if (!this.action && !this.requestMethod) {
        console.error("TDesign Upload Error: one of action and requestMethod must be exist.");
        return;
      }

      this.errorMsg = "";
      innerFiles.forEach(file => {
        file.status = "progress";
        this.loadingFile = file;
      });

      if (this.requestMethod) {
        this.handleRequestMethod(innerFiles);
      } else {
        if (this.useMockProgress) {
          this.handleMockProgress(innerFiles);
        }

        const request = xhr;
        const currentXhr = request({
          method: this.method,
          action: this.action,
          data: this.data,
          files: innerFiles,
          name: this.name,
          headers: this.headers,
          withCredentials: this.withCredentials,
          onError: this.onError,
          onProgress: this.handleProgress,
          onSuccess: this.handleSuccess
        });

        if (this.isSingleRequest) {
          this.xhrReq = currentXhr;
        } else if (typeof index === "number") this.toUploadFiles[index].xhr = currentXhr;
      }
    },

    handleMockProgress(files) {
      const timer = setInterval(() => {
        files.forEach(file => {
          if (file.status === "success" || file.percent >= 99) {
            clearInterval(timer);
            return;
          }

          file.percent += 1;
        });
        const {
          percent
        } = files[0];
        this.handleProgress({
          files,
          percent,
          type: "mock"
        });
      }, 10);
    },

    handleRequestMethod(files) {
      if (!isFunction__default["default"](this.requestMethod)) {
        console.warn("TDesign Upload Warn: `requestMethod` must be a function.");
        return;
      }

      const requestMethodParam = this.uploadInOneRequest ? files : files[0];
      this.requestMethod(requestMethodParam).then(res => {
        if (!this.handleRequestMethodResponse(res)) return;

        if (res.status === "success") {
          this.handleSuccess({
            files,
            response: res.response
          });
        } else if (res.status === "fail") {
          const r = res.response || {};
          this.onError({
            file: this.uploadInOneRequest ? null : files[0],
            files,
            response: { ...r,
              error: res.error
            }
          });
        }
      });
    },

    handleRequestMethodResponse(res) {
      if (!res) {
        console.error("TDesign Upload Error: `requestMethodResponse` is required.");
        return false;
      }

      if (!res.status) {
        console.error("TDesign Upload Error: `requestMethodResponse.status` is missing, which value is `success` or `fail`");
        return false;
      }

      if (!["success", "fail"].includes(res.status)) {
        console.error("TDesign Upload Error: `requestMethodResponse.status` must be `success` or `fail`");
        return false;
      }

      if (res.status === "success" && (!res.response || !res.response.url)) {
        console.warn("TDesign Upload Warn: `requestMethodResponse.response.url` is required, when `status` is `success`");
      }

      return true;
    },

    multipleUpload(currentFiles) {
      if (this.uploadAllFilesInOneRequest) {
        this.upload(currentFiles);
      } else {
        currentFiles.forEach((file, index) => {
          this.upload(file, index);
        });
      }
    },

    onError(options) {
      var _res;

      const {
        event,
        file,
        files,
        response,
        resFormatted
      } = options;
      const innerFiles = Array.isArray(files) ? files : [file];
      innerFiles.forEach(file2 => {
        file2.status = "fail";
        this.loadingFile = file2;
      });
      let res = response;

      if (!resFormatted && typeof this.formatResponse === "function") {
        res = this.formatResponse(response, {
          file,
          currentFiles: files
        });
      }

      this.errorMsg = (_res = res) === null || _res === void 0 ? void 0 : _res.error;
      const context = {
        e: event,
        file: this.uploadInOneRequest ? null : innerFiles[0],
        currentFiles: innerFiles
      };
      utils_event.emitEvent(this, "fail", context);
    },

    handleProgress(_ref2) {
      let {
        event,
        file,
        files: currentFiles,
        percent,
        type = "real"
      } = _ref2;
      const innerFiles = Array.isArray(currentFiles) ? currentFiles : [file];
      if ((innerFiles === null || innerFiles === void 0 ? void 0 : innerFiles.length) <= 0) return log.log.error("Uploader", "Progress Error files");
      innerFiles.forEach(file2 => {
        file2.percent = Math.min(percent, 100);
        this.loadingFile = file2.status === "success" ? null : file2;
      });
      const progressCtx = {
        percent,
        e: event,
        file,
        type,
        currentFiles: innerFiles
      };
      utils_event.emitEvent(this, "progress", progressCtx);
    },

    handleSuccess(_ref3) {
      var _res2;

      let {
        event,
        file,
        files: currentFiles,
        response
      } = _ref3;
      const innerFiles = Array.isArray(currentFiles) ? currentFiles : [file];
      if ((innerFiles === null || innerFiles === void 0 ? void 0 : innerFiles.length) <= 0) return log.log.error("Uploader", "success no files");
      innerFiles.forEach(file2 => {
        file2.status = "success";
      });
      let res = response;

      if (typeof this.formatResponse === "function") {
        res = this.formatResponse(response, {
          file: this.uploadInOneRequest ? null : innerFiles[0],
          currentFiles: innerFiles
        });
      }

      if ((_res2 = res) !== null && _res2 !== void 0 && _res2.error) {
        this.onError({
          event,
          file: this.uploadInOneRequest ? null : innerFiles[0],
          files: innerFiles,
          response: res,
          resFormatted: true
        });
        return;
      }

      if (!this.uploadInOneRequest) {
        innerFiles[0].url = res.url || innerFiles[0].url;
      }

      this.toUploadFiles = without__default["default"](this.toUploadFiles, ...innerFiles);
      const newFiles = innerFiles.map(file2 => ({ ...file2,
        response: res
      }));
      this.multiple && this.files.push(...newFiles);
      const uploadedFiles = this.multiple ? this.files : newFiles;
      const context = {
        e: event,
        response: res,
        trigger: "upload-success"
      };
      this.emitChangeEvent(uploadedFiles, context);
      const sContext = {
        file: this.uploadInOneRequest ? null : newFiles[0],
        fileList: uploadedFiles,
        currentFiles: newFiles,
        e: event,
        response: res
      };
      utils_event.emitEvent(this, "success", sContext);
      this.loadingFile = null;
    },

    handlePreview(_ref4) {
      let {
        file,
        event
      } = _ref4;
      return {
        file,
        event
      };
    },

    triggerUpload() {
      if (this.tDisabled) return;
      this.$refs.input.click();
    },

    handleDragenter(e) {
      if (this.tDisabled) return;
      this.dragActive = true;
      utils_event.emitEvent(this, "dragenter", {
        e
      });
    },

    handleDragleave(e) {
      if (this.tDisabled) return;
      this.dragActive = false;
      utils_event.emitEvent(this, "dragleave", {
        e
      });
    },

    handleBeforeUpload(file) {
      if (typeof this.beforeUpload === "function") {
        const r = this.beforeUpload(file);
        if (r instanceof Promise) return r;
        return new Promise(resolve => resolve(r));
      }

      return new Promise(resolve => {
        if (this.sizeLimit) {
          resolve(this.handleSizeLimit(file.size));
        }

        resolve(true);
      });
    },

    handleSizeLimit(fileSize) {
      const sizeLimit = typeof this.sizeLimit === "number" ? {
        size: this.sizeLimit,
        unit: "KB"
      } : this.sizeLimit;
      const rSize = utils.isOverSizeLimit1(fileSize, sizeLimit.size, sizeLimit.unit);

      if (!rSize) {
        this.errorMsg = sizeLimit.message ? this.t(sizeLimit.message, {
          sizeLimit: sizeLimit.size
        }) : `${this.t(this.global.sizeLimitMessage, {
          sizeLimit: sizeLimit.size
        })} ${sizeLimit.unit}`;
      }

      return rSize;
    },

    cancelUpload() {
      if (this.loadingFile) {
        if (!this.requestMethod) {
          var _this$xhrReq, _this$xhrReq$abort;

          this.isSingleRequest && ((_this$xhrReq = this.xhrReq) === null || _this$xhrReq === void 0 ? void 0 : (_this$xhrReq$abort = _this$xhrReq.abort) === null || _this$xhrReq$abort === void 0 ? void 0 : _this$xhrReq$abort.call(_this$xhrReq));
          this.multiple && this.toUploadFiles.forEach(file => {
            if (file.status === "progress") {
              !this.isBatchUpload && file.xhr.abort();
              file.status = "waiting";
            }
          });
        }

        utils_event.emitEvent(this, "cancel-upload");
        this.loadingFile = null;
      }

      this.$refs.input.value = "";
    },

    cancelPreviewImgDialog() {
      this.showImageViewDialog = false;
      let timer = setTimeout(() => {
        this.showImageViewUrl = "";
        clearTimeout(timer);
        timer = null;
      }, 500);
    },

    getDefaultTrigger() {
      var _this$locale4, _this$locale4$trigger, _this$locale5, _this$locale5$trigger, _this$files4;

      const h = this.$createElement;

      if (this.theme === "file-input" || this.showUploadList) {
        return h("l-button", {
          "attrs": {
            "variant": "outline"
          }
        }, [this.uploadListTriggerText]);
      }

      const {
        UploadIcon
      } = this.useGlobalIcon({
        UploadIcon: iconsVue.UploadIcon
      });
      const reuploadText = ((_this$locale4 = this.locale) === null || _this$locale4 === void 0 ? void 0 : (_this$locale4$trigger = _this$locale4.triggerUploadText) === null || _this$locale4$trigger === void 0 ? void 0 : _this$locale4$trigger.reupload) || this.global.triggerUploadText.reupload;
      const normalText = ((_this$locale5 = this.locale) === null || _this$locale5 === void 0 ? void 0 : (_this$locale5$trigger = _this$locale5.triggerUploadText) === null || _this$locale5$trigger === void 0 ? void 0 : _this$locale5$trigger.normal) || this.global.triggerUploadText.normal;
      return h("l-button", {
        "attrs": {
          "variant": "outline"
        }
      }, [h(UploadIcon, {
        "slot": "icon"
      }), (_this$files4 = this.files) !== null && _this$files4 !== void 0 && _this$files4.length ? reuploadText : normalText]);
    },

    renderFileListDisplay() {
      const fileListDisplay = utils_renderNode.renderLNodeJSX(this, "fileListDisplay");
      return fileListDisplay;
    },

    renderInput() {
      const h = this.$createElement;
      return h("input", {
        "ref": "input",
        "attrs": {
          "type": "file",
          "disabled": this.tDisabled,
          "multiple": this.multiple,
          "accept": this.accept,
          "hidden": true
        },
        "on": {
          "change": this.handleChange
        }
      });
    },

    renderSingleDisplay(triggerElement) {
      const h = this.$createElement;
      return h("l-single-file", {
        "attrs": {
          "file": this.files && this.files[0],
          "loadingFile": this.loadingFile,
          "display": this.theme,
          "remove": this.handleSingleRemove,
          "showUploadProgress": this.showUploadProgress,
          "placeholder": this.placeholder,
          "fileListDisplay": this.renderFileListDisplay,
          "locale": this.locale
        }
      }, [h("div", {
        "class": `${this.componentName}__trigger`,
        "on": {
          "click": this.triggerUpload
        }
      }, [triggerElement])]);
    },

    renderDraggerTrigger() {
      const h = this.$createElement;
      const params = {
        dragActive: this.dragActive,
        uploadingFile: this.multiple ? this.toUploadFiles : this.loadingFile
      };
      const triggerElement = utils_renderNode.renderContent(this, "default", "trigger", {
        params
      });
      return h("l-dragger", {
        "attrs": {
          "showUploadProgress": this.showUploadProgress,
          "loadingFile": this.loadingFile,
          "file": this.files && this.files[0],
          "display": this.theme,
          "cancel": this.cancelUpload,
          "trigger": this.triggerUpload,
          "remove": this.handleSingleRemove,
          "upload": this.upload,
          "autoUpload": this.autoUpload,
          "locale": this.locale
        },
        "on": {
          "change": this.handleDragChange,
          "dragenter": this.handleDragenter,
          "dragleave": this.handleDragleave
        }
      }, [triggerElement]);
    },

    renderTrigger() {
      const defaultNode = this.getDefaultTrigger();
      return utils_renderNode.renderContent(this, "default", "trigger", defaultNode);
    },

    renderCustom(triggerElement) {
      const h = this.$createElement;
      return this.draggable ? this.renderDraggerTrigger() : h("div", {
        "class": `${this.componentName}__trigger`,
        "on": {
          "click": this.triggerUpload
        }
      }, [triggerElement]);
    }

  },

  render() {
    const h = arguments[0];
    const triggerElement = this.renderTrigger();
    return h("div", {
      "class": this.componentName
    }, [this.renderInput(), this.showCustomDisplay && this.renderCustom(triggerElement), this.showSingleDisplay && this.renderSingleDisplay(triggerElement), this.singleDraggable && this.renderDraggerTrigger(), this.showImgCard && h("l-image-card", {
      "attrs": {
        "files": this.files,
        "multiple": this.multiple,
        "remove": this.handleMultipleRemove,
        "trigger": this.triggerUpload,
        "loadingFile": this.loadingFile,
        "toUploadFiles": this.toUploadFiles,
        "max": this.max,
        "disabled": this.tDisabled,
        "locale": this.locale
      },
      "on": {
        "imgPreview": this.handlePreviewImg
      }
    }), this.showUploadList && h("l-flow-list", {
      "attrs": {
        "files": this.files,
        "disabled": this.tDisabled,
        "placeholder": this.placeholder,
        "autoUpload": this.autoUpload,
        "toUploadFiles": this.toUploadFiles,
        "remove": this.handleListRemove,
        "showUploadProgress": this.showUploadProgress,
        "allowUploadDuplicateFile": this.allowUploadDuplicateFile,
        "upload": this.multipleUpload,
        "cancel": this.cancelUpload,
        "display": this.theme,
        "batchUpload": this.canBatchUpload,
        "locale": this.locale
      },
      "on": {
        "imgPreview": this.handlePreviewImg,
        "change": this.handleDragChange,
        "dragenter": this.handleDragenter,
        "dragleave": this.handleDragleave
      }
    }, [h("div", {
      "class": `${this.componentName}__trigger`,
      "on": {
        "click": this.triggerUpload
      }
    }, [triggerElement])]), this.showImgDialog && h("l-dialog", {
      "attrs": {
        "visible": this.showImageViewDialog,
        "showOverlay": true,
        "width": "auto",
        "top": "10%",
        "footer": false,
        "header": false
      },
      "class": `${this.componentName}__dialog`,
      "on": {
        "close": this.cancelPreviewImgDialog
      }
    }, [h("div", {
      "class": `${this.classPrefix}__dialog-body-img-box`
    }, [h("img", {
      "attrs": {
        "src": this.showImageViewUrl,
        "alt": ""
      }
    })])]), !this.errorMsg && this.showTips && h("small", {
      "class": this.tipsClasses
    }, [this.tips]), this.showErrorMsg && h("small", {
      "class": this.errorClasses
    }, [this.errorMsg])]);
  }

});

exports["default"] = _Upload;
//# sourceMappingURL=upload.js.map
