// Initialize tooltips document.addEventListener('DOMContentLoaded', function() { if (feather) { feather.replace(); } setupProjectFilters(); // Smooth scrolling for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); }); // API functions async function fetchClimateData() { try { const response = await fetch('https://api.example.com/climate-data'); return await response.json(); } catch (error) { console.error('Error fetching climate data:', error); return null; } } // Projects Filter Functionality function setupProjectFilters() { const searchInput = document.querySelector('custom-project-filter')?.shadowRoot?.querySelector('.filter-search'); const sectorSelect = document.querySelector('custom-project-filter')?.shadowRoot?.querySelector('.filter-select:nth-of-type(1)'); const statusSelect = document.querySelector('custom-project-filter')?.shadowRoot?.querySelector('.filter-select:nth-of-type(2)'); const sortSelect = document.querySelector('custom-project-filter')?.shadowRoot?.querySelector('.filter-select:nth-of-type(3)'); const resetBtn = document.querySelector('custom-project-filter')?.shadowRoot?.querySelector('.filter-reset'); if (searchInput && sectorSelect && statusSelect && sortSelect) { [searchInput, sectorSelect, statusSelect, sortSelect].forEach(el => { el.addEventListener('change', filterProjects); }); if (resetBtn) { resetBtn.addEventListener('click', () => { searchInput.value = ''; sectorSelect.value = ''; statusSelect.value = ''; sortSelect.value = 'newest'; filterProjects(); }); } } function filterProjects() { // Implement actual filtering logic here console.log('Filtering projects...'); } } // Form validation function validateProjectForm(form) { const requiredFields = form.querySelectorAll('[required]'); let isValid = true; requiredFields.forEach(field => { if (!field.value.trim()) { field.classList.add('border-red-500'); isValid = false; } else { field.classList.remove('border-red-500'); } }); return isValid; }