import { CertificateFileKind, DataFileKind, FolderKind, IFile, ProjectKind, TrashEntry } from "@api-client/core/build/browser.js";
import { IconType } from "../../ui/icons/Icons.js";

/**
 * Sorts files on the list.
 * 
 * Folders are always on top.
 */
export function filesSortFunction(a: IFile, b: IFile): number {
  if (a.kind !== b.kind) {
    if (a.kind === FolderKind) {
      return -1;
    }
    return 1;
  }
  if (a.kind === b.kind && a.kind === FolderKind) {
    return (a.info.name || '').localeCompare(b.info.name || '');
  }
  return b.lastModified.time - a.lastModified.time;
}

export function fileIcon(item: IFile | TrashEntry): IconType | undefined {
  let icon: IconType | undefined;
  switch (item.kind) {
    case DataFileKind: icon = 'schema'; break;
    case FolderKind: icon = 'folder'; break;
    case ProjectKind: icon = 'collectionsBookmark'; break;
    case CertificateFileKind: icon = 'certificate'; break;
    default:
  }
  return icon;
}
