/**
 * Config Cache Initialization Plugin
 * Simplified config cache initialization
 */

export default defineNuxtPlugin({
  name: 'config-cache-init',
  enforce: 'pre', // Run before other plugins
  async setup() {
    // Only run on client side
    if (typeof window === 'undefined') {
      return;
    }

    // Initialize a flag to prevent multiple initializations
    if ((window as any).__configCacheInitialized) {
      return;
    }

    // Mark as initialized
    (window as any).__configCacheInitialized = true;

    // Initialize the config cache structure if not already present
    if (!(window as any).__configCache) {
      (window as any).__configCache = {
        recaptcha: null,
        registration: null,
        recaptchaLoading: false,
        registrationLoading: false,
        recaptchaError: null,
        registrationError: null
      };
    }

    // Initialize call history for circuit breaker
    if (!(window as any).__configCallHistory) {
      (window as any).__configCallHistory = {};
    }
  }
});
