Investors may be captivated by the bitter battle between Papa John's founder and its board. What they should be watching is the company's debt levels.

The falling pizza sales and bad publicity have left the company at risk of breaching its lending agreements on $579 million in outstanding debt if it can't turn things around in coming months. The company warned investors earlier this month that it may be forced to renegotiate its loans and credit lines with lenders, which could make financing more expensive at a time when its business is struggling.

Separately, the restaurant chain has hired Bank of America and Lazard to help clean up the mess created by founder John Schnatter. The company is exploring everything, including a massive rebranding, buying him out or even a sale of the entire company.

Basically, every option is on the table.

The outside advisers arrive during a bitter battle involving the pizza company with more than 5,000 franchises, Schnatter himself and the board of directors who forced him to resign as chairman after he used a racial slur on a conference call. Since Schnatter's comment became public in mid-July, Papa John shares have fallen by about 8 percent.

Franchise owners remain fearful for their business. Pizza sales, which were slipping even before the most recent dust up, have now plummeted. Meanwhile, Schnatter has filed a lawsuit that accuses the company of staging a coup and has launched a website, www.savepapajohns.com, to publicly air the legal fight. He has posted the back-and-fourth of court filings and letters between him and the company he founded in the back of his dad's tavern.

The board hasn't held back either. A letter released Wednesday by its independent directors accuses Schnatter of lying and "promoting his self-interest at the expense of all others in an attempt to regain control."

The company's shares, which are down almost 40 percent in the last year, plummeted Aug. 7 after it released second-quarter earnings that missed nearly every key estimate tracked by Wall Street — profit, revenue and same-store sales. It also said pizza sales would be significantly worse than previously forecast, noting that sales at stores open for at least a year were expected to fall 7 to 10 percent in 2018. The company previously estimated they wouldn't decline by more than 3 percent.

Meanwhile, its credit agreement with JPMorgan, PNC Bank, U.S. Bank and other lenders requires Papa John's to keep its amount of leverage low. The leverage ratio is based on how much debt the company has compared to its earnings — which are pizza sales and other revenue minus expenses, in general.

As earnings fall, the leverage ratio rises — unless Papa John's can reduce its debt. The company said it has used about $579.4 million of roughly $1 billion in available credit as of July 1 — $385 million in loans and $194.4 million of its revolving credit line, according to a securities filing this month.

CEO Steve Ritchie blamed the company's recent poor performance on public outcry surrounding Schnatter's remarks. However, the company had declining sales before the uproar. But that drop has accelerated in recent weeks, and strong pizza sales are needed to help keep Papa John's in compliance with its debt covenants, more or less.

Although Papa John's is currently "comfortably within our debt covenants," the pessimistic sales forecast prompted executives to "proactively" open talks with its lenders, Chief Financial Officer Joseph Smith said this month.

"With the company's history of strong cash flow, our constructive long-term relationships with our banks and our comprehensive plans to improve the business, if any accommodation is needed, we fully expect that we will be able to obtain one," Smith told analysts on an Aug. 7 call. "Again, we're just trying to get ahead of the situation and starting our conversations with the bank group."

If the company can't get a reprieve, it said it wouldn't be able to borrow additional funds from the banks, according to an Aug. 7 securities filing. Its lenders could then require immediate repayment of its debt and "require us to cash collateralize outstanding letters of credit or increase our interest rate," according to the filing. "If any of the foregoing events occur, we would need to refinance our debt, or renegotiate or restructure, the terms of the credit agreement."

The leverage ratio, which was 3.4 on July 1, was safely under the bank's requirement of 4.5. But the maximum leverage ratio is gradually lowered by a quarter point every year beginning in September — dropping to 3.75 by 2021, according to its most recent quarterly filing and its August 2017 credit agreement.

That should give the company ample time to renegotiate its lending terms before triggering a violation. But executives will also need to turn sales around to prevent a further worsening of its leverage ratio.

Banks often give companies that are going through unique challenges a reprieve to address those issues. If they persist, lenders can become less lenient.

"We've addressed this and reported we are well within our debt covenant," Papa John's spokeswoman Madeline Chadwick said in an email.

One option Papa John's is considering is a sale, people familiar with the matter say. Potential acquirers could include Burger King-owner Restaurant Brands International or the owner of Buffalo Wild Wings, private equity firm Roark. Pizza, like burgers and sandwiches, scales well internationally.

Still, securing a deal may be challenging. Schnatter owns 30 percent of the company, giving him significant voting power. With its shares and business down, the company may not fetch a compelling price. Potential acquirers, meantime, may be weary of walking into a still on-going public relations mess.

The company has not yet launched a formal sales process, though it has received interest from potential bidders, a person familiar with the situation told CNBC, requesting anonymity because the information is confidential.

Papa John's could also sell the restaurant to Schnatter himself or buy out his stake. Schnatter, though, has not yet indicated any willingness to sell.

Regardless of whether Papa John's sells, it will need to confront the hit to its reputation.

It has brought on a number of experts to advise on an image turnaround, like Endeavor Global Marketing. Bozman Saint John, the chief marketing officer of Endeavor's parent company, is an African-American woman who previously worked to overhaul Uber's image.

The company already seems to be taking a playbook from Domino's Pizza. Nearly a decade ago, Domino's sparked a brand revival acknowledging critiques of its pizza, including accusations of it tasting like cardboard, being mass produced and bland.

In a social media campaign launched last week, Papa John's struck a similar note, telling customers it heard their complaints. In the commercial posted on Facebook and Twitter, it included customers' tweets criticizing the company like "I'm so disappointed, I'll never order from you again."