"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.UploadBatch = void 0;
exports.fileNameCompare = fileNameCompare;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _coreLibBeta = require("@cverse/core-lib-beta");
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var UploadBatch = exports.UploadBatch = /*#__PURE__*/function () {
  function UploadBatch(appId) {
    this.openApi = void 0;
    this.openApi = new _coreLibBeta.OpenApi({
      appId: appId,
      instanceId: -1
    });
  }
  var _proto = UploadBatch.prototype;
  _proto.uploadImage = /*#__PURE__*/function () {
    var _uploadImage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(files) {
      var formData, _iterator, _step, file, res, imageUrl;
      return _regenerator["default"].wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            _context.prev = 0;
            formData = new FormData();
            for (_iterator = _createForOfIteratorHelperLoose(files); !(_step = _iterator()).done;) {
              file = _step.value;
              formData.append("files", file.originFileObj);
            }
            _context.next = 5;
            return this.openApi.uploadBatch(formData);
          case 5:
            res = _context.sent;
            imageUrl = res["data"] || "";
            return _context.abrupt("return", imageUrl);
          case 10:
            _context.prev = 10;
            _context.t0 = _context["catch"](0);
            return _context.abrupt("return", "");
          case 13:
          case "end":
            return _context.stop();
        }
      }, _callee, this, [[0, 10]]);
    }));
    function uploadImage(_x) {
      return _uploadImage.apply(this, arguments);
    }
    return uploadImage;
  }();
  return UploadBatch;
}();
function fileNameCompare(a, b) {
  if (a == null || b == null) return 0;
  var na = a.split(/[-_.—, (]/);
  var nb = b.split(/[-_.—, (]/);
  var maxLoop = Math.max(na.length, nb.length);
  for (var i = 0; i < maxLoop; i++) {
    if (!isNaN(Number(na[i])) && !isNaN(Number(nb[i]))) {
      var num = Number(na[i]) - Number(nb[i]);
      if (num !== 0) {
        return num;
      }
    }
  }
  var ma = a.match(/[0-9]+/);
  var mb = b.match(/[0-9]+/);
  if (ma && mb && ma.length && mb.length) {
    var _num = Number(ma[0]) - Number(mb[0]);
    if (_num !== 0) {
      return _num;
    }
  }
  return a.localeCompare(b);
}