import { useMemo } from 'react' const HealthBar = ({ health }: { health: number }) => { const [barWidths, fillColor] = useMemo(() => { if (!health) return [[0, 0, 0, 0], 'var(--down)'] if (health < 5) { return [[16, 0, 0, 0], 'var(--down)'] } if (health <= 25) { const fillWidth = (health / 25) * 100 return [[fillWidth, 0, 0, 0], 'var(--down)'] } if (health <= 50) { const fillWidth = ((health - 25) / 25) * 100 return [[100, fillWidth, 0, 0], 'var(--warning)'] } if (health <= 75) { const fillWidth = ((health - 50) / 25) * 100 return [[100, 100, fillWidth, 0], 'var(--up)'] } const fillWidth = ((health - 75) / 25) * 100 return [[100, 100, 100, fillWidth], 'var(--up)'] }, [health]) const sharedStyles = { background: fillColor, boxShadow: `0px 0px 8px 0px ${fillColor}`, } return (
) } export default HealthBar