import {Module} from "@/interfaces";
import clsx from "clsx";

interface Props {
	label: string;
	percentage: number;
	color: "red" | "rose" | "purple" | Module;
	useColor?: boolean;
	className?: string;
	textClassName?: string;
}

export default function ProgressBar({label, percentage, color, useColor = false, className, textClassName}: Props) {
	const progressColorClass: {[key in typeof color]: string} = {
		red: "bg-mti-red-light",
		rose: "bg-mti-rose-light",
		purple: "bg-mti-purple-light",
		reading: "bg-ielts-reading",
		listening: "bg-ielts-listening",
		writing: "bg-ielts-writing",
		speaking: "bg-ielts-speaking",
	};

	return (
		<div
			className={clsx(
				"relative rounded-full overflow-hidden flex items-center justify-center",
				className,
				!useColor ? "bg-mti-gray-anti-flash" : progressColorClass[color],
				useColor && "bg-opacity-20",
			)}>
			<div
				style={{width: `${percentage}%`}}
				className={clsx("absolute transition-all duration-300 ease-in-out top-0 left-0 h-full overflow-hidden", progressColorClass[color])}
			/>
			<span className={clsx("z-[1] justify-self-center text-white text-sm font-bold", textClassName)}>{label}</span>
		</div>
	);
}
