The pipe is probably CPVC which is allowed for plumbing inside, pvc isn't although they get away with murder sometimes I've heard in a mobile home. The plastic fitting on the end of the pipe before the tub valve may be threaded, which is not a great thing as plastic female threaded joints are notoriously weak, and often split, which may be the problem - all it takes is a small crack under pressure to leak all over.
They do make transition fittings for CPVC that have metal female parts. It also looks like they used the cement to thread in the fitting for the faucet, and that should have been either plumber's tape, or a pipe dope approved for use on plastic (not all are).
You don't have enough room without major mods to install a modern valve that meets current codes (anti-scald technology), so the least expensive thing is to probably cut off the piping maybe 6" down vertically, and rebuild with new. Instead of a female threaded fitting, find a transition piece that goes from cpvc to brass, thread it onto the valve, then glue in new pieces to mate up with what's still there. You may need a repair coupling if there's no give to spread the pipe apart to insert the coupling - it looks like a normal coupling, but doesn't have a stop in the middle. Make sure to try to center it over the joint. You'll need some cpvc cement and primer, some pipe dope approved for plastic, and some wrenches and maybe pliers, along with probably a hacksaw or similar to cut the pipe...all in all, not a lot. This assumes the valve still works otherwise.
There may be places that still make and sell a replacement valve/spout assembly like you have, but technically, it's illegal to replace it unless you bring it up to code...you can legally fix what you have, though.
Those plastic nuts are what hold the faucet in place, but if they're loose, or the hole in the wall is too big, when you play with the valve, you'd be putting stress on the plastic fittings, and that isn't a good setup for longevity.