"use client"; import { RiArchiveLine, RiCheckLine, RiDeleteBin5Line, RiEyeLine, RiInboxUnarchiveLine, RiPencilLine, } from "@remixicon/react"; import { useMemo } from "react"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardFooter } from "@/components/ui/card"; import { type Note, sortTasksByStatus } from "./types"; const DATE_FORMATTER = new Intl.DateTimeFormat("pt-BR", { dateStyle: "medium", }); interface NoteCardProps { note: Note; onEdit?: (note: Note) => void; onDetails?: (note: Note) => void; onRemove?: (note: Note) => void; onArquivar?: (note: Note) => void; isArquivadas?: boolean; } export function NoteCard({ note, onEdit, onDetails, onRemove, onArquivar, isArquivadas = false, }: NoteCardProps) { const { displayTitle } = useMemo(() => { const resolvedTitle = note.title.trim().length ? note.title : "Anotação sem título"; return { displayTitle: resolvedTitle, formattedDate: DATE_FORMATTER.format(new Date(note.createdAt)), }; }, [note.createdAt, note.title]); const isTask = note.type === "tarefa"; const tasks = note.tasks || []; const sortedTasks = useMemo(() => sortTasksByStatus(tasks), [tasks]); const completedCount = tasks.filter((t) => t.completed).length; const totalCount = tasks.length; const actions = [ { label: "editar", icon: , onClick: onEdit, variant: "default" as const, }, { label: "detalhes", icon: , onClick: onDetails, variant: "default" as const, }, { label: isArquivadas ? "desarquivar" : "arquivar", icon: isArquivadas ? ( ) : ( ), onClick: onArquivar, variant: "default" as const, }, { label: "remover", icon: , onClick: onRemove, variant: "destructive" as const, }, ].filter((action) => typeof action.onClick === "function"); return ( {displayTitle} {isTask && ( {completedCount}/{totalCount} concluídas )} {isTask ? ( {sortedTasks.slice(0, 5).map((task) => ( {task.completed && ( )} {task.text} ))} {tasks.length > 5 && ( +{tasks.length - 5} {tasks.length - 5 === 1 ? "tarefa" : "tarefas"}... )} ) : ( {note.description} )} {actions.length > 0 ? ( {actions.map(({ label, icon, onClick, variant }) => ( onClick?.(note)} className={`flex items-center gap-1 font-medium transition-opacity hover:opacity-80 ${ variant === "destructive" ? "text-destructive" : "text-primary" }`} aria-label={`${label} anotação`} > {icon} {label} ))} ) : null} ); }
+{tasks.length - 5} {tasks.length - 5 === 1 ? "tarefa" : "tarefas"}...
{note.description}