// packages/block-editor/src/utils/sorting.ts
function isGreater(a, b) {
  if (typeof a === "string" && typeof b === "string") {
    return a > b;
  }
  return Number(a) > Number(b);
}
var comparator = (field, items, order) => {
  return (a, b) => {
    let cmpA, cmpB;
    if (typeof field === "function") {
      cmpA = field(a);
      cmpB = field(b);
    } else {
      cmpA = a[field];
      cmpB = b[field];
    }
    if (isGreater(cmpA, cmpB)) {
      return order === "asc" ? 1 : -1;
    } else if (isGreater(cmpB, cmpA)) {
      return order === "asc" ? -1 : 1;
    }
    const orderA = items.findIndex((item) => item === a);
    const orderB = items.findIndex((item) => item === b);
    if (orderA > orderB) {
      return 1;
    } else if (orderB > orderA) {
      return -1;
    }
    return 0;
  };
};
function orderBy(items, field, order = "asc") {
  return items.concat().sort(comparator(field, items, order));
}
export {
  orderBy
};
//# sourceMappingURL=sorting.mjs.map
