import logging
from typing import Callable

from rio import Component
from src.ezgg_lan_manager.components.LoginBox import LoginBox
from src.ezgg_lan_manager.components.UserInfoBox import UserInfoBox
from src.ezgg_lan_manager.types.UserSession import UserSession

logger = logging.getLogger(__name__.split(".")[-1])

class UserInfoAndLoginBox(Component):
    state_changed_cb: Callable
    def build(self) -> Component:
        try:
            user_id = self.session[UserSession].user_id
            return UserInfoBox(status_change_cb=self.state_changed_cb, user_id=user_id)
        except KeyError:
            return LoginBox(status_change_cb=self.state_changed_cb)
