"""Обработчик главного меню."""
from maxapi.dispatcher import Router
from maxapi.filters import F
from maxapi.types.updates.message_callback import MessageCallback
from maxapi.context import BaseContext

from bot.keyboards import main_menu_kb
from bot.send_helper import bot_send

router = Router(router_id="menu")


@router.message_callback(F.callback.payload == "main_menu")
async def cb_main_menu(
    event: MessageCallback, context: BaseContext, bot_user: dict
) -> None:
    await context.set_state(None)
    await event.answer(notification="")

    chat_id = event.message.recipient.chat_id if event.message else None
    if chat_id is None:
        return

    await bot_send(
        event.bot,
        chat_id=chat_id,
        user_id=bot_user["max_user_id"],
        text="Главное меню:",
        attachments=[main_menu_kb()],
    )
