Through a court battle in and it could be worse for them. May even make them distrustful of you.
I would hang in there. If time goes by and she doesn't stabilize (like 6 months) then re-assess and decide what to do at that point.
Make sure to document. If this not a one time only occurrance, then you may need to take primary custody just for stability.
She may voluntarily give you prime custody if she feels like she can trust you to let her have unhampered access and 50/50 back when she is able.