1) A and B hydraulic systems are independent. There is no exchange of fluid at the brakes, so B system fluid is returned to the B system, and A system's fluid stays there as well. The two systems don't need to "know" which system is in use. They are independent.
2) The parking brake can be applied with either A or B hydraulic systems pressurised. If neither, then it can be applied using pressure from the brake accumulator. Then when the parking brake lever is applied, not only does it close the parking brake valce but it also locks the brake pedals in that position.