Not much point trying to re-attach it to that metalwork. Might as well remove the final hinge, repair all three sections with fresh metal, rust proof as best you can and re-attach the pop top. Possibly stick strips of fibreglass matting with resin and gel-coat/paint over the top of the hinges on the metalwork as an extra barrier to water.
Yes as others on here have said really the only way to go is to get the roof of cut out the rot and weld in new matal.
We had to do the same on our van, our's was pretty bad there's some pics on my first post.
Think the hardest part of the repair was getting the pop top in the right position when fitting it back on.
Best of luck with the repair