/**
 * League role types - defined locally to avoid core dependencies
 */
export type MembershipRole = 'owner' | 'admin' | 'steward' | 'member';
export type LeagueRole = MembershipRole;

export function isLeagueOwnerRole(role: LeagueRole): boolean {
  return role === 'owner';
}

export function isLeagueAdminRole(role: LeagueRole): boolean {
  return role === 'admin';
}

export function isLeagueStewardRole(role: LeagueRole): boolean {
  return role === 'steward';
}

export function isLeagueMemberRole(role: LeagueRole): boolean {
  return role === 'member';
}

/**
 * Returns true for roles that should be treated as having elevated permissions.
 * This keeps UI logic open for future roles like steward, streamer, sponsor.
 */
export function isLeagueAdminOrHigherRole(role: LeagueRole): boolean {
  return role === 'owner' || role === 'admin' || role === 'steward';
}

/**
 * Ordering helper for sorting memberships in tables.
 */
export function getLeagueRoleOrder(role: LeagueRole): number {
  const order: Record<LeagueRole, number> = {
    owner: 0,
    admin: 1,
    steward: 2,
    member: 3,
  };
  return order[role] ?? 99;
}

/**
 * Centralized display configuration for league membership roles.
 */
export function getLeagueRoleDisplay(
  role: LeagueRole,
): { text: string; badgeClasses: string } {
  switch (role) {
    case 'owner':
      return {
        text: 'Owner',
        badgeClasses: 'bg-yellow-500/10 text-yellow-500 border-yellow-500/30',
      };
    case 'admin':
      return {
        text: 'Admin',
        badgeClasses: 'bg-purple-500/10 text-purple-400 border-purple-500/30',
      };
    case 'steward':
      return {
        text: 'Steward',
        badgeClasses: 'bg-blue-500/10 text-blue-400 border-blue-500/30',
      };
    case 'member':
    default:
      return {
        text: 'Member',
        badgeClasses: 'bg-primary-blue/10 text-primary-blue border-primary-blue/30',
      };
  }
}