use pdfmake_rust::{ColumnsNode, Document, DocumentNode, Margins, PageSize, PdfMake, Style, TextNode};
use std::fs;

fn main() {
    let doc = Document::builder()
        .page_size(PageSize::a4())
        .page_margins(Margins::all(40.0))
        .content(DocumentNode::Text(TextNode::new("Multi-Column Layout").inline_style(
            Style::new().font_size(20.0).bold(true),
        )))
        .content(create_two_column_layout())
        .content(create_three_column_layout())
        .build();

    let pdf = PdfMake::new();
    let bytes = pdf.render(&doc).expect("Failed to render PDF");

    fs::write("examples/pdfs/multi_column.pdf", &bytes).expect("Failed to write PDF");
    println!("Generated examples/pdfs/multi_column.pdf ({} bytes)", bytes.len());
}

fn create_two_column_layout() -> DocumentNode {
    let left = vec![
        DocumentNode::Text(TextNode::new("Left Column").inline_style(Style::new().bold(true))),
        DocumentNode::text("This is the content of the left column."),
    ];

    let right = vec![
        DocumentNode::Text(TextNode::new("Right Column").inline_style(Style::new().bold(true))),
        DocumentNode::text("This is the content of the right column."),
    ];

    DocumentNode::columns(ColumnsNode::new(vec![left, right]))
}

fn create_three_column_layout() -> DocumentNode {
    let col1 = vec![DocumentNode::text("Column 1")];
    let col2 = vec![DocumentNode::text("Column 2")];
    let col3 = vec![DocumentNode::text("Column 3")];

    DocumentNode::columns(ColumnsNode::new(vec![col1, col2, col3]))
}
