from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton


def get_marathons_keyboard(marathons: list) -> InlineKeyboardMarkup:
    """Create keyboard with marathon buttons."""
    buttons = []

    for marathon in marathons:
        status_emoji = {
            "preparing": "⏳",
            "active": "🎮",
            "finished": "🏁"
        }.get(marathon.get("status"), "❓")

        buttons.append([
            InlineKeyboardButton(
                text=f"{status_emoji} {marathon.get('title', 'Marathon')}",
                callback_data=f"marathon:{marathon.get('id')}"
            )
        ])

    return InlineKeyboardMarkup(inline_keyboard=buttons)


def get_marathon_details_keyboard(marathon_id: int) -> InlineKeyboardMarkup:
    """Create keyboard for marathon details view."""
    buttons = [
        [
            InlineKeyboardButton(
                text="🔄 Обновить",
                callback_data=f"marathon:{marathon_id}"
            )
        ],
        [
            InlineKeyboardButton(
                text="◀️ Назад к списку",
                callback_data="back_to_marathons"
            )
        ]
    ]

    return InlineKeyboardMarkup(inline_keyboard=buttons)
