'use client'; import { useState } from 'react'; import Image from 'next/image'; import Link from 'next/link'; import { useSession } from 'next-auth/react'; import { useRouter, usePathname } from 'next/navigation'; import { Tag } from './Tag'; type ConnectionStatus = 'PENDING' | 'ACCEPTED' | 'REJECTED' | null; interface ProfileCardProps { firstName: string; lastName: string; isVerified: boolean; title: string; location: string; memberSince: string; bio: string; expertise: string[]; showEditButton?: boolean; editHref?: string; messageHref?: string; requestsHref?: string; pendingRequestCount?: number; connectionStatus?: ConnectionStatus; onConnectClick?: () => void; // Callback when Connect button is clicked (for opening modal) onUnlinkClick?: () => void; // Callback when Unlink button is clicked } export function ProfileCard({ firstName, lastName, isVerified, title, location, memberSince, bio, expertise, showEditButton = false, editHref = '/agent/edit', messageHref, requestsHref, pendingRequestCount = 0, connectionStatus, onConnectClick, onUnlinkClick, }: ProfileCardProps) { const { data: session } = useSession(); const router = useRouter(); const pathname = usePathname(); const [isUnlinking, setIsUnlinking] = useState(false); // Handle unlink click const handleUnlinkClick = async () => { if (isUnlinking) return; setIsUnlinking(true); try { await onUnlinkClick?.(); } finally { setIsUnlinking(false); } }; // Handle action click - require login if not authenticated const handleActionClick = (e: React.MouseEvent, targetHref?: string) => { if (!session) { e.preventDefault(); // Store the current page to redirect back after login const returnUrl = encodeURIComponent(pathname); router.push(`/login?callbackUrl=${returnUrl}`); return; } // If logged in and has href, navigation will happen naturally via Link if (!targetHref) { e.preventDefault(); // Handle button click when logged in but no href specified } }; return (
{/* Name and Actions Row */}

{firstName}{' '} {lastName}

{isVerified && ( <> Verified (Verified Expert) )} {showEditButton && ( Edit profile )}

{title}

Location {location} Calendar Member Since {memberSince}
{/* Action Buttons */}
{messageHref ? ( handleActionClick(e, messageHref)} className="flex items-center gap-2 px-4 py-1.5 bg-[#e58625] text-[#00293d] text-sm font-normal rounded-[15px] border border-[#00293d]/10 hover:bg-[#d47720] transition-colors font-serif cursor-pointer" > Message Message ) : ( )} {showEditButton && requestsHref ? ( // Agent's own profile - show Requests link with badge handleActionClick(e, requestsHref)} className="relative flex items-center gap-2 px-4 py-1.5 bg-[#e58625] text-[#00293d] text-sm font-normal rounded-[15px] border border-[#00293d]/10 hover:bg-[#d47720] transition-colors font-serif cursor-pointer" > Requests Requests {pendingRequestCount > 0 && ( {pendingRequestCount > 99 ? '99+' : pendingRequestCount} )} ) : ( // Public view - show Connect/Pending/Unlink button based on connection status connectionStatus === 'PENDING' ? ( ) : connectionStatus === 'ACCEPTED' ? ( ) : ( ) )}
{/* Bio */}

{bio}

{/* Expertise Tags */}

Expertise:

{expertise.map((tag, idx) => ( {tag} ))}
); }