import { JSX } from 'preact/jsx-runtime'

export const currencyFormat = new Intl.NumberFormat('en-US', {
	style: 'currency',
	currency: 'USD',
	maximumFractionDigits: 2,
	minimumFractionDigits: 2,
})

export function Currency(
	{ amount, ...props }:
		& { amount: number }
		& JSX.HTMLAttributes<HTMLSpanElement>,
) {
	return (
		<span class='font-mono' {...props}>
			{currencyFormat.format(amount)}
		</span>
	)
}
