// Test script for date presets
// Run this in the browser console to verify the "Last 2 days" preset is working correctly

function testDatePresets() {
  console.log('🧪 Testing Date Presets...');
  
  const today = new Date();
  const todayString = today.toDateString();
  const yesterdayString = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1).toDateString();
  
  console.log('📅 Current Date Info:', {
    today: todayString,
    yesterday: yesterdayString,
    todayISO: today.toISOString(),
    yesterdayISO: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1).toISOString()
  });
  
  // Test the "Last 2 days" calculation
  const twoDayRange = {
    from: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1),
    to: new Date(today.getFullYear(), today.getMonth(), today.getDate())
  };
  
  console.log('🔍 2-Day Range Test:', {
    from: twoDayRange.from.toDateString(),
    to: twoDayRange.to.toDateString(),
    fromISO: twoDayRange.from.toISOString(),
    toISO: twoDayRange.to.toISOString(),
    isCorrect: twoDayRange.from.toDateString() === yesterdayString && 
              twoDayRange.to.toDateString() === todayString
  });
  
  // Test all presets
  const presets = [
    { label: 'Today', from: 0, to: 0 },
    { label: 'Last 2 days', from: -1, to: 0 },
    { label: 'Last 7 days', from: -6, to: 0 },
    { label: 'Last 30 days', from: -29, to: 0 }
  ];
  
  presets.forEach(preset => {
    const fromDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + preset.from);
    const toDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + preset.to);
    
    console.log(`📅 ${preset.label}:`, {
      from: fromDate.toDateString(),
      to: toDate.toDateString(),
      fromISO: fromDate.toISOString(),
      toISO: toDate.toISOString()
    });
  });
  
  return '✅ Test completed. Check console for results.';
}

// Export for use in browser console
if (typeof window !== 'undefined') {
  window.testDatePresets = testDatePresets;
  console.log('📝 Test function available. Run testDatePresets() to test date presets.');
}

module.exports = { testDatePresets };
