'use client' import { useRouter } from 'next/navigation' import { NotebookResponse } from '@/lib/types/api' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { MoreHorizontal, Archive, ArchiveRestore, Trash2, FileText, StickyNote } from 'lucide-react' import { formatDistanceToNow } from 'date-fns' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { useUpdateNotebook } from '@/lib/hooks/use-notebooks' import { NotebookDeleteDialog } from './NotebookDeleteDialog' import { useState } from 'react' import { useTranslation } from '@/lib/hooks/use-translation' import { getDateLocale } from '@/lib/utils/date-locale' interface NotebookCardProps { notebook: NotebookResponse } export function NotebookCard({ notebook }: NotebookCardProps) { const { t, language } = useTranslation() const [showDeleteDialog, setShowDeleteDialog] = useState(false) const router = useRouter() const updateNotebook = useUpdateNotebook() const handleArchiveToggle = (e: React.MouseEvent) => { e.stopPropagation() updateNotebook.mutate({ id: notebook.id, data: { archived: !notebook.archived } }) } const handleCardClick = () => { router.push(`/notebooks/${encodeURIComponent(notebook.id)}`) } return ( <>
{notebook.name} {notebook.archived && ( {t('notebooks.archived')} )}
e.stopPropagation()}> {notebook.archived ? ( <> {t('notebooks.unarchive')} ) : ( <> {t('notebooks.archive')} )} { e.stopPropagation() setShowDeleteDialog(true) }} className="text-red-600" > {t('common.delete')}
{notebook.description || t('chat.noDescription')}
{t('common.updated').replace('{time}', formatDistanceToNow(new Date(notebook.updated), { addSuffix: true, locale: getDateLocale(language) }))}
{/* Item counts footer */}
{notebook.source_count} {notebook.note_count}
) }