from pathlib import Path
from typing import Union
import pandas as pd
from .render import render


class DataFrameToImage:
    """Convert pandas DataFrame to PNG image."""

    def __init__(
        self,
        font_size: int = 14,
        header_bg_color: tuple = (70, 130, 180),  # Steel blue
        header_text_color: tuple = (255, 255, 255),
        cell_bg_color: tuple = (255, 255, 255),
        cell_text_color: tuple = (0, 0, 0),
        margin: int = 10,
    ):
        self.font_size = font_size
        self.header_bg_color = header_bg_color
        self.header_text_color = header_text_color
        self.cell_bg_color = cell_bg_color
        self.cell_text_color = cell_text_color
        self.margin = margin

    def convert(
        self,
        df: pd.DataFrame,
        output_path: Union[str, Path],
        **kwargs
    ):
        """Convert DataFrame to image and save."""
        render(
            df,
            output_path,
            font_size=self.font_size,
            header_bg_color=self.header_bg_color,
            header_text_color=self.header_text_color,
            cell_bg_color=self.cell_bg_color,
            cell_text_color=self.cell_text_color,
            margin=self.margin,
            **kwargs
        )
