import asyncio
from playwright.async_api import async_playwright

async def run():
    async with async_playwright() as p:
        br = await p.chromium.launch(channel='msedge', headless=True)
        pg = await br.new_page(viewport={'width':1280,'height':800})
        await pg.goto('http://localhost:8090/DOZIKWORKS_OS_v5_locked.dc.html', timeout=10000)
        await pg.wait_for_timeout(3000)

        r = await pg.evaluate('''() => {
            const app = window.__dzw;
            const btn = document.getElementById("dzw-edge-mode-btn");
            if(!btn) return {err:"btn not found"};
            // initBtn 수동 호출 (패널 열리면 자동 호출되는 것)
            DZW5_EDGEPATH.initBtn(app);
            // ON 클릭
            btn.onclick();
            return {
                edgeMode_ON: app?._edgeMode,
                btn_text: btn.textContent,
                EDGEPATH_module: typeof window.DZW5_EDGEPATH,
                ENGINE_extractEdges: typeof window.DZW5_ENGINE?.extractEdges
            };
        }''')
        print('ON 후:', r)
        await pg.screenshot(path='edgepath_verify.png')
        print('스크린샷: edgepath_verify.png')

        r2 = await pg.evaluate('''() => {
            const btn = document.getElementById("dzw-edge-mode-btn");
            btn.onclick();
            return { edgeMode_OFF: window.__dzw?._edgeMode, btn_text: btn.textContent };
        }''')
        print('OFF 후:', r2)
        await br.close()
        print('완료')

asyncio.run(run())
