'use client';

import { useEffectiveDriverId } from "@/hooks/useEffectiveDriverId";
import { getMembership } from '@/lib/leagueMembership';
import type { MembershipRole } from '@/lib/types/MembershipRole';
import { Badge } from '@/ui/Badge';

interface MembershipStatusProps {
  leagueId: string;
}

export function MembershipStatus({ leagueId }: MembershipStatusProps) {
  const currentDriverId = useEffectiveDriverId();
  
  if (!currentDriverId) {
    return (
      <Badge variant="default">
        Not a Member
      </Badge>
    );
  }
  
  const membership = currentDriverId ? getMembership(leagueId, currentDriverId) : null;

  if (!membership) {
    return (
      <Badge variant="default">
        Not a Member
      </Badge>
    );
  }

  const getRoleVariant = (role: MembershipRole): 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' => {
    switch (role) {
      case 'owner':
        return 'warning';
      case 'admin':
        return 'primary';
      case 'steward':
        return 'info';
      case 'member':
        return 'primary';
      default:
        return 'default';
    }
  };

  const getRoleText = (role: MembershipRole): string => {
    switch (role) {
      case 'owner': return 'Owner';
      case 'admin': return 'Admin';
      case 'steward': return 'Steward';
      case 'member': return 'Member';
      default: return 'Member';
    }
  };

  return (
    <Badge variant={getRoleVariant(membership.role)}>
      {getRoleText(membership.role)}
    </Badge>
  );
}
