// Safari Compatibility Test Script
// Run this in a Safari browser console on the find-a-trainer page

console.log('=== Safari Compatibility Test ===');

// Test 1: Check if Safari-compatible script is loaded
console.log('1. Checking script sources...');
const scripts = Array.from(document.querySelectorAll('script[src*="find-trainer"]'));
const safariScript = scripts.find(s => s.src.includes('safari-compatible'));
const regularScript = scripts.find(s => s.src.includes('find-trainer.js') && !s.src.includes('safari-compatible'));

console.log('Scripts found:', scripts.map(s => s.src));
console.log('Safari-compatible script loaded:', !!safariScript);
console.log('Regular script loaded:', !!regularScript);

// Test 2: Check if hvac_find_trainer object exists
console.log('2. Checking localized data...');
console.log('hvac_find_trainer exists:', typeof hvac_find_trainer !== 'undefined');
if (typeof hvac_find_trainer !== 'undefined') {
    console.log('Browser info:', hvac_find_trainer.browser_info);
}

// Test 3: Check if jQuery is working
console.log('3. Checking jQuery...');
console.log('jQuery loaded:', typeof $ !== 'undefined');
console.log('jQuery version:', typeof $ !== 'undefined' ? $.fn.jquery : 'not available');

// Test 4: Check for JavaScript errors
console.log('4. Checking for ES6+ syntax issues...');
try {
    // Try some ES6 features that Safari might not support
    const testArrow = () => 'arrow function works';
    const testTemplate = `template literal works`;
    const testConst = 'const works';
    
    console.log('ES6 arrow functions:', testArrow());
    console.log('ES6 template literals:', testTemplate);
    console.log('ES6 const:', testConst);
} catch (e) {
    console.error('ES6 syntax error:', e.message);
    console.log('✅ This confirms Safari-compatible script should be loaded');
}

// Test 5: Check if find-trainer functionality works
console.log('5. Checking find-trainer elements...');
const filterButtons = document.querySelectorAll('.hvac-filter-btn');
const trainerCards = document.querySelectorAll('.hvac-trainer-card');
const searchBox = document.querySelector('#hvac-trainer-search');

console.log('Filter buttons found:', filterButtons.length);
console.log('Trainer cards found:', trainerCards.length);
console.log('Search box found:', !!searchBox);

// Test 6: Check if click events work
console.log('6. Testing click events...');
if (filterButtons.length > 0) {
    console.log('Filter buttons are interactive:', filterButtons[0].onclick !== null || 
                                                 filterButtons[0].addEventListener !== undefined);
}

console.log('=== Test Complete ===');
console.log('Open browser dev tools and check for JavaScript errors');
console.log('Try clicking filter buttons to test functionality');