from urllib.parse import urljoin
from shared.config import config
from shared.utils import log
from ...listings import scrape_products

async def capture_category(
    slug: str,
):
    list_url = urljoin(config()["base_url"], f"/{slug}")
    log(f"[{slug}] page 1…")
    items, total_pages = await scrape_products(list_url, page=1)

    pmax = int(total_pages or 1)
    for p in range(2, pmax + 1):
        log(f"[{slug}] page {p}…")
        items_p, _tp = await scrape_products(list_url, page=p)
        items.extend(items_p)
    return (list_url, items, total_pages)
