Integrate $\int\sqrt\frac{\sin(x-a)}{\sin(x+a)}dx$
Integrate $$I=\int\sqrt\frac{\sin(x-a)}{\sin(x+a)}dx$$
Let $$\begin{align}u^2=\frac{\sin(x-a)}{\sin(x+a)}\implies 2udu&=\frac{\sin(x+a)\cos(x-a)-\sin(x-a)\cos(x+a)}{\sin^2(x+a)}dx\\2udu&=\frac{\sin((x+a)-(x-a))}{\sin^2(x+a)}dx\\ 2udu&=\frac{\sin(2a)}{\sin^2(x+a)}dx\end{align}$$ Now: $$\begin{align}u^2&=\frac{\sin(x+a-2a)}{\sin(x+a)} \\u^2&=\frac{\sin(x+a)\cos(2a)-\cos(x+a)\sin(2a)}{\sin(x+a)} \\u^2&=\cos(2a)-\sin(2a)\cot(x+a) \\\cot(x+a)&=(\cos(2a)-u^2)\csc(2a) \\\csc^2(x+a)=\cot^2(x+a)+1&=(\cos(2a)-u^2)^2\csc^2(2a)+1 \\\csc^2(x+a)&=\frac{\cos^2(2a)+u^4-2u^2\cos2(2a)+\sin^2(2a)}{\csc^2(2a)} \\\sin^2(x+a)&=\frac{\sin^2(2a)}{u^4-2u^2\cos(2a)+1}\end{align}$$ Now: $$\begin{align} I&=\int u.\frac{2udu\sin^2(x+a)}{\sin(2a)}\\ I&=\int\frac2{\sin(2a)}.u^2.\frac{\sin^2(2a)}{u^4-2u^2\cos(2a)+1}du \\I&=2\sin(2a)\int\frac{u^2}{u^4-2ku^2+1}du\quad k:=\cos 2a \\\frac If&=\int\frac{2+u^{-2}-u^{-2}}{u^2-2k+u^{-2}}du=\int\frac{1+u^{-2}}{u^2-2k+u^{-2}}du+\int\frac{1-u^{-2}}{u^2-2k+u^{-2}}du\quad \\f:=\sin(2a) \\&=\int\frac{d(u-u^{-1})}{(u-u^{-1})^2+2-2k}+\int\frac{d(u+u^{-1})}{(u+u^{-1})^2-2-2k}\end{align}$$
Now: $2-2k=2(1-\cos 2a)=4\sin^24a,2+2k=2(1+\cos 2a)=4\cos^24a$
So: $$I=\sin2a\left(\frac1{2\sin4a}\arctan\left(\frac{u-u^{-1}}{2\sin(4a)}\right)+\frac1{4\cos4a}\ln\left|\frac{u+u^{-1}-2\cos 4a}{u+u^{-1}+2\cos 4a}\right|\right)+C$$ Or: $$I=\frac1{4\cos2a}\arctan\left(\frac{-\sin a\cos x}{\sin4a\sqrt{\sin(x+a)\sin(x-a)}}\right)+\frac{\sin2a}{4\cos 4a}\ln\left|\frac{\sin x\cos a-\cos4a\sqrt{\sin(x+a)\sin(x-a)}}{\sin x\cos a+\cos4a\sqrt{\sin(x+a)\sin(x-a)}}\right|+C$$ But the textbook answer is:
$$\cos a\arccos\left(\frac{\cos x}{\cos a}\right)-\sin a\ln(\sin x+\sqrt{\sin^2x-\sin^2a})+c$$
Here is an alternative way. \begin{align}\sqrt{\frac{\sin(x-a)}{\sin(x+a)}}&=\frac{\sin(x-a)}{\sqrt{\sin(x-a)\sin(x+a)}}=\frac{\sin x\cos a-\cos x\sin a}{\sqrt{\frac12(\cos 2a-\cos 2x)}}\\&=\frac{\cos a\sin x}{\sqrt{\cos^2a-\cos^2x}}-\frac{\sin a\cos x}{\sqrt{\sin^2 x-\sin^2 a}}\end{align} Now for the first one, substitute $\cos x=\cos t\cos a$. $$\int \frac{\cos a\sin x}{\sqrt{\cos^2a-\cos^2x}}dx=\int\cos a\,dt=t\cos a=\cos a\arccos\left(\frac{\cos x}{\cos a}\right)+C_1$$ The second one, substitute $\sin x=\cosh s\sin a$. \begin{align}\int\frac{\sin a\cos x}{\sqrt{\sin^2 x-\sin^2 a}}dx&=\int\sin a\,ds=s\sin a=\sin a\cosh^{-1}\left(\frac{\sin x}{\sin a}\right)\\&=\sin a\ln\left(\frac{\sin x}{\sin a}+\sqrt{\frac{\sin^2x}{\sin^2a}-1}\right)+C_2\\&=\sin a\ln(\sin x+\sqrt{\sin^2x-\sin^2a})+C_3\end{align} Therefore, $$\int\sqrt{\frac{\sin(x-a)}{\sin(x+a)}}dx=\cos a\arccos\left(\frac{\cos x}{\cos a}\right)-\sin a\ln(\sin x+\sqrt{\sin^2 x-\sin^2 a})+C$$
Let us write $$I_a=\int\sqrt{\frac{\sin(x-a)}{\sin(x+a)}}\mathrm dx$$ and compute $I_+=I_a+I_{-a}$ and $I_-=I_a-I_{-a}$. We get $$I_\pm=I_a\pm I_{-a}=\int\frac{\sin(x-a)\pm\sin(x+a)}{\sqrt{\sin(x+a)\sin(x-a)}}\mathrm dx.$$ Using trigonometric formulas, one obtains $$I_+=2\cos a\int\frac{\sin x}{\sqrt{\cos^2a-\cos^2x}}\mathrm dx\\ I_-=2\sin a\int\frac{\cos x}{\sqrt{\sin^2x-\sin^2a}}\mathrm dx.$$ Now just apply the adequate changes of variables $$I_+=2\cos a \arccos\left(\frac{\cos x}{\cos a}\right)+c_+\\ I_-=-2\sin a \ln\left(\sin x+\sqrt{\sin^2x-\sin^2a}\right)+c_-$$ and the result is $I_a=\frac12\left(I_++I_-\right)$.
Other answers offer alternative approaches to integrating form the beginning. If you are looking to find where your steps went astray, it starts when you are using: $$2(1-\cos(2a))=4\sin^2(4a)$$ but the correct identity is: $$2(1-\cos(2a))=4\sin^2(a)$$ Just check both sides with $a=\pi/4$ and you'll believe it. And similarly for the next identity that you use: $2(1+\cos(2a))=4\cos^2(4a)$ should be $2(1+\cos(2a))=4\cos^2(a)$.
From there, you would have $$I=\sin2a\left(\frac1{2\sin a}\arctan\left(\frac{u-u^{-1}}{2\sin(a)}\right)+\frac1{4\cos a}\ln\left|\frac{u+u^{-1}-2\cos a}{u+u^{-1}+2\cos a}\right|\right)+C$$
which gives $$I=\cos(a)\arctan\left(\frac{u-u^{-1}}{2\sin(a)}\right)+\frac1{2}\sin(a)\ln\left|\frac{u+u^{-1}-2\cos a}{u+u^{-1}+2\cos a}\right|+C$$
And then we start back-substituting. We reach a point where it helps to use $\arctan\left(\frac{A}{B}\right)=\arcsin\left(\frac{A}{\sqrt{A^2+B^2}}\right)=\frac{\pi}{2}-\arccos\left(\frac{A}{\sqrt{A^2+B^2}}\right)$ and the constant can be absorbed into the $C$. Keep in mind that expressions in $a$ are constant for the purposes of $C$. Then we reach a point where by adding a certain logarithmic expression in $a$ (again, absorbed into $C$) we can simplify the appearance of the logarithmic term.
$$ \begin{align} I&=\cos(a)\arctan\left(\frac{\sqrt\frac{\sin(x-a)}{\sin(x+a)}-\sqrt\frac{\sin(x+a)}{\sin(x-a)}}{2\sin(a)}\right)\\ &\phantom{=}{}+\frac1{2}\sin(a)\ln\left|\frac{\sqrt\frac{\sin(x-a)}{\sin(x+a)}+\sqrt\frac{\sin(x+a)}{\sin(x-a)}-2\cos a}{\sqrt\frac{\sin(x-a)}{\sin(x+a)}+\sqrt\frac{\sin(x+a)}{\sin(x-a)}+2\cos a}\right|+C\\ &=\cos(a)\arctan\left(\frac{\sin(x-a)-\sin(x+a)}{2\sin(a)\sqrt{\sin(x-a)\sin(x+a)}}\right)\\ &\phantom{=}{}+\frac1{2}\sin(a)\ln\left|\frac{\sin(x-a)+\sin(x+a)-2\cos(a)\sqrt{\sin(x-a)\sin(x+a)}}{\sin(x-a)+\sin(x+a)+2\cos(a)\sqrt{\sin(x-a)\sin(x+a)}}\right|+C\\ &=\cos(a)\arctan\left(\frac{-\cos(x)}{\sqrt{\sin(x-a)\sin(x+a)}}\right)\\ &\phantom{=}{}+\frac1{2}\sin(a)\ln\left|\frac{\sin(x)-\sqrt{\sin(x-a)\sin(x+a)}}{\sin(x)+\sqrt{\sin(x-a)\sin(x+a)}}\right|+C\\ &=-\cos(a)\arcsin\left(\frac{\cos(x)}{\sqrt{\cos^2(x)+\sin(x-a)\sin(x+a)}}\right)\\ &\phantom{=}{}+\frac1{2}\sin(a)\ln\left|\frac{\sin(x)-\sqrt{\sin(x-a)\sin(x+a)}}{\sin(x)+\sqrt{\sin(x-a)\sin(x+a)}}\right|+C\\ &=-\cos(a)\left(\frac{\pi}{2}-\arccos\left(\frac{\cos(x)}{\sqrt{\cos^2(x)+\frac12\cos(2a)-\frac12\cos(2x)}}\right)\right)\\ &\phantom{=}{}+\frac1{2}\sin(a)\ln\left|\frac{\sin(x)-\sqrt{\sin(x-a)\sin(x+a)}}{\sin(x)+\sqrt{\sin(x-a)\sin(x+a)}}\right|+C\\ &=\cos(a)\arccos\left(\frac{\cos(x)}{\cos(a)}\right)+\frac1{2}\sin(a)\ln\left|\frac{\sin(x)-\sqrt{\sin(x-a)\sin(x+a)}}{\sin(x)+\sqrt{\sin(x-a)\sin(x+a)}}\right|+C_1 \end{align}$$
Note that $-\cos(a)\frac{\pi}{2}$ has been absorbed into $C$.
It remains to show $$\frac1{2}\ln\left|\frac{\sin(x)-\sqrt{\sin(x-a)\sin(x+a)}}{\sin(x)+\sqrt{\sin(x-a)\sin(x+a)}}\right|=-\ln\left|\sin(x)+\sqrt{\sin^2(x)-\sin^2(a)}\right|+C_2(a)$$ If you add $\ln\left|\sin(x)+\sqrt{\sin^2(x)-\sin^2(a)}\right|$ to the left side, you have $$ \begin{align} &\ln\left|\sqrt{\sin(x)-\sqrt{\sin(x-a)\sin(x+a)}}\sqrt{\sin(x)+\sqrt{\sin(x-a)\sin(x+a)}}\right|\\ &=\ln\left|\sqrt{\sin^2(x)-\sin(x-a)\sin(x+a)}\right|\\ &=\ln\left|\sqrt{\sin^2(x)-\frac12\cos(2a)+\frac12\cos(2x)}\right|\\ &=\ln\left|\sqrt{\sin^2(a)}\right|=C_2(a)\\ \end{align}$$
which establishes that last relation.
Also this write up has a typo at an earlier line, with $$\csc^2(x+a)=\frac{\cos^2(2a)+u^4-2u^2\cos2(2a)+\sin^2(2a)}{\csc^2(2a)}$$ but you meant $$\csc^2(x+a)=\frac{\cos^2(2a)+u^4-2u^2\cos(2a)+\sin^2(2a)}{\sin^2(2a)}$$ In any case, these things have been corrected at the next line.