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


def main(rd: SyncRuntimeDesign) -> dict[str, object]:
    rd.capture()
    with rd.layout.batch() as batch:
        first = batch.place(rd.root.circuit.u1, (10, 5), 90, on=Side.Top)
        second = batch.place(rd.root.circuit.u2, (0, -12), 0, on=Side.Bottom)
    if not rd.layout.sync(timeout=30):
        raise TimeoutError("Batch applied; background work is still pending")
    rd.capture()
    report = rd.issues()
    return {
        "placements": {
            "circuit.u1": str(first.placement),
            "circuit.u2": str(second.placement),
        },
        "checks_complete": report.complete,
        "error_count": len(report.errors),
        "issues": report.text(),
    }
