A statistical theory of weakly charged polyelectrolytes: fluctuations, equation of state, and microphase separation