Cut where I marked in red. This will leave the hub of the wye intact ( marked in blue) with pipe glued into it.
View attachment 40563
This fitting will solvent weld with your pvc glue OVER that hub. It’s a specialty fitting.
https://www.supplyhouse.com/Jones-Stephens-P22100-1-1-2-Plastic-Over-Fitting-Repair-Fitting-PVC
Then you’ll need one of these…….
https://www.acehardware.com/departm...V5v_jBx3ssAp_EAQYASABEgI37PD_BwE&gclsrc=aw.ds
This will glue inside of the specialty fitting above. It’ll accept the new ptrap you buy. Buy one just like you used before and just throw away the pipe adapter that comes with it.
You’ll use the pipe adapter I told you to buy above. It’ll save room…..you don’t have much room there.
In fact it’s so close that the above fittings and my directions may not work. The trap might be too large to fit back into your space. You can try. If it doesn’t work you’ll need to cut that pvc wye off and configure it another way. Thevwye looks like it’s almost jammed up against the wall without any pipe exposed. Not good for a homeowner.