/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { CloseCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon } from 'tdesign-icons-vue';
import { Loading } from '../loading/index.js';
import { prefix } from '../config.js';
import { UPLOAD_NAME, abridgeName } from './util.js';
import props from './props.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../utils/set-style.js';
import '../utils/classnames.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';

var SingleFile = Vue.extend({
  name: "TUploadSingleFile",
  components: {
    TIconClearCircleFilled: CloseCircleFilledIcon,
    TIconCheckCircleFilled: CheckCircleFilledIcon,
    TIconErrorCircleFilled: ErrorCircleFilledIcon,
    Loading: Loading
  },
  data: function data() {
    return {};
  },
  props: {
    showUploadProgress: props.showUploadProgress,
    file: Object,
    loadingFile: Object,
    remove: Function,
    placeholder: String,
    display: {
      type: String,
      validator: function validator(val) {
        return ["file", "file-input"].includes(val);
      }
    }
  },
  computed: {
    percent: function percent() {
      return this.loadingFile && this.loadingFile.percent;
    },
    showPreview: function showPreview() {
      return Boolean(this.file && this.file.name);
    },
    showTextPreview: function showTextPreview() {
      return this.display === "file";
    },
    showInput: function showInput() {
      return this.display === "file-input";
    },
    showProgress: function showProgress() {
      return !!(this.loadingFile && this.loadingFile.status === "progress");
    },
    showDelete: function showDelete() {
      return this.file && this.file.name && !this.loadingFile;
    },
    inputName: function inputName() {
      var fileName = this.file && this.file.name;
      var loadingName = this.loadingFile && this.loadingFile.name;
      return this.showProgress ? loadingName : fileName;
    },
    inputText: function inputText() {
      return this.inputName || this.placeholder;
    },
    inputTextClass: function inputTextClass() {
      return ["".concat(prefix, "-input__inner"), _defineProperty({}, "".concat(UPLOAD_NAME, "__placeholder"), !this.inputName)];
    },
    classes: function classes() {
      return ["".concat(UPLOAD_NAME, "__single"), "".concat(UPLOAD_NAME, "__single-").concat(this.display)];
    }
  },
  methods: {
    renderProgress: function renderProgress() {
      var h = this.$createElement;

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

      if (this.showUploadProgress) {
        return h("div", {
          "class": "".concat(UPLOAD_NAME, "__single-progress")
        }, [h(Loading), h("span", {
          "class": "".concat(UPLOAD_NAME, "__single-percent")
        }, [Math.min(this.loadingFile.percent, 99), "%"])]);
      }
    },
    renderResult: function renderResult() {
      var h = this.$createElement;

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

      if (this.file && this.file.name && !this.loadingFile) {
        return h(CheckCircleFilledIcon);
      }

      return "";
    },
    renderFilePreviewAsText: function renderFilePreviewAsText() {
      var _this = this;

      var h = this.$createElement;
      if (!this.inputName) return;
      return h("div", {
        "class": "".concat(UPLOAD_NAME, "__single-display-text t-upload__display-text--margin")
      }, [h("span", {
        "class": "".concat(UPLOAD_NAME, "__single-name")
      }, [this.inputName]), this.showProgress ? this.renderProgress() : h(CloseCircleFilledIcon, {
        "class": "".concat(UPLOAD_NAME, "__icon-delete"),
        "nativeOn": {
          "click": function click(e) {
            return _this.remove(e);
          }
        }
      })]);
    },
    renderFilePreviewAsInput: function renderFilePreviewAsInput() {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(UPLOAD_NAME, "__single-input-preview ").concat(prefix, "-input")
      }, [h("div", {
        "class": this.inputTextClass
      }, [h("span", {
        "class": "".concat(UPLOAD_NAME, "__single-input-text")
      }, [abridgeName(this.inputText, 4, 6)]), this.showProgress && this.renderProgress(), this.renderResult()])]);
    }
  },
  render: function render() {
    var _this2 = this;

    var 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": "".concat(UPLOAD_NAME, "__single-input-delete"),
      "on": {
        "click": function click(e) {
          return _this2.remove(e);
        }
      }
    }, ["\u5220\u9664"])]);
  }
});

export { SingleFile as default };
//# sourceMappingURL=single-file.js.map
