/* Augment window.MOCK with helpers the screens depend on */
(function () {
  const M = window.MOCK;

  M.MES_LABELS = ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'];

  M.fmtMonShort = (d) => M.MES_LABELS[(d.getMonth ? d.getMonth() : new Date(d).getMonth())];
  M.fmtDayShort = (d) => {
    const dt = d instanceof Date ? d : new Date(d);
    return M.pad(dt.getDate()) + '/' + M.pad(dt.getMonth() + 1);
  };
  M.fmtMonthYear = (d) => {
    const dt = d instanceof Date ? d : new Date(d);
    return M.MES_LABELS[dt.getMonth()] + ' ' + dt.getFullYear();
  };
  M.fmtBRLShort = (v) => {
    const n = Number(v) || 0;
    if (n >= 1e6) return 'R$ ' + (n / 1e6).toFixed(1).replace('.', ',') + 'M';
    if (n >= 1e3) return 'R$ ' + (n / 1e3).toFixed(1).replace('.', ',') + 'k';
    return M.fmtBRL(n);
  };

  M.sameDay = (a, b) => {
    const da = a instanceof Date ? a : new Date(a);
    const db = b instanceof Date ? b : new Date(b);
    return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth() && da.getDate() === db.getDate();
  };
  M.sameDayHoje = (d) => M.sameDay(d, new Date());
  M.thisMonth = (d) => {
    const dt = d instanceof Date ? d : new Date(d);
    const now = new Date();
    return dt.getFullYear() === now.getFullYear() && dt.getMonth() === now.getMonth();
  };

  M.redeById = (id) => M.REDES.find(r => r.id === id);
  M.filialById = (id) => M.FILIAIS.find(f => f.id === id);
  M.unidById = (id) => M.UNIDADES.find(u => u.id === id);
})();
