import { compareUTF8 } from "compare-utf8";
import { assertBoolean, assertNumber, assertString } from "../../../shared/src/asserts.js";
function compareValues(a, b) {
  a = normalizeUndefined(a);
  b = normalizeUndefined(b);
  if (a === b) {
    return 0;
  }
  if (a === null) {
    return -1;
  }
  if (b === null) {
    return 1;
  }
  if (typeof a === "boolean") {
    assertBoolean(b);
    return a ? 1 : -1;
  }
  if (typeof a === "number") {
    assertNumber(b);
    return a - b;
  }
  if (typeof a === "string") {
    assertString(b);
    return compareUTF8(a, b);
  }
  throw new Error(`Unsupported type: ${a}`);
}
function normalizeUndefined(v) {
  return v ?? null;
}
function makeComparator(order, reverse) {
  return (a, b) => {
    for (const ord of order) {
      const field = ord[0];
      const comp = compareValues(a[field], b[field]);
      if (comp !== 0) {
        const result = ord[1] === "asc" ? comp : -comp;
        return reverse ? -result : result;
      }
    }
    return 0;
  };
}
function valuesEqual(a, b) {
  if (a == null || b == null) {
    return false;
  }
  return a === b;
}
export {
  compareValues,
  makeComparator,
  normalizeUndefined,
  valuesEqual
};
//# sourceMappingURL=data.js.map
