// Dismiss the cookie-consent banner if it's showing. It is fixed to the bottom
// of the viewport and intercepts pointer events over the catalog footer (where
// row-select checkboxes live), so tests that click there must clear it first.
export async function dismissCookies(page) {
  const banner = page.locator('.cookie-consent-banner')
  if (await banner.count()) {
    // Click to persist the consent choice so it doesn't reappear on
    // later navigation...
    await page.getByRole('button', { name: 'Save choice' }).click().catch(() => {})
    await banner.waitFor({ state: 'hidden', timeout: 5000 }).catch(() => {})
    // ...then forcibly remove any node still in the DOM. The dismiss
    // click occasionally doesn't land before a test clicks a catalog
    // footer checkbox (flaky over the deployed edge), and a lingering
    // fixed banner intercepts those pointer events. Removing the node
    // makes the dismissal deterministic.
    await banner.evaluate((el) => el.remove()).catch(() => {})
  }
}
