/**
 * Date Formatter Utility
 * Provides consistent date and time formatting across the application
 */

export class DateFormatter {
  /**
   * Format date and time in a human-readable format
   * Example: "November 20, 2025 at 3:45 PM"
   */
  public static formatDateTime(date: Date | string): string {
    const dateObj = typeof date === 'string' ? new Date(date) : date;

    const options: Intl.DateTimeFormatOptions = {
      year: 'numeric',
      month: 'long',
      day: 'numeric',
      hour: 'numeric',
      minute: '2-digit',
      hour12: true,
    };

    return dateObj.toLocaleString('en-US', options);
  }

  /**
   * Format date only (no time)
   * Example: "November 20, 2025"
   */
  public static formatDate(date: Date | string): string {
    const dateObj = typeof date === 'string' ? new Date(date) : date;

    const options: Intl.DateTimeFormatOptions = {
      year: 'numeric',
      month: 'long',
      day: 'numeric',
    };

    return dateObj.toLocaleDateString('en-US', options);
  }

  /**
   * Format time only (no date)
   * Example: "3:45 PM"
   */
  public static formatTime(date: Date | string): string {
    const dateObj = typeof date === 'string' ? new Date(date) : date;

    const options: Intl.DateTimeFormatOptions = {
      hour: 'numeric',
      minute: '2-digit',
      hour12: true,
    };

    return dateObj.toLocaleTimeString('en-US', options);
  }

  /**
   * Format date and time with timezone
   * Example: "November 20, 2025 at 3:45 PM EST"
   */
  public static formatDateTimeWithTimezone(date: Date | string): string {
    const dateObj = typeof date === 'string' ? new Date(date) : date;

    const options: Intl.DateTimeFormatOptions = {
      year: 'numeric',
      month: 'long',
      day: 'numeric',
      hour: 'numeric',
      minute: '2-digit',
      hour12: true,
      timeZoneName: 'short',
    };

    return dateObj.toLocaleString('en-US', options);
  }

  /**
   * Format for email templates with date and time on separate lines
   * Returns an object with separate date and time strings
   */
  public static formatForEmail(date: Date | string): {
    dateTime: string;
    date: string;
    time: string;
  } {
    return {
      dateTime: this.formatDateTime(date),
      date: this.formatDate(date),
      time: this.formatTime(date),
    };
  }
}
