import { test, expect } from '@playwright/test';

test('Empirical Mega Verification', async ({ page }) => {
    page.on('console', msg => console.log('BROWSER:', msg.text()));

    // 1. Verify AutoForm
    console.log('--- Verifying AutoForm Mega ---');
    await page.goto('http://localhost:5173/test/form_test.html');
    await page.waitForTimeout(3000);
    
    const checkForm = async (id) => {
        return await page.evaluate((fid) => {
            const form = document.getElementById(fid);
            const inputs = form.querySelectorAll('input, select, textarea');
            const labels = form.querySelectorAll('label');
            return {
                id: fid,
                inputCount: inputs.length,
                labelCount: labels.length,
                html: form.innerHTML.substring(0, 100)
            };
        }, id);
    };

    const vResult = await checkForm('formV');
    const hResult = await checkForm('formH');
    const iResult = await checkForm('formI');
    
    console.log('Form results:', { vResult, hResult, iResult });
    expect(vResult.inputCount).toBeGreaterThan(5);
    expect(hResult.inputCount).toBeGreaterThan(5);

    // 2. Verify List
    console.log('--- Verifying List Mega ---');
    await page.goto('http://localhost:5173/test/list_test.html');
    await page.waitForTimeout(3000);

    const checkList = async (id) => {
        return await page.evaluate((lid) => {
            const list = document.getElementById(lid);
            const items = list.querySelectorAll('.list-group-item');
            return {
                id: lid,
                itemCount: items.length,
                labels: Array.from(items).map(i => i.textContent.trim())
            };
        }, id);
    };

    const stdResult = await checkList('listStd');
    const grpResult = await checkList('listGrp');
    const treeResult = await checkList('listTree');

    console.log('List results:', { stdResult, grpResult, treeResult });
    
    expect(stdResult.itemCount).toBeGreaterThan(0);
    expect(grpResult.itemCount).toBeGreaterThan(2);
    expect(treeResult.itemCount).toBeGreaterThan(0);
});
