import { useState } from 'react' import { useWritingHistory } from '@/hooks/use-writing-history' import { useAuthStore } from '@/store/auth-store' import type { WritingSubmission } from '@/types' function scoreColor(score: string) { const n = parseFloat(score) if (n >= 7) return 'bg-green-100 text-green-700' if (n >= 5) return 'bg-amber-100 text-amber-700' return 'bg-red-100 text-red-700' } function relativeTime(iso: string) { const diff = Date.now() - new Date(iso).getTime() const mins = Math.floor(diff / 60_000) if (mins < 1) return 'vừa xong' if (mins < 60) return `${mins} phút trước` const hours = Math.floor(mins / 60) if (hours < 24) return `${hours} giờ trước` return `${Math.floor(hours / 24)} ngày trước` } function SubmissionCard({ item }: { item: WritingSubmission }) { const [open, setOpen] = useState(false) const fb = item.feedback return (
{open && fb && (

Bài viết gốc

{item.content}

{fb.grammar?.length > 0 && (

Ngữ pháp

    {fb.grammar.map((g, i) => (
  • {g}
  • ))}
)} {fb.vocabulary?.length > 0 && (

Từ vựng

    {fb.vocabulary.map((v, i) => (
  • {v}
  • ))}
)} {fb.structure && (

Cấu trúc

{fb.structure}

)} {fb.summary && (

Tổng nhận xét

{fb.summary}

)}
)}
) } export function WritingHistory() { const user = useAuthStore((s) => s.user) const { data: history, isLoading } = useWritingHistory() if (!user) return null return (

Lịch sử chấm bài

{isLoading && (
Đang tải...
)} {!isLoading && !history?.length && (
history

Chưa có bài nào được chấm.

)} {!!history?.length && (
{history.map((item) => )}
)}
) }