from pathlib import Path
import typer
import pandas as pd
from .core import render

app = typer.Typer()


@app.command()
def convert(
    input_file: Path = typer.Argument(..., help="Input CSV, Excel, or markdown table file"),
    output_file: Path = typer.Argument(..., help="Output PNG image file"),
    font_size: int = typer.Option(14, "-s", "--size", help="Font size"),
):
    """Convert CSV/Excel/markdown table file to PNG image."""
    # Detect file type and read accordingly
    if input_file.suffix.lower() in ['.xlsx', '.xls']:
        df = pd.read_excel(input_file)
    elif input_file.suffix.lower() == '.md':
        # Read markdown table using pandas
        df = pd.read_csv(input_file, sep='|', skipinitialspace=True)
    else:
        df = pd.read_csv(input_file)

    render(df, output_file, font_size=font_size)
    typer.echo(f"Image saved to {output_file}")


if __name__ == "__main__":
    app()
