export function formatNumber(
    num: number,
    options?: Intl.NumberFormatOptions,
): string {
    return new Intl.NumberFormat('id-ID', options).format(num);
}

export function formatWhatsAppPhone(phone: string): string {
    const digits = phone.replace(/\D/g, '');

    if (digits.startsWith('62')) {
        return digits;
    }

    if (digits.startsWith('0')) {
        return '62' + digits.slice(1);
    }

    return '62' + digits;
}

export type DateFormatStyle = 'full' | 'short' | 'datetime';

export function formatDate(dateString: string, style: DateFormatStyle = 'full'): string {
    const date = new Date(dateString);

    const datePart = date.toLocaleDateString('id-ID', {
        day: '2-digit',
        month: style === 'short' ? 'short' : 'long',
        year: 'numeric',
    });

    if (style === 'short') {
        return datePart;
    }

    const timePart = date.toLocaleTimeString('id-ID', {
        hour: '2-digit',
        minute: '2-digit',
    });

    return `${datePart} ${timePart}`;
}

export function formatShortDate(dateString: string): string {
    return formatDate(dateString, 'short');
}

export function formatDateTime(dateString: string): string {
    return formatDate(dateString, 'datetime');
}
