import typing
from typing_extensions import Unpack
from datetime import time
from instaui.components.element import Element
from instaui.vars.types import TMaybeRef
from instaui.arco import component_types
from instaui.event.event_mixin import EventMixin
from ._utils import handle_props, try_setup_vmodel

_TTimePickerValue = typing.Union[
    str, int, time, typing.List[typing.Union[str, int, time]]
]


class TimePicker(Element):
    def __init__(
        self,
        value: typing.Optional[TMaybeRef[_TTimePickerValue]] = None,
        **kwargs: Unpack[component_types.TTimepicker],
    ):
        super().__init__("a-time-picker")

        try_setup_vmodel(self, value)
        self.props(handle_props(kwargs))  # type: ignore

    def on_change(
        self,
        handler: EventMixin,
        *,
        extends: typing.Optional[typing.List] = None,
    ):
        self.on(
            "change",
            handler,
            extends=extends,
        )
        return self

    def on_select(
        self,
        handler: EventMixin,
        *,
        extends: typing.Optional[typing.List] = None,
    ):
        self.on(
            "select",
            handler,
            extends=extends,
        )
        return self

    def on_clear(
        self,
        handler: EventMixin,
        *,
        extends: typing.Optional[typing.List] = None,
    ):
        self.on(
            "clear",
            handler,
            extends=extends,
        )
        return self

    def on_popup_visible_change(
        self,
        handler: EventMixin,
        *,
        extends: typing.Optional[typing.List] = None,
    ):
        self.on(
            "popup-visible-change",
            handler,
            extends=extends,
        )
        return self
