export const DEFAULT_TIMEZONE = 'America/New_York';

/**
 * Formats an ISO datetime string as a date + time in the given IANA timezone.
 */
export function formatDateTime(
    dateString: string | null,
    timezone: string = DEFAULT_TIMEZONE,
    { includeSeconds = false }: { includeSeconds?: boolean } = {},
): string {
    if (!dateString) {
        return '—';
    }

    return new Date(dateString).toLocaleString('en-US', {
        timeZone: timezone,
        year: 'numeric',
        month: 'short',
        day: 'numeric',
        hour: 'numeric',
        minute: '2-digit',
        second: includeSeconds ? '2-digit' : undefined,
        timeZoneName: 'short',
    });
}

/**
 * Formats an ISO datetime string as a date only, in the given IANA timezone.
 */
export function formatDate(dateString: string | null, timezone: string = DEFAULT_TIMEZONE): string {
    if (!dateString) {
        return '—';
    }

    return new Date(dateString).toLocaleDateString('en-US', {
        timeZone: timezone,
        year: 'numeric',
        month: 'short',
        day: 'numeric',
    });
}
