const rupiahFormatter = new Intl.NumberFormat('id-ID', {
	style: 'currency',
	currency: 'IDR',
	minimumFractionDigits: 0,
	maximumFractionDigits: 0
});

const shortRupiahFormatter = new Intl.NumberFormat('id-ID', {
	notation: 'compact',
	compactDisplay: 'short',
	maximumFractionDigits: 1
});

const dayFormatter = new Intl.DateTimeFormat('id-ID', { weekday: 'short' });
const dateFormatter = new Intl.DateTimeFormat('id-ID', {
	day: 'numeric',
	month: 'long',
	year: 'numeric'
});
const timeFormatter = new Intl.DateTimeFormat('id-ID', {
	hour: '2-digit',
	minute: '2-digit'
});

export function formatRupiah(amount: number): string {
	return rupiahFormatter.format(amount);
}

export function formatRupiahShort(amount: number): string {
	if (Math.abs(amount) < 1_000_000) return formatRupiah(amount);
	return `Rp${shortRupiahFormatter.format(amount).replace(/\s/g, '')}`;
}

export function formatPersen(value: number): string {
	const sign = value > 0 ? '+' : '';
	return `${sign}${value.toFixed(1)}%`;
}

export function formatTanggalLengkap(date: Date = new Date()): string {
	return dateFormatter.format(date);
}

export function getHariSingkat(dateStr: string): string {
	return dayFormatter.format(new Date(dateStr)).replace('.', '');
}

export function formatWaktu(dateStr: string): string {
	return timeFormatter.format(new Date(dateStr));
}
