Jamie Lynn Spears wrote a beautiful song titled "When the Lights Go Out" for her daughter, Maddie Aldridge, and sang it at the Grand Ole Opry in March 2016. The performance resurfaced online after the 8-year-old's ATV accident on Sunday, February 5. Watch a clip above!

"Whenever I wrote 'When the Lights Go Out,' it was coming from a place ... it was the first night, of course, that Maddie was away from me," the country singer, 25, said with tears in her eyes in her 2016 TLC documentary, Jamie Lynn Spears: When the Lights Go Out, which was named after the song. Spears welcomed Maddie in 2008, two years before she and Maddie's father, Casey Aldridge, separated.

"She was with her dad for the first time, and I was by myself," Spears recalled of the moment she wrote the song. "In that moment, I called Daddy [Jamie Spears]. I was just by myself, and I was just like, I want to be able to let people into that side of me because that's the story. That's why I'm doing it. As you can tell, the music moves me, of course, but it comes from moments like that."

"It reminds me of exactly why I'm still driven to do this, for this baby girl," the Zoey 101 alum added.

In the TLC documentary, Spears reflected on her teenage pregnancy, her close bond with Maddie and her debut at the legendary Grand Ole Opry in Nashville last year. In one scene, Spears called her daughter her "best friend" and said she loves having her in the audience at concerts because she "can just look at her and sing to her and pretend like nobody else is there."

"I just want to be a good mom who makes her little girl proud," the former child star said in the film.

As Us Weekly previously reported, Maddie was driving a Polaris off-road vehicle on Sunday when it flipped over into a nearby pond, submerging her underwater for several minutes. Spears, her husband, Jamie Watson, and other family members dove into the pond to attempt to rescue Maddie, but she was "trapped and secured by the seatbelt and the ATV's safety netting," the Tangipahoa Parish Sheriff's Office told Us in a statement on Monday, February 6. Maddie was airlifted to a hospital in New Orleans and, as of Monday afternoon, was in "stable but critical condition," authorities said.

Jamie Lynn's sister, pop superstar Britney Spears, tweeted on Monday, "Need all the wishes and prayers for my niece."

Want stories like these delivered straight to your inbox? Sign up now for the Us Weekly newsletter!