from aiogram import Router, F
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from aiogram.types import Message, CallbackQuery, InlineKeyboardButton
from aiogram.utils.i18n import gettext as _
from aiogram.utils.keyboard import InlineKeyboardBuilder

from bot.core.bots import BotInfo
from bot.filters import IsOwner
from bot.templates import msg
from bot.utils import status_clear
from configs import COMMANDS

# Настройки экспорта и роутера
__all__ = ("router", "settings_keyboard",)
CMD: str = "settings".lower()
router: Router = Router(name=f"{CMD}_cmd_router")


def settings_keyboard() -> InlineKeyboardBuilder:
    """Клавиатура настроек"""
    ikb: InlineKeyboardBuilder = InlineKeyboardBuilder()
    ikb.row(InlineKeyboardButton(text="🔙 Вернуться", callback_data="settings"))
    return ikb


@router.callback_query(F.data.lower() == CMD, IsOwner())
@router.message(Command(*COMMANDS[CMD], prefix=BotInfo.prefix, ignore_case=True), IsOwner())
async def settings_cmd(message: Message | CallbackQuery, state: FSMContext) -> None:
    """Обработчик команды /settings"""
    await status_clear(message=message, state=state)

    # Создание инлайн-клавиатуры
    ikb: InlineKeyboardBuilder = InlineKeyboardBuilder()
    ikb.row(InlineKeyboardButton(text="Имя бота⚜️", callback_data='set_name'))
    ikb.row(InlineKeyboardButton(text="Описание бота📝", callback_data='set_description'))
    ikb.row(InlineKeyboardButton(text="Виджет🧩", callback_data='set_widget'))
    ikb.row(InlineKeyboardButton(text="Назад◀️", callback_data='menu'))

    # Формируем приветственное сообщение
    text: str = _("""
⚙️ Настройки
"""
                  ).format(
    )

    # Отправляем сообщение
    await msg(message=message, text=text, markup=ikb)
