"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 } 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 { 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: 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 ? (
{tasks.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 }) => ( ))} ) : null}
); }