"use client"; import { useEffect, useState } from "react"; import { cn } from "@/lib/utils"; import { playChaosRiser } from "@/lib/sounds"; type Props = { markedCount: number; totalItems: number; }; export function ChaosMeter({ markedCount, totalItems }: Props) { const [prevCount, setPrevCount] = useState(markedCount); const ratio = totalItems > 0 ? markedCount / totalItems : 0; const percent = Math.round(ratio * 100); useEffect(() => { if (markedCount > prevCount && markedCount % 3 === 0) { playChaosRiser(); } setPrevCount(markedCount); }, [markedCount, prevCount]); const stage = ratio < 0.25 ? "stable" : ratio < 0.5 ? "unstable" : ratio < 0.75 ? "critical" : "meltdown"; const stageLabels: Record = { stable: "✅ Sub stable", unstable: "⚠️ Leaking", critical: "🚨 MELTDOWN", meltdown: "☢️ NUKE", }; return (
{stageLabels[stage]} {percent}% chaos
); }