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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { ErrorCircleFilledIcon, CheckCircleFilledIcon, CloseCircleFilledIcon } from 'tdesign-icons-vue';
import { Loading } from '../loading/index.js';
import { abridgeName } from '../_common/js/upload/utils.js';
import props from './props.js';
import mixins from '../utils/mixins.js';
import getConfigReceiverMixins, { getGlobalIconMixins } from '../config-provider/config-receiver.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/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'vue';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.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 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../config.js';

var SingleFile = mixins(getConfigReceiverMixins("upload"), getGlobalIconMixins()).extend({
  name: "TUploadSingleFile",
  components: {
    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);
      }
    },
    fileListDisplay: {
      type: Function
    },
    locale: props.locale
  },
  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(this.classPrefix, "-input__inner"), _defineProperty({}, "".concat(this.componentName, "__placeholder"), !this.inputName)];
    },
    classes: function classes() {
      return ["".concat(this.componentName, "__single"), "".concat(this.componentName, "__single-").concat(this.display)];
    }
  },
  methods: {
    renderProgress: function renderProgress() {
      var h = this.$createElement;

      if (this.loadingFile.status === "fail") {
        var _this$useGlobalIcon = this.useGlobalIcon({
          ErrorCircleFilledIcon: ErrorCircleFilledIcon
        }),
            ErrorCircleFilledIcon$1 = _this$useGlobalIcon.ErrorCircleFilledIcon;

        return h(ErrorCircleFilledIcon$1);
      }

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

      if (!!this.loadingFile && this.loadingFile.status === "fail") {
        var _this$useGlobalIcon2 = this.useGlobalIcon({
          ErrorCircleFilledIcon: ErrorCircleFilledIcon
        }),
            ErrorCircleFilledIcon$1 = _this$useGlobalIcon2.ErrorCircleFilledIcon;

        return h(ErrorCircleFilledIcon$1);
      }

      if (this.file && this.file.name && !this.loadingFile) {
        var _this$useGlobalIcon3 = this.useGlobalIcon({
          CheckCircleFilledIcon: CheckCircleFilledIcon
        }),
            CheckCircleFilledIcon$1 = _this$useGlobalIcon3.CheckCircleFilledIcon;

        return h(CheckCircleFilledIcon$1);
      }

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

      var h = this.$createElement;
      if (!this.inputName) return;

      var _this$useGlobalIcon4 = this.useGlobalIcon({
        CloseCircleFilledIcon: CloseCircleFilledIcon
      }),
          CloseCircleFilledIcon$1 = _this$useGlobalIcon4.CloseCircleFilledIcon;

      return h("div", {
        "class": ["".concat(this.componentName, "__single-display-text"), "".concat(this.componentName, "__display-text--margin")]
      }, [this.fileListDisplay() || h("span", {
        "class": "".concat(this.componentName, "__single-name")
      }, [this.inputName]), this.showProgress ? this.renderProgress() : h(CloseCircleFilledIcon$1, {
        "class": "".concat(this.componentName, "__icon-delete"),
        "nativeOn": {
          "click": function click(e) {
            return _this.remove({
              e: e,
              file: _this.file
            });
          }
        }
      })]);
    },
    renderFilePreviewAsInput: function renderFilePreviewAsInput() {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(this.componentName, "__single-input-preview ").concat(this.classPrefix, "-input")
      }, [h("div", {
        "class": this.inputTextClass
      }, [h("span", {
        "class": "".concat(this.componentName, "__single-input-text")
      }, [abridgeName(this.inputText, 4, 6)]), this.showProgress && this.renderProgress(), this.renderResult()])]);
    }
  },
  render: function render() {
    var _this2 = this,
        _this$locale,
        _this$locale$triggerU;

    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(this.componentName, "__single-input-delete"),
      "on": {
        "click": function click(e) {
          return _this2.remove({
            e: e,
            file: _this2.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"])])]);
  }
});

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