//! HTML template generation utilities

use super::routing;
use super::styles;

/// Apply HTML template to content
pub fn apply_template(template: &str, title: &str, content: &str) -> String {
    template
        .replace("{{title}}", title)
        .replace("{{content}}", content)
}

/// Create default HTML template with content
pub fn create_default_html(
    title: &str,
    content: &str,
    content_type: &str,
    language: &str,
) -> String {
    let back_link = routing::generate_back_link(content_type, language);
    let css_styles = styles::get_default_css_styles();

    format!(
        r#"<!DOCTYPE html>
<html lang="{}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{}</title>
    <style>
        {}
    </style>
</head>
<body>
    {}
    <main>
        {}
    </main>
</body>
</html>"#,
        language, title, css_styles, back_link, content
    )
}

/// Create full-featured HTML template with enhanced metadata
pub fn create_default_full_html(
    title: &str,
    content: &str,
    content_type: &str,
    language: &str,
    metadata_html: &str,
) -> String {
    let back_link = routing::generate_back_link(content_type, language);
    let css_styles = styles::get_full_css_styles();

    // Insert metadata after title if provided
    let enhanced_content = if !metadata_html.is_empty() {
        super::metadata::insert_metadata_after_title(content, metadata_html)
    } else {
        content.to_string()
    };

    format!(
        r#"<!DOCTYPE html>
<html lang="{}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{}</title>
    <style>
        {}
    </style>
</head>
<body>
    {}
    <main>
        {}
    </main>
</body>
</html>"#,
        language, title, css_styles, back_link, enhanced_content
    )
}
