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 rolldown.
 */
'use strict';

//#region \0rolldown/runtime.js
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
	value,
	configurable: true
});
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);

//#endregion

//#region node_modules/.pnpm/fast-sort@3.4.1/node_modules/fast-sort/dist/sort.cjs.js
var require_sort_cjs = /* @__PURE__ */ __commonJSMin(((exports) => {
	_p_ObjectDefineProperty(exports, "__esModule", { value: true });
	var castComparer = function(comparer) {
		return function(a, b, order) {
			return comparer(a, b, order) * order;
		};
	};
	var throwInvalidConfigErrorIfTrue = function(condition, context) {
		if (condition) throw Error("Invalid sort config: " + context);
	};
	var unpackObjectSorter = function(sortByObj) {
		var _a = sortByObj || {};
		var asc = _a.asc;
		var 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");
		return {
			order,
			sortBy,
			comparer: sortByObj.comparer && castComparer(sortByObj.comparer)
		};
	};
	var multiPropertySorterProvider = function(defaultComparer) {
		return 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 || defaultComparer, 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;
		};
	};
	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);
	}
	var sortArray = 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));
	};
	function createNewSortInstance(opts) {
		var comparer = castComparer(opts.comparer);
		return function(arrayToSort) {
			var ctx = _p_ArrayIsArray(arrayToSort) && !opts.inPlaceSorting ? arrayToSort.slice() : arrayToSort;
			return {
				asc: function(sortBy) {
					return sortArray(1, ctx, sortBy, comparer);
				},
				desc: function(sortBy) {
					return sortArray(-1, ctx, sortBy, comparer);
				},
				by: function(sortBy) {
					return sortArray(1, ctx, sortBy, comparer);
				}
			};
		};
	}
	var defaultComparer = 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;
	};
	var sort = createNewSortInstance({ comparer: defaultComparer });
	var inPlaceSort = createNewSortInstance({
		comparer: defaultComparer,
		inPlaceSorting: true
	});
	exports.createNewSortInstance = createNewSortInstance;
	exports.defaultComparer = defaultComparer;
	exports.inPlaceSort = inPlaceSort;
	exports.sort = sort;
}));

//#endregion
//#region src/external/fast-sort.js
const { createNewSortInstance } = require_sort_cjs();
module.exports = { createNewSortInstance };

//#endregion