//! Fluent Localization System
//!
//! This module provides content-agnostic functionality including:
//! - FTL file parsing and handling
//! - Generic content management and loading
//! - Modular content system with types, models, metadata, markdown processing,
//!   loaders, and resolvers

pub mod content_loader;
pub mod content_traits;
pub mod ftl;
pub mod ftl_parser;

// Modular content system
pub mod loaders;
pub mod markdown;
pub mod metadata;
pub mod models;
pub mod resolvers;
pub mod types;

// Re-export content loader functionality
pub use content_loader::{load_texts_from_ftl, HashMapTexts};
// Re-export content traits
#[cfg(target_arch = "wasm32")]
pub use content_traits::AsyncContentLoader;
pub use content_traits::{
    ContentLoadError, ContentLoader, ContentResult, PathResolvingContentLoader,
    StandardContentLoader,
};
// Re-export FTL types and functionality
pub use ftl::{ComponentKeys, FtlKeys, PageKeys};
pub use ftl_parser::{FtlParseResult, FtlParser, TranslationKey, TranslationSection};
// Content-agnostic modular system re-exports
pub use loaders::{
    load_content_by_slug, load_content_by_type, load_content_index, load_filter_index,
    load_markdown_content,
};
pub use markdown::{
    generate_slug, process_markdown_file, rewrite_content_image_paths, MarkdownProcessor,
};
pub use metadata::{ContentMetadata, ContentQuery, ContentTemplate, MarkdownMetadata};
pub use models::{ContentIndex, ContentPost, FilterIndex, MarkdownPage, PageContent};
pub use resolvers::{
    resolve_content_slug, resolve_content_slug_with_language_priority, resolve_slug,
};
pub use types::{ContentFormat, ContentState, ContentType, SlugResolution};

// Helper functions
pub fn get_content_path(content_type: &str, language: &str, filename: &str) -> String {
    let config = crate::config::ContentManageConfig::from_env();
    config
        .content_path(content_type, language, filename)
        .to_string_lossy()
        .to_string()
}

pub fn get_html_path(content_type: &str, language: &str, slug: &str) -> String {
    let server_root = crate::generated_config::get_server_content_url();
    format!("{server_root}/{content_type}/{language}/{slug}.html")
}

pub fn get_html_path_with_category(
    content_type: &str,
    language: &str,
    slug: &str,
    category: Option<&str>,
) -> String {
    let server_root = crate::generated_config::get_server_content_url();
    match category {
        Some(cat) => format!("{server_root}/{content_type}/{language}/{cat}/{slug}.html"),
        None => format!("{server_root}/{content_type}/{language}/{slug}.html"),
    }
}
