from typing import override

from flut.flutter.widgets.framework import Widget


class Switch(Widget):
    def __init__(
        self,
        *,
        key=None,
        value: bool,
        onChanged=None,
        activeThumbColor=None,
        activeTrackColor=None,
        inactiveThumbColor=None,
        inactiveTrackColor=None,
        autofocus: bool = False,
    ):
        super().__init__("Switch", key=key)
        self.value = value
        self.onChanged = onChanged
        self.activeThumbColor = activeThumbColor
        self.activeTrackColor = activeTrackColor
        self.inactiveThumbColor = inactiveThumbColor
        self.inactiveTrackColor = inactiveTrackColor
        self.autofocus = autofocus

    @override
    def _flut_pack(self) -> dict:
        result = self._flut_base_props()
        result["value"] = self.value
        result["onChangedId"] = self._register_action(self.onChanged) if self.onChanged is not None else None
        result["autofocus"] = self.autofocus
        if self.activeThumbColor is not None:
            result["activeThumbColor"] = self.activeThumbColor._flut_pack()
        if self.activeTrackColor is not None:
            result["activeTrackColor"] = self.activeTrackColor._flut_pack()
        if self.inactiveThumbColor is not None:
            result["inactiveThumbColor"] = self.inactiveThumbColor._flut_pack()
        if self.inactiveTrackColor is not None:
            result["inactiveTrackColor"] = self.inactiveTrackColor._flut_pack()
        return result
