Male peacocks spread their tail feathers to attract peahens and show their fitness, following the handicap principle, and to intimidate rivals, not for cooling, protection, or escape from predators.

The elaborate tail feathers of male peacocks, known as a train, are a classic example of sexual selection in the animal kingdom. The vibrant colors and intricate patterns of the train are not only visually stunning, but also serve as a signal of the peacock's genetic quality to potential mates.

According to the handicap principle, proposed by biologist Amotz Zahavi, extravagant traits such as the peacock's train can evolve and be maintained in a population because they are costly to produce and maintain. In this case, the peacock invests a significant amount of energy and resources into growing and maintaining its elaborate train, making it a signal of its overall fitness and ability to survive despite these handicaps.

When a male peacock spreads its tail feathers in a display, it is not only showcasing its genetic quality to potential mates, but also intimidating rival males. The size and quality of a peacock's train can indicate its dominance and competitive ability, leading to more successful mating opportunities.

In conclusion, the primary function of a male peacock's elaborate tail feathers is to attract peahens and signal their genetic quality, as well as to intimidate rival males in competition for mating opportunities. The handicap principle helps to explain why these extravagant traits have evolved and are maintained in the peacock population.