how can we compute the maximum area of a rectangle which can be inscribed in a triangle of area 'M'

I have taken a special case here in the image file to calculate the inscribed rectangle area but how can we calculate it for general case??
Copyright © 2021 JogjaFile Inc.
Let $EF=x$.
Thus, since $h_a=\frac{2M}{a}$ and $\Delta ABC\sim \Delta AEF$, we obtain: $$\frac{x}{a}=\frac{\frac{2M}{a}-EG}{\frac{2M}{a}},$$ which gives $$EG=\frac{2M}{a}\left(1-\frac{x}{a}\right).$$ Id est, by AM-GM $$S_{EFHG}=\frac{2M}{a}\left(1-\frac{x}{a}\right)x=2M\left(1-\frac{x}{a}\right)\frac{x}{a}\leq2M\left(\frac{1-\frac{x}{a}+\frac{x}{a}}{2}\right)^2=\frac{M}{2}.$$ The equality occurs for $1-\frac{x}{a}=\frac{x}{a},$ which says that we got a maximal value.