As a joke, she says she wants to keep him as a pet, and to her surprise, the young man agrees.
She wants to keep him as a pet. This is what she says as a joke. The young man agrees. This is to her surprise. This is as a joke.