let cachedAddressData = null;
let loadingPromise = null;
/**
 * Lazy load Thai address data from JSON file
 * Data is cached after first load for subsequent calls
 */
export async function loadThaiAddresses() {
    // Return cached data if available
    if (cachedAddressData) {
        return cachedAddressData;
    }
    // Return existing promise if already loading
    if (loadingPromise) {
        return loadingPromise;
    }
    // Start loading the data
    // Use dynamic import instead of fetch for better bundler compatibility
    loadingPromise = import('../assets/thai-addresses.json')
        .then((module) => {
        const data = module.default || module;
        cachedAddressData = data;
        loadingPromise = null;
        return cachedAddressData;
    })
        .catch(error => {
        loadingPromise = null;
        console.error('Error loading Thai addresses:', error);
        throw error;
    });
    return loadingPromise;
}
/**
 * Check if address data is already loaded
 */
export function isAddressDataLoaded() {
    return cachedAddressData !== null;
}
/**
 * Preload address data (optional, for better UX)
 */
export function preloadThaiAddresses() {
    if (!cachedAddressData && !loadingPromise) {
        loadThaiAddresses().catch(() => {
            // Silent fail for preload
        });
    }
}
