/**
 * ldesign v0.4.6
 * (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 VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var _common_js_upload_utils = require('../../_common/js/upload/utils.js');
var button_index = require('../../button/index.js');
var upload_constants = require('../constants.js');
var hooks_useCommonClassName = require('../../hooks/useCommonClassName.js');
var loading_index = require('../../loading/index.js');
var upload_hooks_useDrag = require('../hooks/useDrag.js');
var hooks_useGlobalIcon = require('../../hooks/useGlobalIcon.js');
var imageViewer_index = require('../../image-viewer/index.js');
var utils_renderTnode = require('../../utils/render-tnode.js');
require('../../_common/js/log/log.js');
require('../../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../../button/button.js');
require('../../utils/ripple.js');
require('../../_common/js/utils/set-style.js');
require('../../config.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
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('../../_chunks/dep-7c884501.js');
require('dayjs');
require('../../utils/mixins.js');
require('../../button/props.js');
require('../../loading/directive.js');
require('lodash/isObject');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../../loading/plugin.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../loading/loading.js');
require('../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../config-provider/useConfig.js');
require('../../image-viewer/image-viewer.js');
require('../../hooks/useVModel.js');
require('../../hooks/useDefaultValue.js');
require('../../hooks/useConfig.js');
require('../../utils/helper.js');
require('../../image-viewer/props.js');
require('../../image-viewer/base/Container.js');
require('../../image-viewer/base/ImageModalIcon.js');
require('../../hooks/tnode.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('../../hooks/render-tnode.js');
require('../../image-viewer/base/ImageViewerUtils.js');
require('../../tooltip/index.js');
require('../../utils/map-props.js');
require('../../tooltip/tooltip.js');
require('../../_chunks/dep-c3e1ffac.js');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../utils/event.js');
require('../../popup/container.js');
require('../../popup/utils.js');
require('../../popup/trigger.js');
require('../../tooltip/props.js');
require('../../image-viewer/utils.js');
require('../../image-viewer/base/ImageItem.js');
require('../../image-viewer/hooks.js');
require('../../image-viewer/base/ImageViewerModal.js');
require('../../dialog/index.js');
require('../../dialog/dialog.js');
require('lodash/throttle');
require('../../hooks/useDestroyOnClose.js');
require('../../_common/js/utils/getScrollbarWidth.js');
require('../../dialog/stack.js');
require('../../dialog/props.js');
require('../../dialog/actions.js');
require('../../dialog/plugin.js');
require('../../config-provider/config-provider.js');
require('lodash/cloneDeep');
require('../../image-viewer/const.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; }
var DraggerFile = VueCompositionAPI.defineComponent({
  name: "UploadDraggerFile",
  props: _objectSpread(_objectSpread({}, upload_constants.commonProps), {}, {
    trigger: Function,
    triggerUpload: Function,
    uploadFiles: Function,
    cancelUpload: Function,
    dragEvents: Object
  }),
  setup: function setup(props) {
    var _toRefs = VueCompositionAPI.toRefs(props),
      displayFiles = _toRefs.displayFiles;
    var _useCommonClassName = hooks_useCommonClassName["default"](),
      sizeClassNames = _useCommonClassName.sizeClassNames;
    var uploadPrefix = "".concat(props.classPrefix, "-upload");
    var drag = upload_hooks_useDrag["default"](props.dragEvents);
    var dragActive = drag.dragActive;
    var draggerFileRef = VueCompositionAPI.ref();
    var classes = VueCompositionAPI.computed(function () {
      var _displayFiles$value$;
      return ["".concat(uploadPrefix, "__dragger"), _defineProperty__default["default"]({}, "".concat(uploadPrefix, "__dragger-center"), !displayFiles.value[0]), _defineProperty__default["default"]({}, "".concat(uploadPrefix, "__dragger-error"), ((_displayFiles$value$ = displayFiles.value[0]) === null || _displayFiles$value$ === void 0 ? void 0 : _displayFiles$value$.status) === "fail")];
    });
    var icons = hooks_useGlobalIcon.useGlobalIcon({
      CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
      ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon
    });
    return {
      drag: drag,
      dragActive: dragActive,
      draggerFileRef: draggerFileRef,
      classes: classes,
      sizeClassNames: sizeClassNames,
      uploadPrefix: uploadPrefix,
      icons: icons
    };
  },
  methods: {
    renderImage: function renderImage() {
      var _file$response;
      var h = this.$createElement;
      if (!this.displayFiles.length) return;
      var file = this.displayFiles[0];
      var url = (file === null || file === void 0 ? void 0 : file.url) || (file === null || file === void 0 ? void 0 : (_file$response = file.response) === null || _file$response === void 0 ? void 0 : _file$response.url);
      return h("div", {
        "class": "".concat(this.uploadPrefix, "__dragger-img-wrap")
      }, [url && h(imageViewer_index.ImageViewer, {
        "attrs": {
          "images": [url],
          "trigger": function trigger(h2, _ref3) {
            var open = _ref3.open;
            return h("img", {
              "attrs": {
                "src": url
              },
              "on": {
                "click": open
              },
              "style": {
                maxWidth: "100%",
                maxHeight: "100%"
              }
            });
          }
        },
        "style": {
          maxWidth: "120px",
          maxHeight: "120px"
        }
      })]);
    },
    renderUploading: function renderUploading() {
      var h = this.$createElement;
      if (!this.displayFiles.length) return;
      var file = this.displayFiles[0];
      if ((file === null || file === void 0 ? void 0 : file.status) === "progress") {
        return h("div", {
          "class": "".concat(this.uploadPrefix, "__single-progress")
        }, [h(loading_index.Loading), h("span", {
          "class": "".concat(this.uploadPrefix, "__single-percent")
        }, [file.percent, "%"])]);
      }
    },
    renderMainPreview: function renderMainPreview() {
      var _this = this,
        _this$locale;
      var h = this.$createElement;
      var file = this.displayFiles[0];
      var _this$icons = this.icons,
        CheckCircleFilledIcon = _this$icons.CheckCircleFilledIcon,
        ErrorCircleFilledIcon = _this$icons.ErrorCircleFilledIcon;
      var fileName = this.abridgeName ? _common_js_upload_utils.abridgeName.apply(void 0, [file.name].concat(_toConsumableArray__default["default"](this.abridgeName))) : file.name;
      var fileInfo = [h("div", {
        "class": "".concat(this.uploadPrefix, "__dragger-text"),
        "key": "info"
      }, [h("span", {
        "class": "".concat(this.uploadPrefix, "__single-name")
      }, [fileName]), file.status === "progress" && this.renderUploading(), file.status === "success" && h(CheckCircleFilledIcon), file.status === "fail" && h(ErrorCircleFilledIcon)]), h("small", {
        "class": "".concat(this.sizeClassNames.small),
        "key": "size"
      }, [this.locale.file.fileSizeText, "\uFF1A", _common_js_upload_utils.getFileSizeText(file.size)]), h("small", {
        "class": "".concat(this.sizeClassNames.small),
        "key": "time"
      }, [this.locale.file.fileOperationDateText, "\uFF1A", file.uploadTime || "-"])];
      return h("div", {
        "class": "".concat(this.uploadPrefix, "__dragger-progress")
      }, [this.theme === "image" && this.renderImage(), h("div", {
        "class": "".concat(this.uploadPrefix, "__dragger-progress-info")
      }, [utils_renderTnode.renderTNodeJSX(this, "fileListDisplay", {
        params: {
          files: this.displayFiles
        }
      }) || fileInfo, h("div", {
        "class": "".concat(this.uploadPrefix, "__dragger-btns")
      }, [["progress", "waiting"].includes(file.status) && !this.disabled && h(button_index.Button, {
        "attrs": {
          "theme": "primary",
          "variant": "text"
        },
        "class": "".concat(this.uploadPrefix, "__dragger-progress-cancel"),
        "on": {
          "click": function click(e) {
            var _this$cancelUpload;
            return (_this$cancelUpload = _this.cancelUpload) === null || _this$cancelUpload === void 0 ? void 0 : _this$cancelUpload.call(_this, {
              e: e,
              file: _this.toUploadFiles[0] || _this.files[0]
            });
          }
        }
      }, [(_this$locale = this.locale) === null || _this$locale === void 0 ? void 0 : _this$locale.cancelUploadText]), !this.autoUpload && file.status === "waiting" && h(button_index.Button, {
        "attrs": {
          "theme": "primary",
          "variant": "text",
          "disabled": this.disabled
        },
        "on": {
          "click": function click() {
            var _this$uploadFiles;
            return (_this$uploadFiles = _this.uploadFiles) === null || _this$uploadFiles === void 0 ? void 0 : _this$uploadFiles.call(_this);
          }
        },
        "class": "".concat(this.uploadPrefix, "__dragger-upload-btn")
      }, [this.locale.triggerUploadText.normal])]), ["fail", "success"].includes(file === null || file === void 0 ? void 0 : file.status) && !this.disabled && h("div", {
        "class": "".concat(this.uploadPrefix, "__dragger-btns")
      }, [h(button_index.Button, {
        "attrs": {
          "theme": "primary",
          "variant": "text",
          "disabled": this.disabled
        },
        "class": "".concat(this.uploadPrefix, "__dragger-progress-cancel"),
        "on": {
          "click": this.triggerUpload
        }
      }, [this.locale.triggerUploadText.reupload]), h(button_index.Button, {
        "attrs": {
          "theme": "danger",
          "variant": "text",
          "disabled": this.disabled
        },
        "class": "".concat(this.uploadPrefix, "__dragger-delete-btn"),
        "on": {
          "click": function click(e) {
            var _this$onRemove;
            return (_this$onRemove = _this.onRemove) === null || _this$onRemove === void 0 ? void 0 : _this$onRemove.call(_this, {
              e: e,
              index: 0,
              file: file
            });
          }
        }
      }, [this.locale.triggerUploadText["delete"]])])])]);
    },
    renderDefaultDragElement: function renderDefaultDragElement() {
      var _this$locale$triggerU;
      var h = this.$createElement;
      var unActiveElement = h("div", [h("span", {
        "class": "".concat(this.uploadPrefix, "--highlight")
      }, [(_this$locale$triggerU = this.locale.triggerUploadText) === null || _this$locale$triggerU === void 0 ? void 0 : _this$locale$triggerU.normal]), h("span", ["\xA0\xA0/\xA0\xA0", this.locale.dragger.draggingText])]);
      var activeElement = h("div", [this.locale.dragger.dragDropText]);
      return this.dragActive ? activeElement : unActiveElement;
    },
    getContent: function getContent() {
      var _this$$scopedSlots$de, _this$$scopedSlots;
      var h = this.$createElement;
      var file = this.displayFiles[0];
      if (file && (["progress", "success", "fail", "waiting"].includes(file.status) || !file.status)) return this.renderMainPreview();
      return h("div", {
        "class": "".concat(this.uploadPrefix, "__trigger"),
        "on": {
          "click": this.triggerUpload
        }
      }, [((_this$$scopedSlots$de = (_this$$scopedSlots = this.$scopedSlots)["default"]) === null || _this$$scopedSlots$de === void 0 ? void 0 : _this$$scopedSlots$de.call(_this$$scopedSlots, null)) || this.renderDefaultDragElement()]);
    }
  },
  render: function render() {
    var _this$trigger;
    var h = arguments[0];
    return h("div", {
      "ref": "draggerFileRef",
      "class": this.classes,
      "on": {
        "drop": this.drag.handleDrop,
        "dragenter": this.drag.handleDragenter,
        "dragover": this.drag.handleDragover,
        "dragleave": this.drag.handleDragleave
      }
    }, [((_this$trigger = this.trigger) === null || _this$trigger === void 0 ? void 0 : _this$trigger.call(this, h, {
      files: this.displayFiles,
      dragActive: this.dragActive
    })) || this.getContent()]);
  }
});

exports["default"] = DraggerFile;
//# sourceMappingURL=dragger-file.js.map
