In triangle $ABC$, $\angle A = 45^\circ$ and $M$ is the midpoint of $\overline{BC}$. The line $\overline{AM}$ intersects the circumcircle of $ABC$ for the second time at point $D$, and $AM = 2MD$. Find $\cos\angle AOD$, where $O$ is the circumcenter of $ABC$.

Let's think step by step and output the final answer within \boxed{}.
user