"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startsWithNumeral = startsWithNumeral;
exports.compareByComplexity = compareByComplexity;
exports.compareByName = compareByName;
const util_1 = require("../spec/util");
const complexity_1 = require("./complexity");
const NUMERAL = '0123456789';
function startsWithNumeral(str) {
    return NUMERAL.indexOf(str[0]) > -1;
}
function compareByComplexity(specs, classes, a, b) {
    const aC = (0, complexity_1.getSpecComplexity)(specs, classes, a, true);
    const bC = (0, complexity_1.getSpecComplexity)(specs, classes, b, true);
    if (aC < bC) {
        return -1;
    }
    else if (aC > bC) {
        return 1;
    }
    else {
        return compareByName(specs, a, b);
    }
}
function compareByName(specs, a, b) {
    const aSpec = (0, util_1.getSpec)(specs, a);
    const bSpec = (0, util_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;
    }
}
//# sourceMappingURL=search.js.map