from typing import Optional, override

from flut.flutter.widgets.framework import Widget


class AppBar(Widget):

    def __init__(
        self,
        *,
        key=None,
        leading: Optional[Widget] = None,
        title: Optional[Widget] = None,
        actions=None,
        elevation: Optional[float] = None,
        scrolledUnderElevation: Optional[float] = None,
        backgroundColor=None,
        centerTitle: Optional[bool] = None,
    ):
        super().__init__("AppBar", key=key)
        self.leading = leading
        self.title = title
        self.actions = actions
        self.elevation = elevation
        self.scrolledUnderElevation = scrolledUnderElevation
        self.backgroundColor = backgroundColor
        self.centerTitle = centerTitle

    @override
    def _flut_pack(self) -> dict:
        result = self._flut_base_props()
        if self.leading is not None:
            result["leading"] = self.leading._flut_pack()
        if self.title is not None:
            result["title"] = self.title._flut_pack()
        if self.actions is not None:
            result["actions"] = [a._flut_pack() for a in self.actions]
        if self.elevation is not None:
            result["elevation"] = self.elevation
        if self.scrolledUnderElevation is not None:
            result["scrolledUnderElevation"] = self.scrolledUnderElevation
        if self.backgroundColor is not None:
            result["backgroundColor"] = self.backgroundColor._flut_pack()
        if self.centerTitle is not None:
            result["centerTitle"] = self.centerTitle
        return result
