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

'use strict';

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

var iconsVue = require('@ldesign/icons-vue');
var utils = require('../../chunks/utils.js');
var components_loading_index = require('../loading/index.js');
var components_upload_props = require('./props.js');
var utils_mixins = require('../../utils/mixins.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
require('../../chunks/defineProperty-56324511.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('vue');
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/render-node.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/with-install.js');
require('../loading/plugin.js');

var LSingleFile = utils_mixins["default"](components_configProvider_configReceiver["default"]("upload"), components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LUploadSingleFile",
  components: {
    Loading: components_loading_index.Loading
  },

  data() {
    return {};
  },

  props: {
    showUploadProgress: components_upload_props["default"].showUploadProgress,
    file: Object,
    loadingFile: Object,
    remove: Function,
    placeholder: String,
    display: {
      type: String,

      validator(val) {
        return ["file", "file-input"].includes(val);
      }

    },
    fileListDisplay: {
      type: Function
    },
    locale: components_upload_props["default"].locale
  },
  computed: {
    percent() {
      return this.loadingFile && this.loadingFile.percent;
    },

    showPreview() {
      return Boolean(this.file && this.file.name);
    },

    showTextPreview() {
      return this.display === "file";
    },

    showInput() {
      return this.display === "file-input";
    },

    showProgress() {
      return !!(this.loadingFile && this.loadingFile.status === "progress");
    },

    showDelete() {
      return this.file && this.file.name && !this.loadingFile;
    },

    inputName() {
      const fileName = this.file && this.file.name;
      const loadingName = this.loadingFile && this.loadingFile.name;
      return this.showProgress ? loadingName : fileName;
    },

    inputText() {
      return this.inputName || this.placeholder;
    },

    inputTextClass() {
      return [`${this.classPrefix}-input__inner`, {
        [`${this.componentName}__placeholder`]: !this.inputName
      }];
    },

    classes() {
      return [`${this.componentName}__single`, `${this.componentName}__single-${this.display}`];
    }

  },
  methods: {
    renderProgress() {
      const h = this.$createElement;

      if (this.loadingFile.status === "fail") {
        const {
          ErrorCircleFilledIcon
        } = this.useGlobalIcon({
          ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon
        });
        return h(ErrorCircleFilledIcon);
      }

      if (this.showUploadProgress) {
        return h("div", {
          "class": `${this.componentName}__single-progress`
        }, [h(components_loading_index.Loading), h("span", {
          "class": `${this.componentName}__single-percent`
        }, [Math.min(this.loadingFile.percent, 99), "%"])]);
      }
    },

    renderResult() {
      const h = this.$createElement;

      if (!!this.loadingFile && this.loadingFile.status === "fail") {
        const {
          ErrorCircleFilledIcon
        } = this.useGlobalIcon({
          ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon
        });
        return h(ErrorCircleFilledIcon);
      }

      if (this.file && this.file.name && !this.loadingFile) {
        const {
          CheckCircleFilledIcon
        } = this.useGlobalIcon({
          CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon
        });
        return h(CheckCircleFilledIcon);
      }

      return "";
    },

    renderFilePreviewAsText() {
      const h = this.$createElement;
      if (!this.inputName) return;
      const {
        CloseCircleFilledIcon
      } = this.useGlobalIcon({
        CloseCircleFilledIcon: iconsVue.CloseCircleFilledIcon
      });
      return h("div", {
        "class": [`${this.componentName}__single-display-text`, `${this.componentName}__display-text--margin`]
      }, [this.fileListDisplay() || h("span", {
        "class": `${this.componentName}__single-name`
      }, [this.inputName]), this.showProgress ? this.renderProgress() : h(CloseCircleFilledIcon, {
        "class": `${this.componentName}__icon-delete`,
        "nativeOn": {
          "click": e => this.remove({
            e,
            file: this.file
          })
        }
      })]);
    },

    renderFilePreviewAsInput() {
      const h = this.$createElement;
      return h("div", {
        "class": `${this.componentName}__single-input-preview ${this.classPrefix}-input`
      }, [h("div", {
        "class": this.inputTextClass
      }, [h("span", {
        "class": `${this.componentName}__single-input-text`
      }, [utils.abridgeName(this.inputText, 4, 6)]), this.showProgress && this.renderProgress(), this.renderResult()])]);
    }

  },

  render() {
    var _this$locale, _this$locale$triggerU;

    const h = arguments[0];
    return h("div", {
      "class": this.classes
    }, [this.showInput && this.renderFilePreviewAsInput(), this.$scopedSlots.default && this.$scopedSlots.default(null), this.showTextPreview && this.renderFilePreviewAsText(), this.showInput && this.showDelete && h("span", {
      "class": `${this.componentName}__single-input-delete`,
      "on": {
        "click": e => this.remove({
          e,
          file: this.file
        })
      }
    }, [((_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.delete) || this.t(this.global.triggerUploadText.delete)])]);
  }

});

exports["default"] = LSingleFile;
//# sourceMappingURL=single-file.js.map
