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

'use strict';

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

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
var loading_index = require('../../loading/index.js');
var link_index = require('../../link/index.js');
var hooks_tnode = require('../../hooks/tnode.js');
var _common_js_upload_utils = require('../../_common/js/upload/utils.js');
var hooks_useGlobalIcon = require('../../hooks/useGlobalIcon.js');
var upload_constants = require('../constants.js');
require('../../utils/withInstall.js');
require('../../loading/directive.js');
require('../../loading/plugin.js');
require('../../utils/dom.js');
require('../../_chunks/dep-7f0559c3.js');
require('lodash/isString');
require('lodash/isFunction');
require('lodash/isArray');
require('../../utils/easing.js');
require('../../hooks/useConfig.js');
require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('dayjs');
require('../../loading/loading.js');
require('@babel/runtime/helpers/slicedToArray');
require('../../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../hooks/useTeleport.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/set-style.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('../../link/link.js');
require('../../link/props.js');
require('../../_common/js/log/log.js');

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

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

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__default["default"](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; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
var NormalFile = vue.defineComponent({
  name: "UploadNormalFile",
  props: _objectSpread({
    multiple: Boolean
  }, upload_constants.commonProps),
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    var _toRefs = vue.toRefs(props),
      theme = _toRefs.theme,
      disabled = _toRefs.disabled,
      classPrefix = _toRefs.classPrefix;
    var locale = vue.computed(function () {
      return props.locale;
    });
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        CloseIcon: iconsVueNext.CloseIcon,
        TimeFilledIcon: iconsVueNext.TimeFilledIcon,
        CheckCircleFilledIcon: iconsVueNext.CheckCircleFilledIcon,
        ErrorCircleFilledIcon: iconsVueNext.ErrorCircleFilledIcon,
        CloseCircleFilledIcon: iconsVueNext.CloseCircleFilledIcon
      }),
      CloseIcon = _useGlobalIcon.CloseIcon,
      TimeFilledIcon = _useGlobalIcon.TimeFilledIcon,
      CheckCircleFilledIcon = _useGlobalIcon.CheckCircleFilledIcon,
      ErrorCircleFilledIcon = _useGlobalIcon.ErrorCircleFilledIcon,
      CloseCircleFilledIcon = _useGlobalIcon.CloseCircleFilledIcon;
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var uploadPrefix = "".concat(classPrefix.value, "-upload");
    var renderProgress = function renderProgress(percent) {
      return vue.createVNode("div", {
        "class": "".concat(uploadPrefix, "__single-progress")
      }, [vue.createVNode(loading_index.Loading, null, null), vue.createVNode("span", {
        "class": "".concat(uploadPrefix, "__single-percent")
      }, [percent || 0, "%"])]);
    };
    var renderFilePreviewAsText = function renderFilePreviewAsText(files) {
      var _files$;
      if (theme.value !== "file") return null;
      if (!props.multiple && ((_files$ = files[0]) === null || _files$ === void 0 ? void 0 : _files$.status) === "fail" && props.autoUpload) return null;
      return files.map(function (file, index) {
        var fileName = props.abridgeName && file.name ? _common_js_upload_utils.abridgeName.apply(void 0, [file.name].concat(_toConsumableArray__default["default"](props.abridgeName))) : file.name;
        return vue.createVNode("div", {
          "class": "".concat(uploadPrefix, "__single-display-text ").concat(uploadPrefix, "__display-text--margin"),
          "key": file.name + index + file.percent + file.status
        }, [file.url ? vue.createVNode(link_index.Link, {
          "href": file.url,
          "target": "_blank",
          "hover": "color",
          "size": "small",
          "class": "".concat(uploadPrefix, "__single-name")
        }, _isSlot(fileName) ? fileName : {
          "default": function _default() {
            return [fileName];
          }
        }) : vue.createVNode("span", {
          "class": "".concat(uploadPrefix, "__single-name")
        }, [fileName]), file.status === "fail" && vue.createVNode("div", {
          "class": "".concat(uploadPrefix, "__flow-status ").concat(uploadPrefix, "__file-fail")
        }, [vue.createVNode(ErrorCircleFilledIcon, null, null)]), file.status === "waiting" && vue.createVNode("div", {
          "class": "".concat(uploadPrefix, "__flow-status ").concat(uploadPrefix, "__file-waiting")
        }, [vue.createVNode(TimeFilledIcon, null, null)]), file.status === "progress" && renderProgress(file.percent), !disabled.value && file.status !== "progress" && vue.createVNode(CloseIcon, {
          "class": "".concat(uploadPrefix, "__icon-delete"),
          "onClick": function onClick(_ref2) {
            var e = _ref2.e;
            return props.onRemove({
              e: e,
              file: file,
              index: index
            });
          }
        }, null)]);
      });
    };
    var renderFilePreviewAsInput = function renderFilePreviewAsInput() {
      var _props$abridgeName;
      if (theme.value !== "file-input") return;
      var file = props.displayFiles[0] || [];
      var inputTextClass = ["".concat(classPrefix.value, "-input__inner"), _defineProperty__default["default"]({}, "".concat(uploadPrefix, "__placeholder"), !props.displayFiles[0])];
      var disabledClass = disabled.value ? "".concat(classPrefix.value, "-is-disabled") : "";
      var fileName = (_props$abridgeName = props.abridgeName) !== null && _props$abridgeName !== void 0 && _props$abridgeName.length && file !== null && file !== void 0 && file.name ? _common_js_upload_utils.abridgeName.apply(void 0, [file.name].concat(_toConsumableArray__default["default"](props.abridgeName))) : file === null || file === void 0 ? void 0 : file.name;
      return vue.createVNode("div", {
        "class": "".concat(uploadPrefix, "__single-input-preview ").concat(classPrefix.value, "-input ").concat(disabledClass)
      }, [vue.createVNode("div", {
        "class": inputTextClass
      }, [vue.createVNode("span", {
        "class": ["".concat(uploadPrefix, "__single-input-text"), _defineProperty__default["default"]({}, props.placeholderClass, props.placeholder && !(file !== null && file !== void 0 && file.name))]
      }, [file !== null && file !== void 0 && file.name ? fileName : props.placeholder]), (file === null || file === void 0 ? void 0 : file.status) === "progress" && renderProgress(file.percent), (file === null || file === void 0 ? void 0 : file.status) === "waiting" && vue.createVNode(TimeFilledIcon, {
        "class": "".concat(uploadPrefix, "__status-icon ").concat(uploadPrefix, "__file-waiting")
      }, null), file.status === "success" && vue.createVNode(CheckCircleFilledIcon, {
        "class": "".concat(uploadPrefix, "__status-icon")
      }, null), (file === null || file === void 0 ? void 0 : file.name) && file.status === "fail" && vue.createVNode(ErrorCircleFilledIcon, {
        "class": "".concat(uploadPrefix, "__status-icon ").concat(uploadPrefix, "__file-fail")
      }, null), Boolean(!disabled.value && file.name) && vue.createVNode(CloseCircleFilledIcon, {
        "class": "".concat(uploadPrefix, "__single-input-clear"),
        "onClick": function onClick(_ref5) {
          var e = _ref5.e;
          return props.onRemove({
            e: e,
            file: file,
            index: 0
          });
        }
      }, null)])]);
    };
    return function () {
      var _slots$default, _displayFiles$, _displayFiles$0$respo;
      var classes = ["".concat(uploadPrefix, "__single"), "".concat(uploadPrefix, "__single-").concat(theme.value)];
      var fileListDisplay = renderTNodeJSX("fileListDisplay", {
        params: {
          files: props.displayFiles
        }
      });
      var displayFiles = props.displayFiles;
      return vue.createVNode("div", {
        "class": classes
      }, [theme.value === "file-input" && renderFilePreviewAsInput(), (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots), theme.value === "file" && props.placeholder && !displayFiles[0] && vue.createVNode("small", {
        "class": [props.tipsClasses, props.placeholderClass]
      }, [props.placeholder]), fileListDisplay || renderFilePreviewAsText(displayFiles), props.sizeOverLimitMessage && vue.createVNode("small", {
        "class": props.errorClasses
      }, [props.sizeOverLimitMessage]), !props.multiple && ((_displayFiles$ = displayFiles[0]) === null || _displayFiles$ === void 0 ? void 0 : _displayFiles$.status) === "fail" && theme.value === "file" ? vue.createVNode("small", {
        "class": [props.errorClasses, props.placeholderClass]
      }, [((_displayFiles$0$respo = displayFiles[0].response) === null || _displayFiles$0$respo === void 0 ? void 0 : _displayFiles$0$respo.error) || locale.value.progress.failText]) : null]);
    };
  }
});

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