import { Group, Stack, Text, Card, Badge, Box, ActionIcon } from "@mantine/core";
import { PhoneIcon, CheckCircleIcon } from "@phosphor-icons/react";
import { useFreeAgents } from "../../queries";
import UnenrollFreeAgent from "./unenroll-free-agent";
import toast from "@/lib/sonner";
import { useAuth } from "@/contexts/auth-context";
import PlayerAvatar from "@/components/player-avatar";
const EnrolledFreeAgent: React.FC<{ tournamentId: string, isRegional?: boolean }> = ({
tournamentId,
isRegional
}) => {
const { data: freeAgents } = useFreeAgents(tournamentId);
const { user } = useAuth();
const copyToClipboard = async (phone: string) => {
try {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(phone);
toast.success("Phone number copied!");
return;
}
const textArea = document.createElement("textarea");
textArea.value = phone;
textArea.style.display = "hidden";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
const successful = document.execCommand('copy');
document.body.removeChild(textArea);
if (successful) {
toast.success("Phone number copied!");
} else {
throw new Error("Copy command failed");
}
} catch (err) {
console.error("Failed to copy:", err);
toast.error("Failed to copy");
}
};
if (isRegional) {
return (
{user?.first_name} {user?.last_name}
Enrolled
Partners will be randomly assigned when enrollment closes
);
}
return (
✓ Enrolled as Free Agent
Other players looking for teammates:
{freeAgents.length > 1 ? (
Free Agents
{freeAgents.length}
{freeAgents
.filter(agent => agent.player)
.map((agent) => (
{agent.player?.first_name} {agent.player?.last_name}
{agent.phone && (
copyToClipboard(agent.phone!)}
style={{ cursor: 'pointer' }}
>
copyToClipboard(agent.phone!)}
>
{agent.phone}
)}
))}
) : (
You're the first free agent!
)}
);
};
export default EnrolledFreeAgent;