const parseLocalDate = (dateStr) => {
  if (!dateStr) return null;

  const iso = dateStr.match(/^(\d{4})-(\d{2})-(\d{2})/);
  if (iso) return new Date(+iso[1], +iso[2] - 1, +iso[3]);
  const dmy = dateStr.match(/^(\d{2})\/(\d{2})\/(\d{4})/);
  if (dmy) return new Date(+dmy[3], +dmy[2] - 1, +dmy[1]);
  return null;
};

const formatWeekday = (dateStr) => {
  const d = parseLocalDate(dateStr);
  if (!d) return "";
  const w = d.toLocaleDateString("pt-BR", { weekday: "long" });
  return w.charAt(0).toUpperCase() + w.slice(1);
};

const formatDayMonth = (dateStr) => {
  const d = parseLocalDate(dateStr);
  if (!d) return "";
  return d.toLocaleDateString("pt-BR", { day: "2-digit", month: "2-digit" });
};

export { parseLocalDate, formatWeekday, formatDayMonth };
