import { useEffect, useState, useMemo } from 'react';
import {
CheckCircle2, Circle, BookOpen, Users, Search, ChevronLeft, ChevronRight, RefreshCcw, AlertTriangle
} from 'lucide-react';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Skeleton } from '@/components/ui/skeleton';
import { Separator } from '@/components/ui/separator';
import { ScrollArea } from '@/components/ui/scroll-area';
import {
Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, DialogClose,
} from '@/components/ui/dialog';
import {
Pagination, PaginationContent, PaginationItem,
PaginationLink, PaginationPrevious, PaginationNext, PaginationEllipsis,
} from '@/components/ui/pagination';
import { useAdminCourseReadingProgress } from '@/contexts/AdminCourseReadingProgressContext';
import { useDateFormat } from '@/hooks/useDateFormat';
const PAGE_SIZE = 10;
// ─── Helpers ──────────────────────────────────────────────────────────────────
function StatusBadge({ status }) {
if (!status) return Not started;
return status === 'completed'
? Completed
: In Progress;
}
function ProgressBar({ value, total, className = '' }) {
const pct = total > 0 ? Math.round((value / total) * 100) : 0;
return (
{value} / {total}
);
}
// Only relevant once reading is fully done but the course still isn't 'completed' —
// i.e. a still-unpassed unit quiz and/or course assessment is what's blocking it.
function PendingNotice({ entry }) {
const readingDone = entry.lessons_total > 0 && entry.lessons_completed === entry.lessons_total;
if (!readingDone || entry.course_status === 'completed') return null;
if (!entry.quizzes_pending && !entry.assessment_pending) return null;
const parts = [];
if (entry.quizzes_pending > 0) {
parts.push(`${entry.quizzes_pending} quiz${entry.quizzes_pending === 1 ? '' : 'zes'} needed`);
}
if (entry.assessment_pending) parts.push('Assessment needed');
return (