from typing import Any, List, Optional, Union

from ..report_conditions import CustomReportConditions
from ..report_element import CustomReportElement
from ..report_named_resource import CustomReportNamedResource


class GroupTableRenderer(CustomReportElement):
    """Renders grouped data as a set of sub-tables, one per group."""

    def __init__(
        self,
        columns: Union[CustomReportNamedResource, Any],
        group_name: str,
        style: Optional[str] = None,
        group_title: Optional[str] = None,
        group_spacing: Optional[int] = None,
        conditions: Optional[List[CustomReportConditions]] = None,
        spacing: Optional[int] = None,
    ):
        """Creates a GroupTableRenderer.

        Args:
            columns: Resource that defines the column configuration.
            group_name: Name of the group field used to split data into sub-tables.
            style: Optional style identifier.
            group_title: Optional title template displayed above each sub-table.
            group_spacing: Vertical spacing between sub-tables.
            conditions: Export-format conditions that control when this renderer is applied.
            spacing: Vertical spacing before this renderer.
        """
        super().__init__(name="group_tables", conditions=conditions, spacing=spacing)
        self.add_param("columns", columns)
        self.add_param("group_name", group_name)
        self.add_param("style", style)
        self.add_param("group_title", group_title)
        self.add_param("group_spacing", group_spacing)
