from aiogram import Router, F
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from aiogram.types import Message

from bot import BotInfo
from bot.utils import status_clear
from configs import COMMANDS
from middleware.loggers import logger

__all__ = ("router",)
CMD: str = "cancel".casefold()
router: Router = Router(name=f"{CMD}_cmd_router")


@router.callback_query(F.data.casefold() == CMD)
@router.message(Command(*COMMANDS[CMD], prefix=BotInfo.prefix, ignore_case=True))
@router.message(F.text.casefold().in_(COMMANDS[CMD]))
async def cancel_handler(message: Message, state: FSMContext, text: str = "❌ Отмена предыдущего действия!"):
    """
    Позволяет пользователю отменить процесс смены описания
    """
    await status_clear(message=message, state=state)

    logger.info(text=text)

    await message.answer(text)
