from typing import Optional, override

from .framework import Widget
from ..painting.basic_types import Axis


class ListView(Widget):
    def __init__(
        self,
        *,
        key=None,
        scrollDirection: Axis = Axis.vertical,
        reverse: bool = False,
        controller=None,
        shrinkWrap: bool = False,
        padding=None,
        cacheExtent: Optional[float] = None,
        children: list[Widget] = [],
    ):
        super().__init__("ListView", key=key)
        self.scrollDirection = scrollDirection
        self.reverse = reverse
        self.controller = controller
        self.shrinkWrap = shrinkWrap
        self.padding = padding
        self.cacheExtent = cacheExtent
        self.children = children

    @override
    def _flut_pack(self) -> dict:
        result = self._flut_base_props()
        result["scrollDirection"] = self.scrollDirection._flut_pack()
        result["reverse"] = self.reverse
        result["shrinkWrap"] = self.shrinkWrap
        result["children"] = [c._flut_pack() for c in self.children]
        if self.controller is not None:
            result["controller"] = self.controller._flut_pack()
        if self.padding is not None:
            result["padding"] = self.padding._flut_pack()
        if self.cacheExtent is not None:
            result["cacheExtent"] = self.cacheExtent
        return result
