'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); const [showLocationModal, setShowLocationModal] = useState(false); // Split location into parts and limit display const locationParts = location.split(',').map(s => s.trim()).filter(Boolean); const maxVisibleLocations = 4; const visibleLocations = locationParts.slice(0, maxVisibleLocations).join(', '); const hasMoreLocations = locationParts.length > maxVisibleLocations; const remainingCount = locationParts.length - maxVisibleLocations; // 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 (
{title}
{bio}
{/* Expertise Tags */}Expertise:
{/* Separate long text entries from short tag entries */} {expertise.filter(tag => tag.length > 60).length > 0 && ({expertise.filter(tag => tag.length > 60).join(' ')}
)}