import { format } from "date-fns";

// utils/dateFormatter.js
export function formatDate(date = new Date()): string {
    const d = new Date(date);

    const year = d.getFullYear();
    const month = String(d.getMonth() + 1).padStart(2, '0'); // Months are 0-based
    const day = String(d.getDate()).padStart(2, '0');

    return `${year}-${month}-${day}`;
}

/**
 * Format a date to "dd MMM, yyyy" e.g., "13 Mar, 2026"
 * @param {Date|string|number} date - Date object or parsable date string
 * @returns {string} formatted date
 */
export function formatReadable(date = new Date()): string {
    return format(date, "dd MMM, yyyy");
}

export const getDayName = (date?: Date) => {
    if (!date) return ""
    return format(date, "EEEE")
}


export function displayDate(dateStr: string) {
    const date = new Date(dateStr);
    const formattedDate = date.toLocaleDateString("en-US", { month: "short", day: "numeric" });

    return formattedDate
}