"""Admin keyboard definitions."""

from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton


def get_admin_main_menu() -> InlineKeyboardMarkup:
    """Main admin panel keyboard."""
    return InlineKeyboardMarkup(
        inline_keyboard=[
            [InlineKeyboardButton(text="➕ افزودن مسابقه", callback_data="admin_add_match")],
            [InlineKeyboardButton(text="⚽ مدیریت مسابقات", callback_data="admin_manage_matches")],
            [InlineKeyboardButton(text="🏁 ثبت نتیجه مسابقه", callback_data="admin_record_result")],
            [InlineKeyboardButton(text="👥 کاربران", callback_data="admin_users")],
            [InlineKeyboardButton(text="📊 آمار", callback_data="admin_stats")],
            [InlineKeyboardButton(text="📢 ارسال پیام همگانی", callback_data="admin_broadcast")],
            [InlineKeyboardButton(text="📁 خروجی اکسل", callback_data="admin_export_excel")],
            [InlineKeyboardButton(text="🔎 جستجوی کاربر", callback_data="admin_search_user")]
        ]
    )


def get_matches_management_keyboard(matches: list[dict]) -> InlineKeyboardMarkup:
    """Keyboard for managing matches."""
    keyboard = []
    for match in matches:
        team1 = match.get("team1", "")
        team2 = match.get("team2", "")
        match_id = match.get("id", "")
        status = match.get("status", "")

        status_emoji = "✅" if status == "finished" else "⏳" if status == "upcoming" else "🔴"
        button_text = f"{status_emoji} {team1} vs {team2}"
        keyboard.append([
            InlineKeyboardButton(text=button_text, callback_data=f"admin_view_match_{match_id}"),
            InlineKeyboardButton(text="🗑️", callback_data=f"admin_delete_match_{match_id}")
        ])

    keyboard.append([InlineKeyboardButton(text="بازگشت", callback_data="admin_back")])
    return InlineKeyboardMarkup(inline_keyboard=keyboard)


def get_record_result_keyboard(matches: list[dict]) -> InlineKeyboardMarkup:
    """Keyboard for selecting match to record result."""
    keyboard = []
    for match in matches:
        if match.get("status") == "upcoming":
            team1 = match.get("team1", "")
            team2 = match.get("team2", "")
            match_id = match.get("id", "")
            button_text = f"⚽ {team1} vs {team2}"
            keyboard.append([InlineKeyboardButton(text=button_text, callback_data=f"record_result_{match_id}")])

    keyboard.append([InlineKeyboardButton(text="بازگشت", callback_data="admin_back")])
    return InlineKeyboardMarkup(inline_keyboard=keyboard)


def get_broadcast_type_keyboard() -> InlineKeyboardMarkup:
    """Keyboard for selecting broadcast message type."""
    return InlineKeyboardMarkup(
        inline_keyboard=[
            [InlineKeyboardButton(text="📝 متن", callback_data="broadcast_text")],
            [InlineKeyboardButton(text="🖼️ عکس", callback_data="broadcast_photo")],
            [InlineKeyboardButton(text="🎥 ویدیو", callback_data="broadcast_video")],
            [InlineKeyboardButton(text="📎 فایل", callback_data="broadcast_file")],
            [InlineKeyboardButton(text="بازگشت", callback_data="admin_back")]
        ]
    )


def get_admin_back_keyboard() -> InlineKeyboardMarkup:
    """Keyboard with back button for admin panel."""
    return InlineKeyboardMarkup(
        inline_keyboard=[
            [InlineKeyboardButton(text="بازگشت", callback_data="admin_back")]
        ]
    )