1import type { Channel } from "./types";
2
3export const byName = (a: Channel, b: Channel) => a.name.localeCompare(b.name);
4
5const rank = (c: Channel) => (c.type === "text" ? 0 : c.type === "voice" ? 1 : 2);
6
7export const firstChannel = (channels: Channel[]): Channel | null =>
8 [...channels].sort((a, b) => rank(a) - rank(b) || byName(a, b))[0] ?? null;