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=False, args=['--start-maximized'])
        ctx = await br.new_context(no_viewport=True)
        pg = await ctx.new_page()
        await pg.goto('http://localhost:8090/DOZIKWORKS_OS_v5_locked.dc.html')
        print('로딩 50초 대기...')
        await pg.wait_for_timeout(50000)

        # JS로 너클붐 선택 + xform 패널 열기
        r = await pg.evaluate('''() => {
            const app = window.__dzw;
            if(!app || !app._knuckleMesh) return "knuckleMesh 없음";
            app._knuckleSelect();
            return "선택 완료, tcSelected=" + app._tcSelected;
        }''')
        print('너클붐 선택:', r)
        await pg.wait_for_timeout(1500)

        # 패널 열기
        r2 = await pg.evaluate('''() => {
            const app = window.__dzw;
            app._showXformPanel();
            const panel = document.getElementById("dzw-xform-panel");
            return "패널 display=" + (panel ? panel.style.display : "없음");
        }''')
        print('패널:', r2)
        await pg.wait_for_timeout(1000)

        # 필릿 추출 버튼 클릭
        await pg.evaluate('() => document.getElementById("dzw-extract-fillet").click()')
        await pg.wait_for_timeout(3000)

        await pg.screenshot(path='fillet_result.png')
        print('스크린샷 저장: fillet_result.png')

        print('브라우저 열려있음. 직접 확인하세요.')
        await pg.wait_for_timeout(120000)
        await br.close()

asyncio.run(run())
