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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
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-28395935.js');
require('../../chunks/log.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('vue');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/slicedToArray');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/render-node.js');
require('@babel/runtime/helpers/typeof');
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');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

var LSingleFile = utils_mixins["default"](components_configProvider_configReceiver["default"]("upload"), components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LUploadSingleFile",
  components: {
    Loading: components_loading_index.Loading
  },
  data: function data() {
    return {};
  },
  props: {
    showUploadProgress: components_upload_props["default"].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: components_upload_props["default"].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__default["default"]({}, "".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: iconsVue.ErrorCircleFilledIcon
        }),
            ErrorCircleFilledIcon = _this$useGlobalIcon.ErrorCircleFilledIcon;

        return h(ErrorCircleFilledIcon);
      }

      if (this.showUploadProgress) {
        return h("div", {
          "class": "".concat(this.componentName, "__single-progress")
        }, [h(components_loading_index.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: iconsVue.ErrorCircleFilledIcon
        }),
            ErrorCircleFilledIcon = _this$useGlobalIcon2.ErrorCircleFilledIcon;

        return h(ErrorCircleFilledIcon);
      }

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

        return h(CheckCircleFilledIcon);
      }

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

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

      var _this$useGlobalIcon4 = this.useGlobalIcon({
        CloseCircleFilledIcon: iconsVue.CloseCircleFilledIcon
      }),
          CloseCircleFilledIcon = _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, {
        "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")
      }, [utils.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"])])]);
  }
});

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