const puppeteer = require('puppeteer');
(async () => {
    const browser = await puppeteer.launch({ headless: "new" });
    const page = await browser.newPage();
    await page.setViewport({ width: 1400, height: 900 });
    await page.goto('http://127.0.0.1:8000/conference/business-management-economics-spain-2026/call-for-papers', { waitUntil: 'networkidle0' });
    
    // Check if dropdown exists
    const navText = await page.evaluate(() => {
        const text = [];
        document.querySelectorAll('nav button').forEach(b => text.push(b.innerText.trim()));
        return text;
    });
    console.log("Nav Buttons found:", navText);
    
    // Click 'Call for Papers'
    await page.evaluate(() => {
        const btns = Array.from(document.querySelectorAll('nav button'));
        const target = btns.find(b => b.innerText.includes('Call for Papers') || b.innerText.includes('CALL FOR PAPERS'));
        if (target) target.click();
    });
    
    await page.waitForTimeout(500);
    
    // Check what is visible
    const visibleDropdowns = await page.evaluate(() => {
        const text = [];
        document.querySelectorAll('nav [x-show="open"]').forEach(d => {
            if (d.offsetParent !== null) text.push(d.innerText.trim().substring(0, 100).replace(/\n/g, " "));
        });
        return text;
    });
    console.log("Visible dropdown text after click:", visibleDropdowns);
    
    await browser.close();
})();
