import { chromium } from 'playwright';
import { config } from 'dotenv';
import path from 'path';
config({ path: path.resolve(process.cwd(), '.env.local') });

(async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage();

  // Try the direct forms app URL first
  await page.goto('https://forms.skyslope.com', { waitUntil: 'domcontentloaded', timeout: 30_000 });
  await page.waitForTimeout(3000);

  console.log('URL after goto forms.skyslope.com:', page.url());
  await page.screenshot({ path: 'scripts/debug-forms-home.png' });

  // Look for any login/sign-in link
  const loginLinks = await page.locator('a, button').all();
  for (const el of loginLinks) {
    const text = await el.textContent().catch(() => '');
    const href = await el.getAttribute('href').catch(() => '');
    if (/login|sign.?in|log.?in|get started|access/i.test((text ?? '') + (href ?? ''))) {
      console.log('Found login element:', text?.trim().slice(0,60), href?.slice(0,80));
    }
  }

  await browser.close();
})();
