import { plainText } from "@/components/rich-text";
import { comparisonRows } from "@/content/loan-comparisons";
import type { LoanContent } from "@/content/types";

export function loanMarkdown(loan: LoanContent, depth = 1) {
  const heading = (level: number) => "#".repeat(depth + level - 1);
  return [
    `${heading(1)} ${loan.metadataTitle}`,
    "",
    `Source: https://maxcredit.sg/${loan.slug}`,
    "",
    plainText(loan.hero.description),
    "",
    loan.intro.title ? `${heading(2)} ${loan.intro.title}` : "",
    plainText(loan.intro.description),
    "",
    `${heading(2)} Frequently asked questions`,
    "",
    ...loan.faqs.flatMap((faq) => [
      `${heading(3)} ${faq.question}`,
      "",
      plainText(faq.answer),
      "",
    ]),
    `${heading(2)} Compare related loan services`,
    "",
    ...comparisonRows(loan.slug).map(
      (row) =>
        `- [${row.label}](https://maxcredit.sg/${row.slug}): ${row.focus}. Ask: ${row.question}`,
    ),
    "",
  ];
}

export const loanMarkdownFooter = [
  "For current product details, contact MaxCredit: https://maxcredit.sg/contact",
  "Ministry of Law’s borrower guide: https://rom.mlaw.gov.sg/information-for-borrowers/guide-to-borrowing-from-licensed-moneylenders-english/",
  "",
];
