A thermodynamic approach to nonlocal plasticity and related variational principles