export default {
	mounted(el, binding) {
		const value = binding.value;
		if (value !== undefined && value !== null) {
			el.textContent = formatNumber(value);
		}
	},
	updated(el, binding){
		const value = binding.value;
		if (value !== undefined && value !== null) {
			el.textContent = formatNumber(value);
		}
	},
	unmounted(el){
		el.removeEventListener('click', el.handler)
	}
}

function formatNumber(num) {
	if (num === null || num === undefined) {
		return '';
	}

	const parts = num.toString().split('.');
	parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
	return parts.join('.');
}
