"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compareByName = exports.compareByComplexity = exports.startsWithNumeral = void 0;
const complexity_1 = require("./complexity");
const spec_1 = require("./spec");
const NUMERAL = '0123456789';
function startsWithNumeral(str) {
    return NUMERAL.indexOf(str[0]) > -1;
}
exports.startsWithNumeral = startsWithNumeral;
function compareByComplexity(specs, a, b) {
    const aC = (0, complexity_1.getSpecComplexity)(specs, a, true);
    const bC = (0, complexity_1.getSpecComplexity)(specs, b, true);
    if (aC < bC) {
        return -1;
    }
    else if (aC > bC) {
        return 1;
    }
    else {
        return compareByName(specs, a, b);
    }
}
exports.compareByComplexity = compareByComplexity;
function compareByName(specs, a, b) {
    const aSpec = (0, spec_1.getSpec)(specs, a);
    const bSpec = (0, spec_1.getSpec)(specs, b);
    const aName = (aSpec.name || '').toLowerCase();
    const bName = (bSpec.name || '').toLowerCase();
    if (startsWithNumeral(aName) && !startsWithNumeral(bName)) {
        return 1;
    }
    else if (!startsWithNumeral(aName) && startsWithNumeral(bName)) {
        return -1;
    }
    if (aName < bName) {
        return -1;
    }
    else if (aName > bName) {
        return 1;
    }
    else {
        return 0;
    }
}
exports.compareByName = compareByName;
//# sourceMappingURL=search.js.map