import asyncio
from playwright.async_api import async_playwright

ROUTES = [
    ('home',      '/'),
    ('about',     '/about/'),
    ('services',  '/services/'),
    ('service',   '/services/floor-refinishing/'),
    ('locations', '/locations/'),
    ('location',  '/locations/buffalo/'),
    ('contact',   '/contact/'),
    ('reviews',   '/reviews/'),
    ('blog',      '/blog/'),
]

async def main():
    async with async_playwright() as p:
        br = await p.firefox.launch(headless=True)
        page = await br.new_page()
        await page.set_viewport_size({'width': 1280, 'height': 900})
        for name, path in ROUTES:
            r = await page.goto('http://localhost:8096' + path, wait_until='networkidle', timeout=20000)
            await page.screenshot(path=f'.planning/screenshots/audit2-{name}.png', full_page=True)
            h1 = await page.eval_on_selector('h1', 'el => el.innerText') if await page.query_selector('h1') else 'NO H1'
            header_ok = bool(await page.query_selector('#site-header'))
            footer_ok = bool(await page.query_selector('footer.site-footer'))
            print(f'{name} | {r.status} | H1: {h1[:60]} | hdr:{header_ok} ftr:{footer_ok}')
        await br.close()

asyncio.run(main())
