// Comprehensive test for all date presets
// Run this in the browser console to verify all presets are working correctly

function testAllPresets() {
  console.log('🧪 Testing All Date Presets...');
  
  const today = new Date();
  const todayString = today.toDateString();
  
  console.log('📅 Current Date:', {
    today: todayString,
    todayISO: today.toISOString(),
    todayLocal: today.toLocaleDateString()
  });
  
  // Define all presets with their expected behavior
  const presets = [
    { label: 'Today', from: 0, to: 0, expectedDays: 1 },
    { label: 'Last 2 days', from: -1, to: 0, expectedDays: 2 },
    { label: 'Last 7 days', from: -6, to: 0, expectedDays: 7 },
    { label: 'Last 30 days', from: -29, to: 0, expectedDays: 30 },
    { label: 'Last 90 days', from: -89, to: 0, expectedDays: 90 }
  ];
  
  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);
    
    const dayDifference = Math.floor((toDate - fromDate) / (1000 * 60 * 60 * 24)) + 1;
    const includesToday = toDate.toDateString() === todayString;
    
    console.log(`📅 ${preset.label}:`, {
      from: fromDate.toDateString(),
      to: toDate.toDateString(),
      fromISO: fromDate.toISOString(),
      toISO: toDate.toISOString(),
      fromLocal: fromDate.toLocaleDateString(),
      toLocal: toDate.toLocaleDateString(),
      dayDifference,
      expectedDays: preset.expectedDays,
      includesToday,
      isCorrect: dayDifference === preset.expectedDays && includesToday
    });
  });
  
  // Test the actual preset functions from the component
  console.log('\n🔍 Testing Actual Preset Functions...');
  
  // Simulate the preset functions
  const testPresetFunctions = () => {
    const today = new Date();
    const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate());
    
    const presetFunctions = [
      {
        label: 'Today',
        getRange: () => ({ from: todayStart, to: todayStart })
      },
      {
        label: 'Last 2 days',
        getRange: () => ({
          from: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1),
          to: todayStart
        })
      },
      {
        label: 'Last 7 days',
        getRange: () => ({
          from: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 6),
          to: todayStart
        })
      },
      {
        label: 'Last 30 days',
        getRange: () => ({
          from: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 29),
          to: todayStart
        })
      },
      {
        label: 'Last 90 days',
        getRange: () => ({
          from: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 89),
          to: todayStart
        })
      }
    ];
    
    presetFunctions.forEach(preset => {
      const range = preset.getRange();
      const dayDifference = Math.floor((range.to - range.from) / (1000 * 60 * 60 * 24)) + 1;
      const includesToday = range.to.toDateString() === todayString;
      
      console.log(`🔧 ${preset.label} Function:`, {
        from: range.from.toDateString(),
        to: range.to.toDateString(),
        fromISO: range.from.toISOString(),
        toISO: range.to.toISOString(),
        dayDifference,
        includesToday,
        isCorrect: includesToday
      });
    });
  };
  
  testPresetFunctions();
  
  return '✅ All preset tests completed. Check console for detailed results.';
}

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

module.exports = { testAllPresets };
