from jitx.layerindex import Side
from jitx.run.runtime import AsyncRuntimeDesign


async def main(rd: AsyncRuntimeDesign) -> dict[str, object]:
    await rd.capture()
    placed = await rd.layout.place(
        rd.root.circuit.u1, (-10, 0), 0, on=Side.Top
    )
    if not await rd.layout.sync(timeout=30):
        raise TimeoutError("Placement applied; background work is still pending")
    await rd.capture()
    report = await rd.issues()
    return {
        "placement": str(placed),
        "checks_complete": report.complete,
        "error_count": len(report.errors),
        "issues": report.text(),
    }
