I am trying to create a custom theorem format using the thmtools package. However, I am running into problems with the alignment of the QED symbol. When I end the theorem with normal text, it placed the QED symbol at the end of the line, and when I end with an equation and use \qedhere, it places the QED symbol right next to the equation. However, I would like the opposite: for the QED to be at the end of the line with an equation, and right next to the period of regular text.
You can see my MWE below:
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{ifthen}
\usepackage{calc}
\declaretheoremstyle[
spaceabove=10pt,
headpunct={},
headformat=\ifthenelse{ \equal{\NOTE}{} }%
{% yes
$\underset{%
\raisebox{2pt}[0pt][0pt]{%
\rule{\widthof{\text{\NAME\ \NUMBER}}+6ex}{.1ex}}%
}{%
\text{\NAME\ \NUMBER}\hfill%
}$%
}{% no
$\underset{%
\raisebox{5.5pt}[0pt][0pt]{%
\rule{\widthof{\text{\NAME\ \NUMBER\hspace{1ex}$|$\hspace{1ex}\NOTE}}+6ex}{.1ex}}%
}{%
\text{\NAME\ \NUMBER\hspace{1ex}$\bm{|}$\hspace{1ex}\NOTE}\hfill%
}$%
}\newline,
spacebelow=10pt,
qed=\qedsymbol
]{thmdefault}
\declaretheorem[style=thmdefault]{Theorem}
\begin{document}
Here is some text.
\begin{Theorem}[Important Theorem]
This is a theorem. Notice that this QED symbol is right next to my equation. I would like it at the end of that line. $$a^2 + b^2 = c^2\qedhere$$
\end{Theorem}
Here is some more text.
\begin{Theorem}[Another Theorem]
This is another theorem. Notice that the QED symbol is placed at the end of the line. I would like it right next to this period.
\end{Theorem}
And here is a little more text.
\end{document}
(I included the large headformat option because the QED does not behave the same if it is not there.)
This seems like it should be a very simple problem with an easy solution (I am only beginning to learn LaTeX), but after a few days of searching, I cannot seem to find a solution.

\qedbut how do you know the original/default definition for it? I want to skip a line and center it below the final equation. Would be good to have a look at it first though. – voices Aug 31 '19 at 00:31\show\qedto see the definition of\qed, or find the definition in the original source code; in this case,amsclass.dtx. The.dtxis filled with documentation as comments, but you should be able to identify the definition. – Werner Aug 31 '19 at 16:18