from typing import Optional, override

from flut.flutter.widgets.framework import Widget


class Checkbox(Widget):
    def __init__(
        self,
        *,
        key=None,
        value: Optional[bool] = None,
        tristate: bool = False,
        onChanged=None,
        activeColor=None,
        checkColor=None,
        autofocus: bool = False,
    ):
        super().__init__("Checkbox", key=key)
        self.value = value
        self.tristate = tristate
        self.onChanged = onChanged
        self.activeColor = activeColor
        self.checkColor = checkColor
        self.autofocus = autofocus

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