const DateFormat = {
  date: "dd.MM.yyyy",
  dateTime: "dd.MM.yyyy HH:mm",
  dateTimeWithSeparator: "dd.MM.yyyy · HH:mm",
  shortDate: "dd.MM",
};

const Formatter = {
  number: (value?: number, roundTo = 1, precision = 1): string =>
    Number.isNaN(Number(value))
      ? "-"
      : // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
        Intl.NumberFormat("et-EE", {
          maximumFractionDigits: precision,
          minimumFractionDigits: precision,
          style: "decimal",
        }).format(Number(value?.toFixed(roundTo) || 0)),
  percentage: (value?: number, roundTo = 1, precision = 1): string =>
    `${Formatter.number(value, roundTo, precision)} %`,
  temperature: (value?: number): string => `${Formatter.number(value)} °C`,
  withDateFormat(value: Date): string {
    try {
      return value.toISOString();
    } catch (e) {
      // eslint-disable-next-line no-console
      console.warn("Failed to format date", value, e);
      return "-";
    }
  },
};

export { DateFormat, Formatter };
export default Formatter;
