Looks like the thru axle came loose and freehub body came away from the hub.
Freehub body, pawls and springs might be enough, worst case the teeth the pawls engage with in the hub might have some damage, though like the pawls they’re hardened steel so likely ok.
Looks like a Bontrager hub so your local Trek store should be able to get spares and check the thru axle and frame.
That's a pretty dramatic failure. Hopefully you didn't have to hike too far.
It's the hub that's jacked. While you could buy a new hub and lace the existing spokes and wheel to it, you might be better off just buying a whole new wheel. Another new Bontrager Line Comp 30 isn't very expensive.
The other consideration is what you can expect from replacing the failed part with another "inexpensive" hub. If it's true that you get what you pay for, buying something a little more robust might be the wisest option.
I had a similar failure on a Whyte T130, one week old and the hub axle sheared. I removed the wheel and the cassette fell on to the floor! Replaced under warranty in 7 days. Steel axle this time, not aluminium alloy. If you look carefully at the centre of the hub, you can see where the last part of the axle sheared, (between 12 and 1 o'clock in the picture).
I’d try and get a new freehub body, it should slide right back on,, you’ll need to take the cassette off the old one first. Make sure that it’s all tight when the wheel is fitted as it looks like this has been coming loose for a while by the signs of the damage.