"""司机端首页 — Page Object（App 端）。

Usage:
    from tests.app.pages.driver_home_page import DriverHomePage

    home = DriverHomePage(driver, platform="android")
    home.go_to_order_list()
"""

from appium.webdriver.webdriver import WebDriver

from tests.app.pages.base_page import AppBasePage


class DriverHomePage(AppBasePage):
    """运八司机端 APP 首页。"""

    def __init__(self, driver: WebDriver, platform: str = "android"):
        super().__init__(driver, platform)
        # ⚠️ 以下 accessibility_id 需要根据实际 APP UI 确认
        self.order_tab = "tab_orders"           # 运单 tab
        self.mine_tab = "tab_mine"              # 我的 tab
        self.home_tab = "tab_home"              # 首页 tab
        self.notification_badge = "badge_notification"

    def is_displayed(self) -> bool:
        """检查首页是否已展示。"""
        try:
            self.wait_visible_by_id(self.home_tab, timeout_s=10)
            return True
        except Exception:
            return False

    def go_to_order_list(self) -> None:
        """点击进入运单列表。"""
        self.tap_by_id(self.order_tab)

    def go_to_mine(self) -> None:
        """点击进入「我的」页面。"""
        self.tap_by_id(self.mine_tab)

    def get_notification_count(self) -> str:
        """获取通知角标数量。"""
        element = self.driver.find_element(
            self.driver.find_element.ACCESSIBILITY_ID, self.notification_badge
        )
        return element.text if element else "0"
