class tables:
    @staticmethod
    def print_table(data: dict, sum_row: dict = None):
        """
        print a formatted table from a dict
        :param data: dict with column names as keys and list of column values
        :param sum_row: optional dict with the same keys for a sum/total row
        """
        # Berechne die maximale Breite jeder Spalte (Header vs. Inhalte vs. Summe)
        col_widths = {}
        for k, v in data.items():
            max_content_len = max((len(str(name)) for name in v), default=0)
            header_len = len(k)
            sum_len = len(str(sum_row[k])) if sum_row and k in sum_row else 0
            col_widths[k] = max(max_content_len, header_len, sum_len)

        # Header drucken
        header = " | ".join(k.ljust(col_widths[k]) for k in data.keys())
        separator = "-+-".join("-" * col_widths[k] for k in data.keys())
        print(header)
        print(separator)

        # Zeilen drucken
        max_len = max(len(v) for v in data.values())
        for i in range(max_len):
            row = []
            for key in data.keys():
                if i < len(data[key]):
                    row.append(str(data[key][i]).ljust(col_widths[key]))
                else:
                    row.append(" " * col_widths[key])
            print(" | ".join(row))

        # Summe drucken, falls übergeben
        if sum_row:
            print(separator)
            sum_line = " | ".join(str(sum_row[k]).ljust(col_widths[k]) for k in data.keys())
            print(sum_line)
