/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var utils = require('../../../chunks/utils2.js');
var components_loading_index = require('../../loading/index.js');
var components_link_index = require('../../link/index.js');
var utils_renderNode = require('../../../utils/render-node.js');
var hooks_useGlobalIcon = require('../../../hooks/use-global-icon.js');
var components_upload_const = require('../const.js');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../utils/with-install.js');
require('vue');
require('lodash');
require('../../../config.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../../utils/mixins.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-838e4192.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');
require('../../link/link.js');
require('../../link/props.js');
require('../../config-provider/useConfig.js');

const NormalFile = VueCompositionAPI.defineComponent({
  name: "UploadNormalFile",
  props: {
    multiple: Boolean,
    ...components_upload_const.commonProps
  },
  setup(props) {
    const icons = hooks_useGlobalIcon.useGlobalIcon({
      CloseIcon: iconsVue.CloseIcon,
      TimeFilledIcon: iconsVue.TimeFilledIcon,
      CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
      ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon,
      CloseCircleFilledIcon: iconsVue.CloseCircleFilledIcon
    });
    const uploadPrefix = `${props.classPrefix}-upload`;
    return {
      uploadPrefix,
      icons
    };
  },
  methods: {
    renderProgress(percent) {
      const h = this.$createElement;
      return h("div", {
        "class": `${this.uploadPrefix}__single-progress`
      }, [h(components_loading_index.Loading), h("span", {
        "class": `${this.uploadPrefix}__single-percent`
      }, [percent || 0, "%"])]);
    },
    renderFilePreviewAsText(files) {
      var _files$;
      const h = this.$createElement;
      if (this.theme !== "file") return null;
      if (!this.multiple && ((_files$ = files[0]) === null || _files$ === void 0 ? void 0 : _files$.status) === "fail") return null;
      const {
        ErrorCircleFilledIcon,
        TimeFilledIcon,
        CloseIcon
      } = this.icons;
      return files.map((file, index) => h("div", {
        "class": `${this.uploadPrefix}__single-display-text ${this.uploadPrefix}__display-text--margin`,
        "key": file.name + index + file.percent + file.status
      }, [file.url ? h(components_link_index.Link, {
        "attrs": {
          "href": file.url,
          "target": "_blank",
          "hover": "color",
          "size": "small"
        },
        "class": `${this.uploadPrefix}__single-name`
      }, [file.name]) : h("span", {
        "class": `${this.uploadPrefix}__single-name`
      }, [file.name]), file.status === "fail" && h("div", {
        "class": `${this.uploadPrefix}__flow-status`
      }, [h(ErrorCircleFilledIcon)]), file.status === "waiting" && h("div", {
        "class": `${this.uploadPrefix}__flow-status`
      }, [h(TimeFilledIcon)]), file.status === "progress" && this.renderProgress(file.percent), !this.disabled && file.status !== "progress" && h(CloseIcon, {
        "class": `${this.uploadPrefix}__icon-delete`,
        "on": {
          "click": e => this.onRemove({
            e,
            file,
            index
          })
        }
      })]));
    },
    renderFilePreviewAsInput() {
      var _this$abridgeName;
      const h = this.$createElement;
      if (this.theme !== "file-input") return;
      const {
        TimeFilledIcon,
        CheckCircleFilledIcon,
        ErrorCircleFilledIcon,
        CloseCircleFilledIcon
      } = this.icons;
      const file = this.displayFiles[0];
      const inputTextClass = [`${this.classPrefix}-input__inner`, {
        [`${this.uploadPrefix}__placeholder`]: !this.displayFiles[0]
      }];
      const disabledClass = this.disabled ? `${this.classPrefix}-is-disabled` : "";
      const fileName = (_this$abridgeName = this.abridgeName) !== null && _this$abridgeName !== void 0 && _this$abridgeName.length && file !== null && file !== void 0 && file.name ? utils.abridgeName(file.name, ...this.abridgeName) : file === null || file === void 0 ? void 0 : file.name;
      return h("div", {
        "class": `${this.uploadPrefix}__single-input-preview ${this.classPrefix}-input ${disabledClass}`
      }, [h("div", {
        "class": inputTextClass
      }, [h("span", {
        "class": `${this.uploadPrefix}__single-input-text`
      }, [file !== null && file !== void 0 && file.name ? fileName : this.placeholder]), (file === null || file === void 0 ? void 0 : file.status) === "progress" && this.renderProgress(file.percent), (file === null || file === void 0 ? void 0 : file.status) === "waiting" && h(TimeFilledIcon, {
        "class": `${this.uploadPrefix}__status-icon`
      }), (file === null || file === void 0 ? void 0 : file.url) && file.status === "success" && h(CheckCircleFilledIcon, {
        "class": `${this.uploadPrefix}__status-icon`
      }), (file === null || file === void 0 ? void 0 : file.name) && file.status === "fail" && h(ErrorCircleFilledIcon, {
        "class": `${this.uploadPrefix}__status-icon`
      }), !this.disabled && h(CloseCircleFilledIcon, {
        "class": `${this.uploadPrefix}__single-input-clear`,
        "on": {
          "click": _ref => {
            let {
              e
            } = _ref;
            return this.onRemove({
              e,
              file,
              index: 0
            });
          }
        }
      })])]);
    }
  },
  render() {
    var _this$$scopedSlots$de, _this$$scopedSlots, _this$displayFiles$, _this$displayFiles$0$;
    const h = arguments[0];
    const classes = [`${this.uploadPrefix}__single`, `${this.uploadPrefix}__single-${this.theme}`];
    const fileListDisplay = utils_renderNode.renderLNodeJSX(this, "fileListDisplay", {
      params: {
        files: this.displayFiles
      }
    });
    return h("div", {
      "class": classes
    }, [this.theme === "file-input" && this.renderFilePreviewAsInput(), (_this$$scopedSlots$de = (_this$$scopedSlots = this.$scopedSlots).default) === null || _this$$scopedSlots$de === void 0 ? void 0 : _this$$scopedSlots$de.call(_this$$scopedSlots, null), this.theme === "file" && this.placeholder && !this.displayFiles[0] && h("small", {
      "class": this.tipsClasses
    }, [this.placeholder]), fileListDisplay || this.renderFilePreviewAsText(this.displayFiles), this.sizeOverLimitMessage && h("small", {
      "class": this.errorClasses
    }, [this.sizeOverLimitMessage]), !this.multiple && ((_this$displayFiles$ = this.displayFiles[0]) === null || _this$displayFiles$ === void 0 ? void 0 : _this$displayFiles$.status) === "fail" && this.theme === "file" ? h("small", {
      "class": this.errorClasses
    }, [((_this$displayFiles$0$ = this.displayFiles[0].response) === null || _this$displayFiles$0$ === void 0 ? void 0 : _this$displayFiles$0$.error) || this.locale.progress.failText]) : null]);
  }
});

exports["default"] = NormalFile;
//# sourceMappingURL=normal-file.js.map
