import ProgressBar from "@/components/Low/ProgressBar"; import useUsers from "@/hooks/useUsers"; import { Module } from "@/interfaces"; import { Assignment } from "@/interfaces/results"; import { calculateBandScore } from "@/utils/score"; import clsx from "clsx"; import moment from "moment"; import { BsBook, BsClipboard, BsHeadphones, BsMegaphone, BsPen, } from "react-icons/bs"; import { usePDFDownload } from "@/hooks/usePDFDownload"; import { uniqBy } from "lodash"; interface Props { onClick?: () => void; allowDownload?: boolean; } export default function AssignmentCard({ id, name, assigner, startDate, endDate, assignees, results, exams, onClick, allowDownload, }: Assignment & Props) { const { users } = useUsers(); const renderPdfIcon = usePDFDownload("assignments"); const calculateAverageModuleScore = (module: Module) => { const resultModuleBandScores = results.map((r) => { const moduleStats = r.stats.filter((s) => s.module === module); const correct = moduleStats.reduce( (acc, curr) => acc + curr.score.correct, 0, ); const total = moduleStats.reduce( (acc, curr) => acc + curr.score.total, 0, ); return calculateBandScore(correct, total, module, r.type); }); return resultModuleBandScores.length === 0 ? -1 : resultModuleBandScores.reduce((acc, curr) => acc + curr, 0) / results.length; }; return (