const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({ headless: false });
  const page = await browser.newPage();
  
  page.on('console', msg => {
    if (msg.type() === 'error') {
      console.log('BROWSER ERROR:', msg.text());
    }
  });
  
  page.on('pageerror', err => {
    console.log('PAGE ERROR:', err);
  });
  
  try {
    console.log('Opening page...');
    await page.goto('http://localhost:3000');
    console.log('Waiting for app to load...');
    
    // Wait longer for React to render
    await page.waitForTimeout(10000);
    
    // Check what's in the DOM
    const result = await page.evaluate(() => {
      const root = document.getElementById('root');
      if (!root) return 'NO_ROOT';
      
      const html = root.innerHTML;
      if (html.length === 0) return 'EMPTY_ROOT';
      if (html.length < 100) return 'SMALL_HTML: ' + html.substring(0, 100);
      
      // Look for specific text
      const text = document.body.innerText;
      if (text.includes('기준정보')) return 'FOUND_CONTENT';
      if (text.length > 0) return 'HAS_TEXT_LENGTH: ' + text.length;
      
      return 'UNKNOWN_STATE';
    });
    
    console.log('DOM State:', result);
    
    await page.screenshot({ path: 'browser_test.png' });
    console.log('Screenshot saved, waiting 5 seconds before closing...');
    
    await page.waitForTimeout(5000);
    
  } catch (err) {
    console.error('Error:', err.message);
  } finally {
    await browser.close();
  }
})();
