'use client'; import React, { useState } from 'react'; import Link from 'next/link'; interface ConfessionViewerProps { confession: { title: string; chapters: { [key: string]: { title: string; paragraphs: { [key: string]: string; }; }; }; }; verses: { [key: string]: string; }; } export default function ConfessionViewer({ confession, verses }: ConfessionViewerProps) { const [activeChapter, setActiveChapter] = useState("1"); const [showScripture, setShowScripture] = useState(true); // Get sorted chapter numbers const chapterNumbers = Object.keys(confession.chapters).sort((a, b) => parseInt(a) - parseInt(b) ); // Function to render Bible references as links with tooltips const renderTextWithReferences = (text: string) => { const regex = /\b(?:\d\s+)?[A-Za-z]+\s+\d+:\d+(?:-\d+)?(?:,\s+\d+(?:-\d+)?)*\b/g; const parts = text.split(regex); const matches = text.match(regex) || []; if (matches.length === 0) return text; return parts.reduce((result: React.ReactNode[], part, i) => { result.push(part); if (i < matches.length) { const reference = matches[i]; const verseText = verses[reference]; if (verseText && showScripture) { result.push( {reference} {reference}: {verseText} ); } else { result.push( {reference} ); } } return result; }, []); }; return ( <> {/* Uncomment this section if you want the introduction and controls */} {/*

The 1689 Baptist Confession of Faith, also called the Second London Baptist Confession, was written by Particular Baptists in England who were concerned that their Calvinistic theological positions would be misunderstood.

This confession follows the Westminster Confession of Faith and the Savoy Declaration in its doctrine, but with Baptist distinctives related to baptism and church polity.

{showScripture ? 'Hover over references to see Scripture text' : 'Scripture tooltips are hidden'}

*/}
{/* Sidebar Navigation */}

Chapters

{chapterNumbers.map(chapterNum => ( ))}
{/* Main Content */}

Chapter {activeChapter}: {confession.chapters[activeChapter].title}

{Object.keys(confession.chapters[activeChapter].paragraphs).map(paraNum => (

{paraNum} Paragraph {paraNum}

{renderTextWithReferences(confession.chapters[activeChapter].paragraphs[paraNum])}

))}
{parseInt(activeChapter) > 1 && ( )} {parseInt(activeChapter) < chapterNumbers.length && ( )}
); }