"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.formatFileSize = void 0;
exports.sortAttachments = sortAttachments;

var _dataset = require("choerodon-ui/dataset");

var formatFileSize = _dataset.Utils.formatFileSize;
exports.formatFileSize = formatFileSize;

function sortAttachments(attachments, sort) {
  if (attachments) {
    if (!sort.custom) {
      var type = sort.type,
          order = sort.order;
      return attachments.sort(function (a, b) {
        if (type === 'name') {
          if (order === 'desc') {
            return b.name.localeCompare(a.name);
          }

          return a.name.localeCompare(b.name);
        }

        if (order === 'desc') {
          return b.creationDate.getTime() - a.creationDate.getTime();
        }

        return a.creationDate.getTime() - b.creationDate.getTime();
      });
    }

    return attachments;
  }
}
//# sourceMappingURL=utils.js.map
