Here the word "heart" refers to a person's thoughts and emotions. "Gladness" describes either 1) the state of the emotions of being happy and peaceful or 2) the ability to understand the truth. AT: "right thinking" (See: [[rc://en/ta/man/translate/figs-metonymy]])
Here wise people are referred to by their "hearts." This speaks of the wise person mourning as being in a house of mourning. AT: "Wise people think deeply about death" (See: [[rc://en/ta/man/translate/figs-synecdoche]] and [[rc://en/ta/man/translate/figs-metaphor]])
Here foolish people are referred to by their "hearts." This speaks of foolish people thinking only about what makes them happy as being in a house of feasting. AT: "but foolish people think only about enjoying themselves" (See: [[rc://en/ta/man/translate/figs-synecdoche]] and [[rc://en/ta/man/translate/figs-metaphor]])