from typing import Optional, override

from .framework import Widget


class GestureDetector(Widget):
    def __init__(
        self,
        *,
        key=None,
        onTap=None,
        onPanStart=None,
        onPanUpdate=None,
        onPanEnd=None,
        child: Optional[Widget] = None,
    ):
        super().__init__("GestureDetector", key=key)
        self.onTap = onTap
        self.onPanStart = onPanStart
        self.onPanUpdate = onPanUpdate
        self.onPanEnd = onPanEnd
        self.child = child

    @override
    def _flut_pack(self) -> dict:
        result = self._flut_base_props()
        if self.onTap is not None:
            result["onTapId"] = self._register_action(self.onTap)
        if self.onPanStart is not None:
            result["onPanStartId"] = self._register_action(self.onPanStart)
        if self.onPanUpdate is not None:
            result["onPanUpdateId"] = self._register_action(self.onPanUpdate)
        if self.onPanEnd is not None:
            result["onPanEndId"] = self._register_action(self.onPanEnd)
        if self.child is not None:
            result["child"] = self.child._flut_pack()
        return result
