/** * Currency Selector Component * Dropdown for selecting donation currency */ (function() { 'use strict'; // Currency selector HTML const selectorHTML = `

Prices are automatically converted from NZD. Your selection is saved for future visits.

`; // Initialize currency selector function initCurrencySelector() { // Find container (should have id="currency-selector-container") const container = document.getElementById('currency-selector-container'); if (!container) { console.warn('Currency selector container not found'); return; } // Insert selector HTML container.innerHTML = selectorHTML; // Get select element const select = document.getElementById('currency-select'); // Set initial value from detected currency const detectedCurrency = detectUserCurrency(); select.value = detectedCurrency; // Trigger initial price update if (typeof window.updatePricesForCurrency === 'function') { window.updatePricesForCurrency(detectedCurrency); } // Listen for changes select.addEventListener('change', function(e) { const newCurrency = e.target.value; // Save preference saveCurrencyPreference(newCurrency); // Update prices if (typeof window.updatePricesForCurrency === 'function') { window.updatePricesForCurrency(newCurrency); } }); } // Auto-initialize when DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCurrencySelector); } else { initCurrencySelector(); } // Expose init function globally window.initCurrencySelector = initCurrencySelector; })();