from texmemo.types import Card


class CSVFormatter():
    def __init__(self) -> None:
        pass

    def _wrap_latex(self, text: str):
        return f"[latex]\n{text}\n[/latex]"

    def format_csv(self, cards: list[Card], header: bool) -> list[list[str]]:
        csv: list[list[str]] = []
        if header:
            csv.append(["front", "back", "tag"])

        for card in cards:
            csv.append([self._wrap_latex(card.front),
                       self._wrap_latex(card.back), card.tag or ''])

        return csv
