from typing import Dict, Set
from .capture_category import capture_category
from .capture_sub import capture_sub
from shared.config import config


async def capture_product_slugs(
   nav: Dict[str, Dict],
   capture_listing,
):
    product_slugs: Set[str] = set()
    for label, slug in config()["categories"]["allow"].items():
        lpars = await capture_category( slug)
        await capture_listing(*lpars)
        (_, items, __) = lpars
        for slug_ in items:
            product_slugs.add(slug_)
        for sub in (nav["cats"].get(label, {}).get("subs", []) or []):
            lpars = await capture_sub(sub, slug)
            await capture_listing(*lpars)
            (_, items, __) = lpars
            for slug_ in items:
                product_slugs.add(slug_)
    return product_slugs
 
