from latex_components_generator import generate_latex_image
import latex_components_generator

def generate_latex_document(
    title: str,
    tables: list[list[list]] = None,
    images: list[tuple[str, int, int]] = None,
    output_file: str = "generated_document.tex"
) -> None:
    """
    Generate a complete LaTeX document with tables and images.
    
    Args:
        title: Title of the document
        tables: List of 2D lists, where each inner list represents a table
        images: List of tuples (filepath, width, height) for images
        output_file: Path to save the generated LaTeX file
    """
    # Start building the document
    latex_code = [
        "\\documentclass{article}",
        "\\usepackage{graphicx}",
        "\\usepackage{booktabs}",
        "\\usepackage{array}",
        "",
        "\\begin{document}",
        f"\\title{{{title}}}",
        "\\author{Generated by LaTeX Document Generator}",
        "\\date{\\today}",
        "\\maketitle",
        ""
    ]
    
    # Add tables if provided
    if tables:
        latex_code.append("\\section{Tables}")
        for table_data in tables:
            latex_code.append(generate_latex_table(table_data))
            latex_code.append("")  # Add some space between tables
    
    # Add images if provided
    if images:
        latex_code.append("\\section{Images}")
        for filepath, width, height in images:
            latex_code.append(generate_latex_image(filepath, width, height))
            latex_code.append("")  # Add some space between images
    
    # Close the document
    latex_code.extend([
        "\\end{document}"
    ])
    
    # Write to file
    with open(output_file, "w") as f:
        f.write("\n".join(latex_code))

def main():
    # Example usage
    sample_tables = [
        [
            ["Name", "Age", "City"],
            ["John Doe", "25", "New York"],
            ["Jane Smith", "30", "London"]
        ],
        [
            ["Product", "Price", "Stock"],
            ["Item 1", "$10", "100"],
            ["Item 2", "$20", "50"]
        ]
    ]
    
    sample_images = [
        ("path/to/image1.jpg", 800, 600),
        ("path/to/image2.jpg", 600, 400)
    ]
    
    generate_latex_document(
        title="Sample Generated Document",
        tables=sample_tables,
        images=sample_images,
        output_file="sample_document.tex"
    )

if __name__ == "__main__":
    main()


