export const formatDate = (dateString: string): string => {
  const date = new Date(dateString);
  return new Intl.DateTimeFormat("fa-IR", {
    year: "numeric",
    month: "long",
    day: "numeric",
    hour: "2-digit",
    minute: "2-digit",
  }).format(date);
};

export const formatDateShort = (dateString: string): string => {
  const date = new Date(dateString);
  return new Intl.DateTimeFormat("fa-IR", {
    year: "numeric",
    month: "short",
    day: "numeric",
  }).format(date);
};

export const formatOptionalDate = (
  value?: string | null,
  options?: Intl.DateTimeFormatOptions
): string => {
  if (!value) {
    return "-";
  }
  const date = new Date(value);
  if (Number.isNaN(date.getTime())) {
    return "-";
  }
  return new Intl.DateTimeFormat(
    "fa-IR",
    options ?? {
      year: "numeric",
      month: "2-digit",
      day: "2-digit",
    }
  ).format(date);
};

export const formatFaNumber = (value?: number | null): string => {
  if (value === undefined || value === null || Number.isNaN(value)) {
    return "0";
  }
  return value.toLocaleString("fa-IR");
};

export const formatPrice = (price: number): string => {
  return (
    new Intl.NumberFormat("fa-IR", {
      minimumFractionDigits: 0,
    }).format(price) + " تومان"
  );
};
