/**
 * The "name" can be described in several places; this function gets the "most sortable" name, based on a precedence of
 * <ol>
 *   <li>displayName</li>
 *   <li>name</li>
 *   <li>appID</li>
 * </ol>
 *
 * @param folderAppType the instance to get the sortable name from
 * @returns the sortable name
 */
const getSortableName = (folderAppType) => { var _a, _b; return (_b = (_a = folderAppType.displayName) !== null && _a !== void 0 ? _a : folderAppType.name) !== null && _b !== void 0 ? _b : folderAppType.appID; };
/**
 * A comparator for FolderAppType instance names.
 *
 * @param lhs the left hand side of the comparison
 * @param rhs the right hand side of the comparison
 * @returns the result of the compare of the names based on getSortableName for both <i>lhs</i> and <i>rhs</i>
 */
const compareFolderAppType = (lhs, rhs) => getSortableName(lhs).localeCompare(getSortableName(rhs));
export default {
    /**
     * Sorts list by name alphabetically
     */
    Alphabetical: (list) => list.sort(compareFolderAppType),
    /**
     * Sorts a list of application by Favorites.
     * It gets a list of apps from Favorites folder
     * then in the sort function, it checks where a, b apps
     * are in favorite folder or not, giving a lower index
     * for apps that are in Favorite folder
     */
    Favorites: (list, favorites) => list.sort((a, b) => {
        var _a, _b;
        const aInFavorites = favorites.includes(a.name) || favorites.includes(a.appID) || favorites.includes((_a = a.displayName) !== null && _a !== void 0 ? _a : "");
        const bInFavorites = favorites.includes(b.name) || favorites.includes(b.appID) || favorites.includes((_b = b.displayName) !== null && _b !== void 0 ? _b : "");
        // a component being in favorites means it is "less than" another component not in favorites, so return -1
        if (aInFavorites && !bInFavorites) {
            return -1;
        }
        else if (!aInFavorites && bInFavorites) {
            return 1;
        }
        return compareFolderAppType(a, b);
    }),
};
//# sourceMappingURL=sort-functions.js.map