// Global configuration
export const CONFIG = {
    DEFAULT_LAT: parseFloat(document.querySelector('meta[name="default-lat"]')?.content) || 53.5461,
    DEFAULT_LNG: parseFloat(document.querySelector('meta[name="default-lng"]')?.content) || -113.4938,
    DEFAULT_ZOOM: parseInt(document.querySelector('meta[name="default-zoom"]')?.content) || 11,
    REFRESH_INTERVAL: 30000, // 30 seconds
    MAX_ZOOM: 20,
    MIN_ZOOM: 2,
    domain: null // Will be loaded dynamically
};

// Load domain configuration from server
export async function loadDomainConfig() {
    try {
        const response = await fetch('/api/config/domain');
        if (response.ok) {
            const data = await response.json();
            CONFIG.domain = data.domain;
            updateHomepageLinks();
        } else {
            console.error('Failed to load domain config:', response.status);
        }
    } catch (error) {
        console.error('Error loading domain config:', error);
    }
}

// Update homepage links with the configured domain
function updateHomepageLinks() {
    if (CONFIG.domain) {
        const homepageUrl = `https://homepage.${CONFIG.domain}`;
        const homepageLink = document.getElementById('homepage-link');
        if (homepageLink) {
            homepageLink.href = homepageUrl;
        }
    }
}
