Thermodynamics of the Heat-Flux Avalanches at the First-Order Magnetic Transition in Magnetocaloric Materials