# scraper2_hj3415/app/nfs/adapters/out/playwright/capabilities/navigation.py
from __future__ import annotations

from logging_hj3415 import logger

from ._base import _PlaywrightBase  # pyright: ignore[reportPrivateUsage]


class PlaywrightNavigation(_PlaywrightBase):
    async def title(self) -> str:
        return await self._page.title()

    async def current_url(self) -> str:
        return self._page.url

    async def goto_and_wait_for_stable(
        self, url: str, timeout_ms: int = 10_000
    ) -> None:
        logger.info(f"goto: {url}")
        _ = await self._page.goto(
            url, timeout=timeout_ms, wait_until="domcontentloaded"
        )
        await self._wait_for_network_quiet(timeout_ms=timeout_ms // 2)

    async def reload(self, *, timeout_ms: int = 10_000) -> None:
        logger.info("reload")
        _ = await self._page.reload(timeout=timeout_ms, wait_until="domcontentloaded")
