Reconfigurable photonics with on-chip single-photon detectors