export function fmtDateTime(d) {
  if (!d) return "";
  try {
    const dt = new Date(d);
    const datePart = dt.toLocaleDateString("sl-SI", {
      year: "numeric",
      month: "2-digit",
      day: "2-digit",
    });
    const timePart = dt.toLocaleTimeString("sl-SI", {
      hour: "2-digit",
      minute: "2-digit",
      hour12: false,
    });
    return `${datePart} ${timePart}`;
  } catch (e) {
    return String(d);
  }
};

export function fmtCurrency(value) {
  const n = Number(value ?? 0);
  try {
    return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(
      n
    );
  } catch (e) {
    return `${n.toFixed(2)} €`;
  }
}

export function fmtDateDMY(value) {
  if (!value) return "-";
  const d = new Date(value);
  if (isNaN(d)) return "-";
  const dd = String(d.getDate()).padStart(2, "0");
  const mm = String(d.getMonth() + 1).padStart(2, "0");
  const yyyy = d.getFullYear();
  return `${dd}.${mm}.${yyyy}`;
}