"use client"; import { motion } from "framer-motion"; import Link from "next/link"; import { useState } from "react"; import { BoltIcon, ChevronDownIcon, PlayIcon, XIcon } from "@/components/icons"; import { Button } from "@/components/ui"; import { useI18n } from "@/lib/i18n"; import { springGentle } from "@/lib/motion"; import type { HomeworkRecord } from "@/lib/schemas"; import { useIsPhone } from "@/lib/use-phone"; import { cn, formatDate, truncate } from "@/lib/utils"; /** * One saved homework result in the library's Homework tab: the finished * solution or the step-by-step guide, with open + delete. */ export function HomeworkCard({ record, onDelete, index = 0, }: { record: HomeworkRecord; onDelete: (id: string) => void; /** Position in the list — used for the capped first-load stagger. */ index?: number; }) { const { t, plural } = useI18n(); const isPhone = useIsPhone(); const [confirmDelete, setConfirmDelete] = useState(false); const [expanded, setExpanded] = useState(false); const href = `/homework?open=${record.id}`; const cardVariants = { hidden: { opacity: 0, y: 12 }, show: { opacity: 1, y: 0, transition: { ...springGentle, delay: Math.min(index, 8) * 0.04 } }, exit: { opacity: 0, scale: 0.97, transition: { duration: 0.16 } }, }; const preview = record.mode === "make" ? truncate(record.answer.replace(/\s+/g, " ").trim(), 150) : truncate( record.steps.map((step) => step.title).join(" · "), 150, ); return ( {/* Phones: the whole card opens the result too; the delete button sits above it. */}

{truncate(record.title, 90)}

{record.mode === "make" ? : } {t(record.mode === "make" ? "homework.history.made" : "homework.history.guide")} · {formatDate(record.updatedAt)} {record.mode === "guide" ? ( <> · {plural(record.steps.length, "homework.steps")} ) : null}

{preview ? ( <>

{preview}

) : null}
{confirmDelete ? (
{t("homework.history.deleteConfirm")}
) : ( <> {t("homework.open")} {t("homework.open")}
{t("homework.open")}
)}
); }