2 subtle problems on calculating this integral $\newcommand{\arcsec}{\operatorname{arcsec}}$
I am supposed to show that this equation holds with using integral by substitution. ($a>0$)
$$\int\frac{\sqrt{u^2-a^2}}{u}\,du=\sqrt{u^2-a^2}-a\arccos \left(\frac a {|u|} \right) + C$$
My attempt is this. (Note that to get rid of absolute values of tangent, I supposed $t ∈ [0 , π/2] ∪ [π , 3π/2]).$
$$u=a\sec(t)\\t=\arcsec\left(\frac u a \right)\\
du=a\tan(t)\sec(t)\,dt\\
\int\frac{\sqrt{u^2-a^2}}{u}\,du=\int\frac{\sqrt{a^2\sec^2(t)-a^2}}{a\sec(t)}a\tan(t)\sec(t) \, dt
=\int\frac{a\tan(t)}{a\sec(t)}a\tan(t)\sec(t) \, dt
=\int a\tan^2(t)\,dt
=a\int(\sec^2(t)-1)\,dt
=a\int \sec^2(t)\,dt-a\int 1\,dt=a\tan(t)-at \\
=a\tan(t)-a\arcsec \left(\frac u a \right)$$
Now calcuting right side of my first equation, we have:
$$\sqrt{u^2-a^2}-a\arccos \left( \frac a {|u|} \right)=a\tan(t)-a\arccos(\frac{a}{|u|})$$
Now to complete my proof, all I have to show is this:
$$\arccos\left( \frac a {|u|} \right) = \arcsec\left( \frac u a \right)$$
So I tried this:
$$u=a\sec(t)=a\cdot\frac{1}{\cos(t)}\rightarrow \cos(t)=\frac{a}{u}\rightarrow \arccos\left( \frac a u \right) = t =\arcsec\left(\frac u a \right) $$
Now I encounter two subtle problems.
First is the absolute value of $|u|,$ which is not appearing in the last line of my proof, but appeared in the right side of my supposed equation that I am trying to prove in the first line. I'm confused what happens when u<0.
Second is about showing $t=\arccos(a/|u|).$ Range of $\arccos(x)$ is $[0,π].$ What if I choose a $t$ such that $t>π$? (Remember at first I supposed $t ∈ [0 , π/2] ∪ [π , 3π/2]).$ Then obviously this equation will be wrong. But what is the cause of this problem? Did I make a mistake anywhere? Please be specific and answer both of my problems and show what I did wrong. Any help would be highly appreciated!
EDIT: I want to make another attempt to do it. Let $t ∈ [0 , π/2) ∪ (π/2 , π]). $This will enable us to use $\arcsin(x)=\arccos(\frac{1}{x})$
I split it into 2 cases.
First let $u>a$ then $t ∈ [0,π/2)$ then we have the same case as calculated above and the problem is solved since $u>0.$
Second let $u<-a$ then $t ∈ (π/2,π]$ then the integral would change to this: $$a\int -\tan^2(t)dt=a\int (1-\sec^2(t))dt=a\int 1.dt - a\int \sec^2(t)dt= a.\arcsec(\frac{u}{a})-a\tan(t)=a.\arccos(\frac{a}{u})-a.\tan(t)$$
Now because $u<0$, I have to show that: $$-\arccos(\frac{a}{-u})=\arccos(\frac{a}{u})$$ But it seems its not!

In the second case of your attempt in the Edit, you have $t\in(\frac\pi2, \pi]$ and $u = a\sec t \in (-\infty, -a]$. Then, we have $t-\frac\pi2 \in [0,\frac\pi2)$ and
$$\sin(t-\frac{\pi}2) = -\cos t =-\frac1{\sec t}  =-\frac a{u}=\frac a{|u|}$$
which leads to 
$$ t -\frac\pi2= \sin^{-1}\frac a{|u|}$$
Now, apply the identity $\sin^{-1} x + \cos^{-1}x = \frac\pi2$ to express $t$ as
$$t = \pi - \cos^{-1}\frac 1{|u|}$$
Then, plug the result into the integral for $u \in (-\infty, -a]$
$$\int\frac{\sqrt{u^2-a^2}}{u}du= - a\tan t + at = \sqrt{u^2-a^2} -a\cos^{-1}\frac a{|u|}+ a\pi+C$$
where the constant term $a\pi$ is to be absorbed in $C$. Moreover, note that
$$\arccos(\frac{a}{u}) \ne -\arccos(\frac{a}{-u})$$
Instead, they differ by the constant $\pi$,
$$\arccos(\frac{a}{u}) = \pi - \arccos(\frac{a}{-u})$$
