import { User, ArrowLeft, Zap, Brain, Star, Tag, Award, Check, Plus } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useNavigate } from 'react-router-dom'; import { Persona } from '@/types/persona'; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"; import { Brain, Heart, Activity, Target, Zap, Users, MapPin, Edit } from 'lucide-react'; import { ResponsiveContainer, Radar, RadarChart, PolarGrid, PolarAngleAxis, PolarRadiusAxis } from 'recharts'; import { useState } from 'react'; import { toast } from 'sonner'; import PersonaEditor from './persona/PersonaEditor'; import { getPersonaAvatarSrc } from '@/utils/avatarUtils'; interface UserCardProps { user: Persona; selected?: boolean; onClick?: (e: React.MouseEvent) => void; showDetailedDialog?: boolean; onSelectionToggle?: (e: React.MouseEvent) => void; showAddToFolderButton?: boolean; onAddToFolder?: (e: React.MouseEvent) => void; onViewDetails?: (persona: Persona) => void; } export default function UserCard({ user, selected = false, onClick, showDetailedDialog = false, onSelectionToggle, showAddToFolderButton = false, onAddToFolder, onViewDetails }: UserCardProps) { const navigate = useNavigate(); const [isEditing, setIsEditing] = useState(false); const [currentPersona, setCurrentPersona] = useState(user); // Use MongoDB _id if available, otherwise fall back to id const personaId = user._id || user.id; const handleClick = (e: React.MouseEvent) => { if (onClick) { onClick(e); } else { navigate(`/synthetic-users/${personaId}`); } }; const handleViewDetails = (e: React.MouseEvent) => { e.stopPropagation(); navigate(`/synthetic-users/${personaId}`); }; const handleSaveEdit = (updatedPersona: Persona) => { setCurrentPersona(updatedPersona); setIsEditing(false); toast.success("Persona updated successfully"); // In a real app, you would save this to your backend/state management }; const oceanData = currentPersona.oceanTraits ? [ { trait: 'Openness', value: currentPersona.oceanTraits.openness || 50 }, { trait: 'Conscientiousness', value: currentPersona.oceanTraits.conscientiousness || 50 }, { trait: 'Extraversion', value: currentPersona.oceanTraits.extraversion || 50 }, { trait: 'Agreeableness', value: currentPersona.oceanTraits.agreeableness || 50 }, { trait: 'Neuroticism', value: currentPersona.oceanTraits.neuroticism || 50 }, ] : []; const handleCardClick = (e: React.MouseEvent) => { // Check if the click target is the "View Details" button or its children const target = e.target as HTMLElement; const isViewDetailsButton = target.closest('button') && target.closest('button')?.textContent?.includes('View Details'); if (isViewDetailsButton) { // Let the button handle its own click return; } if (onSelectionToggle) { onSelectionToggle(e); } else if (onClick) { onClick(e); } }; const handleViewDetailsClick = (e: React.MouseEvent) => { e.stopPropagation(); if (onViewDetails) { onViewDetails(currentPersona); } else { handleViewDetails(e); } }; return (
{/* Overlay for visual feedback */}
{/* Selection checkmark */}
{`${currentPersona.name}
{/* Basic Demographics */}

{currentPersona.name}

{currentPersona.age} • {currentPersona.gender}

{currentPersona.occupation}

{currentPersona.location}

{/* AI-Synthesized Bio */}
{currentPersona.aiSynthesizedBio ? (

{currentPersona.aiSynthesizedBio} {currentPersona.aiSynthesizedBio.length > 150 && '...'}

) : (

"{currentPersona.personality}"

)}
{/* Qualitative Attributes */} {currentPersona.qualitativeAttributes && currentPersona.qualitativeAttributes.length > 0 && (
{currentPersona.qualitativeAttributes.slice(0, 3).map((attribute, index) => ( {attribute} ))}
)} {/* Top Personality Traits */} {currentPersona.topPersonalityTraits && currentPersona.topPersonalityTraits.length > 0 && (
{currentPersona.topPersonalityTraits.slice(0, 3).map((trait, index) => ( {trait} ))}
)}
); }