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

async function findMenus() {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  
  try {
    console.log('메뉴 구조 분석 중...\n');
    await page.goto('http://localhost:3000', { waitUntil: 'networkidle' });
    await page.waitForTimeout(1000);
    
    // 모든 버튼 찾기
    const buttons = await page.locator('button').all();
    console.log('왼쪽 사이드바 메뉴 항목들:\n');
    
    let count = 0;
    for (const button of buttons.slice(0, 50)) {
      const text = await button.textContent();
      const isVisible = await button.isVisible();
      const rect = await button.boundingBox();
      
      if (text && text.trim().length > 0 && isVisible && rect && rect.x < 256) {
        count++;
        console.log(count + '. ' + text.trim() + ' (visible, x=' + Math.round(rect.x) + ')');
      }
    }
    
    // 기준정보 찾기
    console.log('\n기준정보 메뉴 찾기:');
    const basicInfoLocator = page.locator('button, span, div').filter({ hasText: '기준정보' });
    const basicInfoCount = await basicInfoLocator.count();
    console.log('기준정보 관련 요소: ' + basicInfoCount + '개');
    
    for (let i = 0; i < basicInfoCount && i < 5; i++) {
      const text = await basicInfoLocator.nth(i).textContent();
      const isVisible = await basicInfoLocator.nth(i).isVisible();
      console.log((i+1) + '. ' + text?.trim() + ' (visible: ' + isVisible + ')');
    }
    
  } catch (error) {
    console.error('오류: ' + error.message);
  } finally {
    await browser.close();
  }
}

findMenus();
