import { schemaModel as schemaIcon, folderFilled as folderIcon, api as apiIcon, collectionsBookmark, certificate, } from '../../md/icons/Icons.js';
import { ApiFileKind, CertificateFileKind, DomainFileKind, FolderKind, ProjectKind, } from '@api-client/core/models/kinds.js';
/**
 * Reads the last segment of the file path and returns it as a file name.
 *
 * @param path THe file path.
 */
export function getFileName(path) {
    const delimiter = path.includes('/') ? '/' : '\\';
    const last = path.split(delimiter).pop();
    return last || '';
}
/**
 * Sorts files on the list.
 *
 * Folders are always on top.
 */
export function filesSortFunction(a, b) {
    if (a.kind !== b.kind) {
        if (a.kind === FolderKind) {
            return -1;
        }
        return 1;
    }
    if (a.kind === b.kind && a.kind === FolderKind) {
        if (!a.info) {
            return -1;
        }
        if (!b.info) {
            return 1;
        }
        return (a.info.name || '').localeCompare(b.info.name || '');
    }
    return b.lastModified.time - a.lastModified.time;
}
export function fileIcon(item) {
    let icon;
    switch (item.kind) {
        case DomainFileKind:
            icon = schemaIcon;
            break;
        case FolderKind:
            icon = folderIcon;
            break;
        case ApiFileKind:
            icon = apiIcon;
            break;
        case ProjectKind:
            icon = collectionsBookmark;
            break;
        case CertificateFileKind:
            icon = certificate;
            break;
        default:
    }
    return icon;
}
//# sourceMappingURL=Utils.js.map