Time-reversal invariance and thermodynamics of electromagnetic fields in materials with memory