//! Minimal Code Element Test
//!
//! Run with: cargo run -p blinc_app --example code_test --features windowed

use blinc_app::prelude::*;
use blinc_app::windowed::{WindowedApp, WindowedContext};
use blinc_core::Color;

fn main() -> Result<()> {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::DEBUG)
        .init();

    let config = WindowConfig {
        title: "Code Test".to_string(),
        width: 800,
        height: 600,
        resizable: true,
        ..Default::default()
    };

    WindowedApp::run(config, |ctx| build_ui(ctx))
}

fn build_ui(ctx: &WindowedContext) -> impl ElementBuilder {
    let simple_code = "fn main() {\n    println!(\"Hello\");\n}";

    // Debug: print what's being passed to code()
    println!("Code content: {:?}", simple_code);

    div()
        .w(ctx.width)
        .h(ctx.height)
        .bg(Color::rgba(0.1, 0.1, 0.15, 1.0))
        .flex_col()
        .gap(20.0)
        .p(32.0)
        // Regular text for comparison
        .child(
            text("Regular text works fine")
                .size(16.0)
                .color(Color::WHITE),
        )
        // Simple code without syntax highlighting
        .child(
            div()
                .flex_col()
                .gap(4.0)
                .child(
                    text("Simple code (no syntax):")
                        .size(14.0)
                        .color(Color::YELLOW),
                )
                .child(code(simple_code).font_size(14.0).w(400.0).h(100.0)),
        )
        // Code with syntax highlighting
        .child(
            div()
                .flex_col()
                .gap(4.0)
                .child(
                    text("With Rust highlighting:")
                        .size(14.0)
                        .color(Color::YELLOW),
                )
                .child(
                    code(simple_code)
                        .syntax(SyntaxConfig::new(RustHighlighter::new()))
                        .font_size(14.0)
                        .w(400.0)
                        .h(100.0),
                ),
        )
        // Code with line numbers
        .child(
            div()
                .flex_col()
                .gap(4.0)
                .child(text("With line numbers:").size(14.0).color(Color::YELLOW))
                .child(
                    code(simple_code)
                        .syntax(SyntaxConfig::new(RustHighlighter::new()))
                        .line_numbers(true)
                        .font_size(14.0)
                        .w(500.0)
                        .h(100.0),
                ),
        )
}
