import { test as base, type Page } from "@playwright/test"
import { injectVisibleCursor } from "../helpers"

/**
 * Extended test fixtures for video tours.
 *
 * - `tourPage`: A page with visible cursor overlay, ready for recording.
 *
 * Add project-specific setup (cookie consent, modals, etc.) here.
 */
type TourFixtures = {
    tourPage: Page
}

export const tour = base.extend<TourFixtures>({
    tourPage: async ({ page }, use) => {
        // Inject visible cursor (must be before first goto)
        await injectVisibleCursor(page)

        // Override navigation to always use domcontentloaded (BrowserSync keeps WS open)
        const origGoto = page.goto.bind(page)
        page.goto = ((url: string, opts?: any) =>
            origGoto(url, { waitUntil: "domcontentloaded", ...opts })) as typeof page.goto

        await use(page)
    },
})

export { expect } from "@playwright/test"
