/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import { CloseIcon, TimeFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, CloseCircleFilledIcon } from '@ldesign/icons-vue';
import { Loading } from '../../loading/index.js';
import { Link } from '../../link/index.js';
import { renderTNodeJSX } from '../../utils/render-tnode.js';
import { abridgeName } from '../../_common/js/upload/utils.js';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.js';
import { commonProps } from '../constants.js';
import '../../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../loading/directive.js';
import 'lodash/isObject';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../../loading/plugin.js';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../loading/loading.js';
import '../../utils/transfer-dom.js';
import '../../config-provider/config-receiver.js';
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 '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../../_chunks/dep-67ff4010.js';
import '../../config-provider/type.js';
import '../../utils/mixins.js';
import '../../loading/props.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 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../loading/style';
import '../../loading/type.js';
import '../../link/link.js';
import '../../link/props.js';
import '../../link/style';
import '../../link/type.js';
import '../../_common/js/log/log.js';
import '../../hooks/useConfig.js';
import '../../config-provider/useConfig.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var NormalFile = defineComponent({
  name: "UploadNormalFile",
  props: _objectSpread({
    multiple: Boolean
  }, commonProps),
  setup: function setup(props) {
    var icons = useGlobalIcon({
      CloseIcon: CloseIcon,
      TimeFilledIcon: TimeFilledIcon,
      CheckCircleFilledIcon: CheckCircleFilledIcon,
      ErrorCircleFilledIcon: ErrorCircleFilledIcon,
      CloseCircleFilledIcon: CloseCircleFilledIcon
    });
    var uploadPrefix = computed(function () {
      return "".concat(props.classPrefix, "-upload");
    });
    var classes = computed(function () {
      return ["".concat(uploadPrefix.value, "__single"), "".concat(uploadPrefix.value, "__single-").concat(props.theme)];
    });
    return {
      classes: classes,
      uploadPrefix: uploadPrefix,
      icons: icons
    };
  },
  methods: {
    renderProgress: function renderProgress(percent) {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(this.uploadPrefix, "__single-progress")
      }, [h(Loading), h("span", {
        "class": "".concat(this.uploadPrefix, "__single-percent")
      }, [percent || 0, "%"])]);
    },
    renderFilePreviewAsText: function renderFilePreviewAsText(files) {
      var _files$,
        _this = this;
      var h = this.$createElement;
      if (this.theme !== "file") return null;
      if (!this.multiple && ((_files$ = files[0]) === null || _files$ === void 0 ? void 0 : _files$.status) === "fail" && this.autoUpload) return null;
      var _this$icons = this.icons,
        ErrorCircleFilledIcon = _this$icons.ErrorCircleFilledIcon,
        TimeFilledIcon = _this$icons.TimeFilledIcon,
        CloseIcon = _this$icons.CloseIcon;
      return files.map(function (file, index) {
        var fileName = _this.abridgeName && file.name ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(_this.abridgeName))) : file.name;
        return h("div", {
          "class": "".concat(_this.uploadPrefix, "__single-display-text ").concat(_this.uploadPrefix, "__display-text--margin"),
          "key": file.name + index + file.percent + file.status
        }, [file.url ? h(Link, {
          "attrs": {
            "href": file.url,
            "target": "_blank",
            "hover": "color",
            "size": "small"
          },
          "class": "".concat(_this.uploadPrefix, "__single-name")
        }, [fileName]) : h("span", {
          "class": "".concat(_this.uploadPrefix, "__single-name")
        }, [fileName]), file.status === "fail" && h("div", {
          "class": "".concat(_this.uploadPrefix, "__flow-status ").concat(_this.uploadPrefix, "__file-fail")
        }, [h(ErrorCircleFilledIcon)]), file.status === "waiting" && h("div", {
          "class": "".concat(_this.uploadPrefix, "__flow-status ").concat(_this.uploadPrefix, "__file-waiting")
        }, [h(TimeFilledIcon)]), file.status === "progress" && _this.renderProgress(file.percent), !_this.disabled && file.status !== "progress" && h(CloseIcon, {
          "class": "".concat(_this.uploadPrefix, "__icon-delete"),
          "on": {
            "click": function click(_ref) {
              var e = _ref.e;
              return _this.onRemove({
                e: e,
                file: file,
                index: index
              });
            }
          }
        })]);
      });
    },
    renderFilePreviewAsInput: function renderFilePreviewAsInput() {
      var _this$abridgeName,
        _this2 = this;
      var h = this.$createElement;
      if (this.theme !== "file-input") return;
      var _this$icons2 = this.icons,
        TimeFilledIcon = _this$icons2.TimeFilledIcon,
        CheckCircleFilledIcon = _this$icons2.CheckCircleFilledIcon,
        ErrorCircleFilledIcon = _this$icons2.ErrorCircleFilledIcon,
        CloseCircleFilledIcon = _this$icons2.CloseCircleFilledIcon;
      var file = this.displayFiles[0] || {};
      var inputTextClass = ["".concat(this.classPrefix, "-input__inner"), _defineProperty({}, "".concat(this.uploadPrefix, "__placeholder"), !this.displayFiles[0])];
      var disabledClass = this.disabled ? "".concat(this.classPrefix, "-is-disabled") : "";
      var fileName = (_this$abridgeName = this.abridgeName) !== null && _this$abridgeName !== void 0 && _this$abridgeName.length && file !== null && file !== void 0 && file.name ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(this.abridgeName))) : file === null || file === void 0 ? void 0 : file.name;
      return h("div", {
        "class": "".concat(this.uploadPrefix, "__single-input-preview ").concat(this.classPrefix, "-input ").concat(disabledClass)
      }, [h("div", {
        "class": inputTextClass
      }, [h("span", {
        "class": ["".concat(this.uploadPrefix, "__single-input-text"), _defineProperty({}, this.placeholderClass, this.placeholder)]
      }, [file.name ? fileName : this.placeholder]), file.status === "progress" && this.renderProgress(file.percent), file.status === "waiting" && h(TimeFilledIcon, {
        "class": "".concat(this.uploadPrefix, "__status-icon ").concat(this.uploadPrefix, "__file-waiting")
      }), file.status === "success" && h(CheckCircleFilledIcon, {
        "class": "".concat(this.uploadPrefix, "__status-icon")
      }), file.name && file.status === "fail" && h(ErrorCircleFilledIcon, {
        "class": "".concat(this.uploadPrefix, "__status-icon ").concat(this.uploadPrefix, "__file-fail")
      }), Boolean(!this.disabled && file.name) && h(CloseCircleFilledIcon, {
        "class": "".concat(this.uploadPrefix, "__single-input-clear"),
        "on": {
          "click": function click(_ref4) {
            var e = _ref4.e;
            return _this2.onRemove({
              e: e,
              file: file,
              index: 0
            });
          }
        }
      })])]);
    }
  },
  render: function render() {
    var _this$$scopedSlots$de, _this$$scopedSlots, _this$displayFiles$, _this$displayFiles$0$;
    var h = arguments[0];
    var fileListDisplay = renderTNodeJSX(this, "fileListDisplay", {
      params: {
        files: this.displayFiles
      }
    });
    return h("div", {
      "class": this.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.placeholderClass]
    }, [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.placeholderClass]
    }, [((_this$displayFiles$0$ = this.displayFiles[0].response) === null || _this$displayFiles$0$ === void 0 ? void 0 : _this$displayFiles$0$.error) || this.locale.progress.failText]) : null]);
  }
});

export { NormalFile as default };
//# sourceMappingURL=normal-file.js.map
