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)


def get_settings_keyboard(settings: dict) -> InlineKeyboardMarkup:
    """Create keyboard for notification settings."""
    # Get current values with defaults
    notify_events = settings.get("notify_events", True)
    notify_disputes = settings.get("notify_disputes", True)
    notify_moderation = settings.get("notify_moderation", True)

    # Status indicators
    events_status = "✅" if notify_events else "❌"
    disputes_status = "✅" if notify_disputes else "❌"
    moderation_status = "✅" if notify_moderation else "❌"

    buttons = [
        [
            InlineKeyboardButton(
                text=f"{events_status} События (Golden Hour, Jackpot...)",
                callback_data="toggle:notify_events"
            )
        ],
        [
            InlineKeyboardButton(
                text=f"{disputes_status} Споры",
                callback_data="toggle:notify_disputes"
            )
        ],
        [
            InlineKeyboardButton(
                text=f"{moderation_status} Модерация (игры/челленджи)",
                callback_data="toggle:notify_moderation"
            )
        ],
        [
            InlineKeyboardButton(
                text="◀️ Назад",
                callback_data="back_to_menu"
            )
        ]
    ]

    return InlineKeyboardMarkup(inline_keyboard=buttons)
