/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

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

var uploadName = "".concat(prefix, "-upload");
var SingleFile = Vue.extend({
  name: "TUploadSingleFile",
  components: {
    CloseCircleFilledIcon: CloseCircleFilledIcon,
    ErrorCircleFilledIcon: ErrorCircleFilledIcon,
    CheckCircleFilledIcon: CheckCircleFilledIcon,
    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(uploadName, "__placeholder"), !this.inputName)];
    },
    classes: function classes() {
      return ["".concat(uploadName, "__single"), "".concat(uploadName, "__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(uploadName, "__single-progress")
        }, [h(Loading), h("span", {
          "class": "".concat(uploadName, "__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;
      var fileListDisplay = renderTNodeJSX(this, "fileListDisplay");
      return h("div", {
        "class": ["".concat(uploadName, "__single-display-text"), "".concat(uploadName, "__display-text--margin")]
      }, [fileListDisplay || h("span", {
        "class": "".concat(uploadName, "__single-name")
      }, [this.inputName]), this.showProgress ? this.renderProgress() : h(CloseCircleFilledIcon, {
        "class": "".concat(uploadName, "__icon-delete"),
        "nativeOn": {
          "click": function click(e) {
            return _this.remove(e);
          }
        }
      })]);
    },
    renderFilePreviewAsInput: function renderFilePreviewAsInput() {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(uploadName, "__single-input-preview ").concat(prefix, "-input")
      }, [h("div", {
        "class": this.inputTextClass
      }, [h("span", {
        "class": "".concat(uploadName, "__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(uploadName, "__single-input-delete"),
      "on": {
        "click": function click(e) {
          return _this2.remove(e);
        }
      }
    }, ["\u5220\u9664"])]);
  }
});

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