export const formatDate = (date) => {
  const d = new Date(date);
  const month = String(d.getMonth() + 1).padStart(2, '0');
  const day = String(d.getDate()).padStart(2, '0');
  const year = d.getFullYear();
  return `${year}-${month}-${day}`;
};

export const formatCurrency = (amount) => {
  return new Intl.NumberFormat('en-RW', {
    style: 'currency',
    currency: 'RWF',
    minimumFractionDigits: 0,
  }).format(amount);
};

export const getDateRange = (type) => {
  const today = new Date();
  const startDate = new Date();

  if (type === 'daily') {
    startDate.setDate(today.getDate());
  } else if (type === 'weekly') {
    startDate.setDate(today.getDate() - 7);
  } else if (type === 'monthly') {
    startDate.setMonth(today.getMonth());
    startDate.setDate(1);
  }

  return {
    startDate: formatDate(startDate),
    endDate: formatDate(today),
  };
};
