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

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, computed, createVNode, isVNode } from 'vue';
import { CloseIcon, TimeFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, CloseCircleFilledIcon } from '@ldesign/icons-vue-next';
import { Loading } from '../../loading/index.js';
import { Link } from '../../link/index.js';
import { useTNodeJSX } from '../../hooks/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 '../../loading/directive.js';
import '../../loading/plugin.js';
import '../../utils/dom.js';
import '../../_chunks/dep-c9c789a8.js';
import 'lodash/isString';
import 'lodash/isFunction';
import 'lodash/isArray';
import '../../utils/easing.js';
import '../../hooks/useConfig.js';
import '../../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../../config-provider/context.js';
import 'lodash/mergeWith';
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 'dayjs';
import '../../loading/loading.js';
import '@babel/runtime/helpers/slicedToArray';
import '../../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../hooks/useTeleport.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 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../../link/link.js';
import '../../link/props.js';
import '../../_common/js/log/log.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; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var NormalFile = defineComponent({
  name: "UploadNormalFile",
  props: _objectSpread({
    multiple: Boolean
  }, commonProps),
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    var _toRefs = toRefs(props),
      theme = _toRefs.theme,
      disabled = _toRefs.disabled,
      classPrefix = _toRefs.classPrefix;
    var locale = computed(function () {
      return props.locale;
    });
    var _useGlobalIcon = useGlobalIcon({
        CloseIcon: CloseIcon,
        TimeFilledIcon: TimeFilledIcon,
        CheckCircleFilledIcon: CheckCircleFilledIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon,
        CloseCircleFilledIcon: CloseCircleFilledIcon
      }),
      CloseIcon$1 = _useGlobalIcon.CloseIcon,
      TimeFilledIcon$1 = _useGlobalIcon.TimeFilledIcon,
      CheckCircleFilledIcon$1 = _useGlobalIcon.CheckCircleFilledIcon,
      ErrorCircleFilledIcon$1 = _useGlobalIcon.ErrorCircleFilledIcon,
      CloseCircleFilledIcon$1 = _useGlobalIcon.CloseCircleFilledIcon;
    var renderTNodeJSX = useTNodeJSX();
    var uploadPrefix = "".concat(classPrefix.value, "-upload");
    var renderProgress = function renderProgress(percent) {
      return createVNode("div", {
        "class": "".concat(uploadPrefix, "__single-progress")
      }, [createVNode(Loading, null, null), 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 ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(props.abridgeName))) : file.name;
        return createVNode("div", {
          "class": "".concat(uploadPrefix, "__single-display-text ").concat(uploadPrefix, "__display-text--margin"),
          "key": file.name + index + file.percent + file.status
        }, [file.url ? createVNode(Link, {
          "href": file.url,
          "target": "_blank",
          "hover": "color",
          "size": "small",
          "class": "".concat(uploadPrefix, "__single-name")
        }, _isSlot(fileName) ? fileName : {
          "default": function _default() {
            return [fileName];
          }
        }) : createVNode("span", {
          "class": "".concat(uploadPrefix, "__single-name")
        }, [fileName]), file.status === "fail" && createVNode("div", {
          "class": "".concat(uploadPrefix, "__flow-status ").concat(uploadPrefix, "__file-fail")
        }, [createVNode(ErrorCircleFilledIcon$1, null, null)]), file.status === "waiting" && createVNode("div", {
          "class": "".concat(uploadPrefix, "__flow-status ").concat(uploadPrefix, "__file-waiting")
        }, [createVNode(TimeFilledIcon$1, null, null)]), file.status === "progress" && renderProgress(file.percent), !disabled.value && file.status !== "progress" && createVNode(CloseIcon$1, {
          "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({}, "".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 ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(props.abridgeName))) : file === null || file === void 0 ? void 0 : file.name;
      return createVNode("div", {
        "class": "".concat(uploadPrefix, "__single-input-preview ").concat(classPrefix.value, "-input ").concat(disabledClass)
      }, [createVNode("div", {
        "class": inputTextClass
      }, [createVNode("span", {
        "class": ["".concat(uploadPrefix, "__single-input-text"), _defineProperty({}, 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" && createVNode(TimeFilledIcon$1, {
        "class": "".concat(uploadPrefix, "__status-icon ").concat(uploadPrefix, "__file-waiting")
      }, null), file.status === "success" && createVNode(CheckCircleFilledIcon$1, {
        "class": "".concat(uploadPrefix, "__status-icon")
      }, null), (file === null || file === void 0 ? void 0 : file.name) && file.status === "fail" && createVNode(ErrorCircleFilledIcon$1, {
        "class": "".concat(uploadPrefix, "__status-icon ").concat(uploadPrefix, "__file-fail")
      }, null), Boolean(!disabled.value && file.name) && createVNode(CloseCircleFilledIcon$1, {
        "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 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] && createVNode("small", {
        "class": [props.tipsClasses, props.placeholderClass]
      }, [props.placeholder]), fileListDisplay || renderFilePreviewAsText(displayFiles), props.sizeOverLimitMessage && createVNode("small", {
        "class": props.errorClasses
      }, [props.sizeOverLimitMessage]), !props.multiple && ((_displayFiles$ = displayFiles[0]) === null || _displayFiles$ === void 0 ? void 0 : _displayFiles$.status) === "fail" && theme.value === "file" ? 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]);
    };
  }
});

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