The pop stars ended their relationship in 2018.

Selena Gomez found purpose in her heartbreak. In her documentary, Selena Gomez: My Mind & Me, which was released on Apple TV+ on Friday, the 30-year-old opens up about the end of her relationship with Justin Bieber in 2018.

While discussing her hit song, “Lose You to Love Me,” Gomez revealed that she reached out to songwriters Julia Michaels and Justin Tranter with the hope of writing a song that would explain all her emotions.

“I text Julia Michaels and Justin Tranter and said, ‘I think I’m ready to just say I’m sad,'” she revealed. “We wrote the song in 45 minutes. The fastest song I’ve ever written.”

She continued, “It’s about more than a lost love. It’s me learning to choose myself, to choose life, but also hoping that people can find grace and peace in that too. The song is about knowing that you completely lost every part of who you are just to rediscover yourself again.”

Gomez’s on-again, off-again romance with Bieber spanned from 2012 to 2018. Shortly after their split, the “Baby” singer married Hailey Baldwin.

For Gomez, dealing with everything in the public eye made the split harder to deal with.

“Everything was so public,” she explained. “I felt haunted by a past relationship that no one wanted to let go of. Then I just moved past it, and I wasn’t afraid anymore.”

Gomez said that she found the light in a very dark situation.

“I feel like I had to go through the worst possible heartbreak ever and then just forgetting everything at the drop of the hand, it was really confusing,” she reflected. “But I just think that needed to happen and ultimately it was the best thing that ever happened to me.”

“Lose You to Love Me” was one of Gomez’s biggest hits. The ballad was the lead single from her 2020 album, Rare.

Although Gomez doesn’t go into major detail about her relationship with the pop star in the documentary, she does express how she felt tired of the constant connection to Bieber. In another scene of the documentary, Gomez breaks down in tears during rehearsals for her 2016 Revival tour. In the middle of crying, the “Good for You” singer questions if it’s possible for her record label to see her outside of working with Bieber after the head of her record label, John Janick, asked her to do a song with him.

“I don’t know what John thinks, I want to talk to John. I don’t want to disappoint John. I don’t want him to think that he signed some f**king Disney kid,” she says through tears. “It just sucks too, because the whole song thing. He called me this morning about the song with Justin, like, when am I just going to be good enough by myself? When am I gonna be good just by myself, not needed anybody to be associated with?”

Of course, it now all appears to be water under the bridge. Last month, Gomez posed with Hailey for a sweet picture together at the Academy Museum Gala in Los Angeles, putting the longstanding feud rumors between the two to rest.

A source told ET that the pair “are more than cordial and just want to remain friendly.”

“Justin, Hailey, and Selena are glad to have cleared the air, moved on with their lives, and closed that chapter,” the source said. “Selena is doing amazing and is just focusing on herself, her family, and her close-knit circle of friends. She’s not trying to settle down right now and she’s just living her best life.”

ET spoke with Gomez  at the documentary’s premiere on Wednesday night. When asked what she’d tell her younger self, a version of Gomez who was struggling to balance her career, her personal life and her health, she said never “be afraid.”

“I never actually was afraid to tell people that I wanna take time for myself. I never thought that was a bad thing,” Gomez explained. “So, to be sharing something honest and say, ‘Hey, I’m taking a break because I need it?’ I’m being honest, and I think that’s just who I am.”