"use client"; import { formatDistanceToNow } from "date-fns"; import { CheckCircle2, Activity, FileEdit, Archive } from "lucide-react"; import Link from "next/link"; import { Badge } from "~/components/ui/badge"; import { Button } from "~/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "~/components/ui/card"; import { Separator } from "~/components/ui/separator"; interface Study { id: string; name: string; description: string | null; status: "draft" | "active" | "completed" | "archived"; institution: string | null; irbProtocolNumber?: string; createdAt: Date; updatedAt: Date; ownerId?: string; _count?: { experiments: number; trials: number; studyMembers: number; participants: number; }; owner: { name: string | null; email: string; }; } interface StudyCardProps { study: Study; userRole?: "owner" | "researcher" | "wizard" | "observer"; isOwner?: boolean; } const statusConfig = { draft: { label: "Draft", className: "bg-gray-100 text-gray-800 hover:bg-gray-200", icon: FileEdit, }, active: { label: "Active", className: "bg-green-100 text-green-800 hover:bg-green-200", icon: Activity, }, completed: { label: "Completed", className: "bg-blue-100 text-blue-800 hover:bg-blue-200", icon: CheckCircle2, }, archived: { label: "Archived", className: "bg-orange-100 text-orange-800 hover:bg-orange-200", icon: Archive, }, }; export function StudyCard({ study, userRole, isOwner }: StudyCardProps) { const statusInfo = statusConfig[study.status]; const canEdit = isOwner ?? (userRole === "owner" || userRole === "researcher"); return (
{study.name} {study.description}
{statusInfo.label}
{/* Institution and IRB */}
{study.institution}
{study.irbProtocolNumber && (
IRB: {study.irbProtocolNumber}
)}
{/* Statistics */} {study._count && ( <>
Experiments: {study._count.experiments}
Trials: {study._count.trials}
Team: {study._count.studyMembers}
Participants: {study._count.participants}
)} {/* Metadata */}
Created: {formatDistanceToNow(study.createdAt, { addSuffix: true })}
Owner: {study.owner.name ?? study.owner.email}
{study.updatedAt !== study.createdAt && (
Updated: {formatDistanceToNow(study.updatedAt, { addSuffix: true })}
)}
{/* Actions */}
{canEdit && ( )}
{/* Role indicator */} {userRole && (
Your role: {userRole}
)}
); }