//! Unified configuration modules
//!
//! This module provides configuration components that work in both SSR and
//! client contexts.

use serde::{Deserialize, Serialize};

pub mod content;
pub mod defs;
pub mod language;

/// Asset loading mode for development vs production
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum AssetMode {
    /// Load individual source files for debugging
    Source,
    /// Load minified bundles for production
    Bundled,
}

impl AssetMode {
    /// Get default asset mode based on environment
    pub fn default_for_environment() -> Self {
        // Check environment variable override first
        if let Ok(mode) = std::env::var("ASSET_MODE") {
            match mode.to_lowercase().as_str() {
                "source" => return AssetMode::Source,
                "bundled" => return AssetMode::Bundled,
                _ => {}
            }
        }

        // Default based on environment detection
        if let Ok(env) = std::env::var("ENVIRONMENT") {
            match env.to_lowercase().as_str() {
                "development" => AssetMode::Source,
                "production" => AssetMode::Bundled,
                _ => AssetMode::Source,
            }
        } else {
            AssetMode::Source // Default to source for development
        }
    }

    /// Check if this is source mode
    #[allow(dead_code)]
    pub fn is_source(&self) -> bool {
        matches!(self, AssetMode::Source)
    }

    /// Check if this is bundled mode
    #[allow(dead_code)]
    pub fn is_bundled(&self) -> bool {
        matches!(self, AssetMode::Bundled)
    }
}

impl Default for AssetMode {
    fn default() -> Self {
        Self::default_for_environment()
    }
}

// Re-export main configuration types
pub use content::{
    get_dynamic_content_config, get_enabled_content_types, is_content_type_enabled,
    is_pages_enabled, DynamicContentConfig,
};
// Re-export configuration definition types for backward compatibility
pub use defs::{AppConfig, ContentManageConfig, LegalConfig, LogoConfig};
// Re-export language configuration
pub use language::{get_default_language, get_supported_languages, is_supported_language};
