"use client"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardFooter } from "@/components/ui/card"; import { RiDeleteBin5Line, RiEyeLine, RiPencilLine } from "@remixicon/react"; import { CheckIcon } from "lucide-react"; import { useMemo } from "react"; import type { Note } 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; } export function NoteCard({ note, onEdit, onDetails, onRemove }: NoteCardProps) { const { formattedDate, 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 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: "remover", icon: , onClick: onRemove, variant: "destructive" as const, }, ].filter((action) => typeof action.onClick === "function"); return (

{displayTitle}

{isTask && ( {completedCount}/{totalCount} concluídas )}
{formattedDate}
{isTask ? (
{tasks.slice(0, 4).map((task) => (
{task.completed && ( )}
{task.text}
))} {tasks.length > 4 && (

+{tasks.length - 4}{" "} {tasks.length - 4 === 1 ? "tarefa" : "tarefas"}...

)}
) : (

{note.description}

)}
{actions.length > 0 ? ( {actions.map(({ label, icon, onClick, variant }) => ( ))} ) : null}
); }