// utils/formatDate.ts
export interface FormatDateOptions {
  showDate?: boolean;
  showTime?: boolean;
  withWIB?: boolean;
  locale?: string;
}

export function formatDate(
  dateInput: string | Date,
  options: FormatDateOptions = { showDate: true, showTime: true, withWIB: true }
): string {
  const {
    showDate = true,
    showTime = true,
    withWIB = true,
    locale = "id-ID",
  } = options;

  const date = new Date(dateInput);
  const parts: string[] = [];

  if (showDate) {
    const tanggal = new Intl.DateTimeFormat(locale, {
      day: "2-digit",
      month: "long",
      year: "numeric",
    }).format(date);
    parts.push(tanggal);
  }

  if (showTime) {
    const waktu = new Intl.DateTimeFormat(locale, {
      hour: "2-digit",
      minute: "2-digit",
      hour12: false,
    }).format(date);
    parts.push(`${waktu}${withWIB ? " WIB" : ""}`);
  }

  return parts.join(", ");
}
