const { ArrayIsArray: _p_ArrayIsArray } = require('../primordials/array.js')
const { ObjectDefineProperty: _p_ObjectDefineProperty } = require('../primordials/object.js')

"use strict";
/**
 * Bundled from fast-sort
 * This is a zero-dependency bundle created by esbuild.
 */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __commonJS = (cb, mod) => function __require() {
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};

// node_modules/.pnpm/fast-sort@3.4.1/node_modules/fast-sort/dist/sort.cjs.js
var require_sort_cjs = __commonJS({
  "node_modules/.pnpm/fast-sort@3.4.1/node_modules/fast-sort/dist/sort.cjs.js"(exports2) {
    "use strict";
    _p_ObjectDefineProperty(exports2, "__esModule", { value: true });
    var castComparer = /* @__PURE__ */ __name(function(comparer) {
      return function(a, b, order) {
        return comparer(a, b, order) * order;
      };
    }, "castComparer");
    var throwInvalidConfigErrorIfTrue = /* @__PURE__ */ __name(function(condition, context) {
      if (condition)
        throw Error("Invalid sort config: " + context);
    }, "throwInvalidConfigErrorIfTrue");
    var unpackObjectSorter = /* @__PURE__ */ __name(function(sortByObj) {
      var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc;
      var order = asc ? 1 : -1;
      var sortBy = asc || desc;
      throwInvalidConfigErrorIfTrue(!sortBy, "Expected `asc` or `desc` property");
      throwInvalidConfigErrorIfTrue(asc && desc, "Ambiguous object with `asc` and `desc` config properties");
      var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);
      return { order, sortBy, comparer };
    }, "unpackObjectSorter");
    var multiPropertySorterProvider = /* @__PURE__ */ __name(function(defaultComparer2) {
      return /* @__PURE__ */ __name(function multiPropertySorter(sortBy, sortByArr, depth, order, comparer, a, b) {
        var valA;
        var valB;
        if (typeof sortBy === "string") {
          valA = a[sortBy];
          valB = b[sortBy];
        } else if (typeof sortBy === "function") {
          valA = sortBy(a);
          valB = sortBy(b);
        } else {
          var objectSorterConfig = unpackObjectSorter(sortBy);
          return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer2, a, b);
        }
        var equality = comparer(valA, valB, order);
        if ((equality === 0 || valA == null && valB == null) && sortByArr.length > depth) {
          return multiPropertySorter(sortByArr[depth], sortByArr, depth + 1, order, comparer, a, b);
        }
        return equality;
      }, "multiPropertySorter");
    }, "multiPropertySorterProvider");
    function getSortStrategy(sortBy, comparer, order) {
      if (sortBy === void 0 || sortBy === true) {
        return function(a, b) {
          return comparer(a, b, order);
        };
      }
      if (typeof sortBy === "string") {
        throwInvalidConfigErrorIfTrue(sortBy.includes("."), "String syntax not allowed for nested properties.");
        return function(a, b) {
          return comparer(a[sortBy], b[sortBy], order);
        };
      }
      if (typeof sortBy === "function") {
        return function(a, b) {
          return comparer(sortBy(a), sortBy(b), order);
        };
      }
      if (_p_ArrayIsArray(sortBy)) {
        var multiPropSorter_1 = multiPropertySorterProvider(comparer);
        return function(a, b) {
          return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a, b);
        };
      }
      var objectSorterConfig = unpackObjectSorter(sortBy);
      return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);
    }
    __name(getSortStrategy, "getSortStrategy");
    var sortArray = /* @__PURE__ */ __name(function(order, ctx, sortBy, comparer) {
      var _a;
      if (!_p_ArrayIsArray(ctx)) {
        return ctx;
      }
      if (_p_ArrayIsArray(sortBy) && sortBy.length < 2) {
        _a = sortBy, sortBy = _a[0];
      }
      return ctx.sort(getSortStrategy(sortBy, comparer, order));
    }, "sortArray");
    function createNewSortInstance2(opts) {
      var comparer = castComparer(opts.comparer);
      return function(arrayToSort) {
        var ctx = _p_ArrayIsArray(arrayToSort) && !opts.inPlaceSorting ? arrayToSort.slice() : arrayToSort;
        return {
          asc: /* @__PURE__ */ __name(function(sortBy) {
            return sortArray(1, ctx, sortBy, comparer);
          }, "asc"),
          desc: /* @__PURE__ */ __name(function(sortBy) {
            return sortArray(-1, ctx, sortBy, comparer);
          }, "desc"),
          by: /* @__PURE__ */ __name(function(sortBy) {
            return sortArray(1, ctx, sortBy, comparer);
          }, "by")
        };
      };
    }
    __name(createNewSortInstance2, "createNewSortInstance");
    var defaultComparer = /* @__PURE__ */ __name(function(a, b, order) {
      if (a == null)
        return order;
      if (b == null)
        return -order;
      if (typeof a !== typeof b) {
        return typeof a < typeof b ? -1 : 1;
      }
      if (a < b)
        return -1;
      if (a > b)
        return 1;
      return 0;
    }, "defaultComparer");
    var sort = createNewSortInstance2({
      comparer: defaultComparer
    });
    var inPlaceSort = createNewSortInstance2({
      comparer: defaultComparer,
      inPlaceSorting: true
    });
    exports2.createNewSortInstance = createNewSortInstance2;
    exports2.defaultComparer = defaultComparer;
    exports2.inPlaceSort = inPlaceSort;
    exports2.sort = sort;
  }
});

// src/external/fast-sort.js
var { createNewSortInstance } = require_sort_cjs();
module.exports = {
  createNewSortInstance
};
