"""Orbe recipe — fill a multi-field form and submit.

Shows the field-by-field pattern: click a field by its visible label, type the
value with human timing (rhythm derived from the profile's seed), then submit.

Run:
    export ORBE_PROFILE=my-profile-id
    python examples/fill_form.py
"""
import os

import orbe

# Map each field's visible label to the value to type. In real use, load these
# from a CSV/JSON row instead of hard-coding.
FIELDS = {
    "Full name": "Alex Doe",
    "Email": "alex@example.com",
    "Company": "Orbe",
    "Message": "Hello — this form was filled by Orbe.",
}


def main() -> int:
    profile = os.environ["ORBE_PROFILE"]
    with orbe.Trinh(profile) as t:
        t.goto("https://example.com/contact")
        t.wait_for("Submit")
        for label, value in FIELDS.items():
            t.click(label)          # focus the field by its label text
            t.type(value)
        t.click("Submit")
        t.wait_for("Thanks")
        print("Form submitted.")
    return 0


if __name__ == "__main__":
    try:
        raise SystemExit(main())
    except orbe.Blocked as e:
        print(f"Blocked: {e}")
        raise SystemExit(2)
