A thermodynamically consistent nonlocal formulation for damaging materials