import { getAuthRoleLabel } from '@/business/auth/selectors';
import { DEFAULT_CAMPUS_LABEL } from '@/shared/constants/campusDisplay';
import type {
  CampusInfo,
  UserRole,
} from '@/shared/types/app';
import type { TopBarNotification } from '@/business/top-bar/types';

export function getTopBarInitials(name: string): string {
  return name
    .trim()
    .split(/\s+/u)
    .filter(Boolean)
    .map((part) => part[0])
    .join('')
    .slice(0, 2)
    .toUpperCase();
}

export function getTopBarCampusLabel(campusInfo?: CampusInfo): string {
  return campusInfo?.fullName ?? DEFAULT_CAMPUS_LABEL;
}

export function getTopBarRoleLabel(role: UserRole): string {
  return getAuthRoleLabel(role);
}

export function countUnreadTopBarNotifications(
  notifications: readonly TopBarNotification[],
): number {
  return notifications.filter((notification) => notification.unread).length;
}
