{% extends "base.html" %}

{% block title %}Cross-References Index - KJV Study{% endblock %}
{% block description %}Browse all {{ "{:,}".format(total_verses) }} verses with cross-references from the Treasury of Scripture Knowledge{% endblock %}

{% block content %}
<article>
    <h1>Cross-References Index</h1>
    <p class="subtitle">{{ "{:,}".format(total_verses) }} verses across {{ total_books }} books with {{ "{:,}".format(total_refs) }} cross-references</p>

    <section>
        <p>This index lists every verse that has cross-references to related passages. Cross-references help you:</p>
        <ul>
            <li><strong>See connections</strong> between related passages</li>
            <li><strong>Understand context</strong> by comparing parallel accounts</li>
            <li><strong>Study themes</strong> that appear throughout Scripture</li>
            <li><strong>Discover fulfillment</strong> of Old Testament prophecies in the New Testament</li>
        </ul>
        <p>Data sourced from the <strong>Treasury of Scripture Knowledge</strong> via <a href="https://www.openbible.info/labs/cross-references/" target="_blank" rel="noopener">OpenBible.info</a> (CC-BY license).</p>
    </section>

    <nav class="toc">
        <h2>Table of Contents</h2>
        <div class="toc-columns">
            {% for book, chapters in crossref_index.items() %}
            <a href="#{{ book|replace(' ', '-')|lower }}" class="toc-link">{{ book }}</a>
            {% endfor %}
        </div>
    </nav>

    {% for book, chapters in crossref_index.items() %}
    <section class="book-section" id="{{ book|replace(' ', '-')|lower }}">
        <h2>{{ book }}</h2>
        {% for chapter, verses in chapters.items() %}
        <div class="chapter-group">
            <strong>Chapter {{ chapter }}:</strong>
            <span class="verse-list">{% for verse_data in verses %}<a href="/book/{{ book|urlencode }}/chapter/{{ chapter }}/verse/{{ verse_data.verse }}" class="verse-link" title="{{ verse_data.ref_count }} cross-references">{{ verse_data.verse }}</a><span class="ref-badge">{{ verse_data.ref_count }}</span>{% if not loop.last %}, {% endif %}{% endfor %}</span>
            <span class="verse-count">({{ verses|length }} {% if verses|length == 1 %}verse{% else %}verses{% endif %})</span>
        </div>
        {% endfor %}
    </section>
    {% endfor %}

    <section style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
        <h2>Coverage Statistics</h2>
        <table>
            <tr>
                <td><strong>Total Books with Cross-References</strong></td>
                <td>{{ total_books }} of 66</td>
            </tr>
            <tr>
                <td><strong>Total Verses with Cross-References</strong></td>
                <td>{{ "{:,}".format(total_verses) }} of 31,102</td>
            </tr>
            <tr>
                <td><strong>Coverage Percentage</strong></td>
                <td>{{ "%.1f"|format((total_verses / 31102) * 100) }}%</td>
            </tr>
            <tr>
                <td><strong>Total Cross-References</strong></td>
                <td>{{ "{:,}".format(total_refs) }}</td>
            </tr>
            <tr>
                <td><strong>Average per Verse</strong></td>
                <td>{{ "%.1f"|format(total_refs / total_verses) }}</td>
            </tr>
        </table>
    </section>
</article>

<style>
    .subtitle {
        font-size: 1.2rem;
        color: #666;
        margin-top: -1rem;
        margin-bottom: 2rem;
        font-style: italic;
    }

    .toc {
        margin: 2rem 0;
        padding: 1.5rem;
        background: var(--bg-color);
        border: 2px solid var(--border-color);
        border-radius: 4px;
    }

    .toc h2 {
        margin-top: 0;
        margin-bottom: 1rem;
        font-size: 1.3rem;
        color: var(--text-strong);
    }

    .toc-columns {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.5rem;
    }

    .toc-link {
        text-decoration: none;
        color: var(--link-color);
    }

    .toc-link:hover {
        text-decoration: underline;
    }

    .book-section {
        margin: 2.5rem 0;
        padding: 1.5rem;
        background: var(--bg-color);
        border: 1px solid var(--border-color);
        border-radius: 4px;
    }

    .book-section h2 {
        margin-top: 0;
        margin-bottom: 1rem;
        font-size: 1.5rem;
        color: var(--text-strong);
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.5rem;
    }

    .chapter-group {
        margin: 0.75rem 0;
        padding: 0.5rem 0;
        line-height: 1.8;
    }

    .chapter-group strong {
        display: inline-block;
        min-width: 100px;
        color: var(--text-secondary);
    }

    .verse-list {
        display: inline;
    }

    .verse-link {
        text-decoration: none;
        color: var(--link-color);
    }

    .verse-link:hover {
        text-decoration: underline;
    }

    .ref-badge {
        font-size: 0.85em;
        color: var(--text-tertiary);
        vertical-align: super;
    }

    .verse-count {
        margin-left: 0.5rem;
        color: var(--text-tertiary);
        font-size: 0.9rem;
        font-style: italic;
    }

    table {
        width: 100%;
        border-collapse: collapse;
        margin: 1.5rem 0;
    }

    tr {
        border-bottom: 1px solid var(--border-color);
    }

    td {
        padding: 0.75rem 1rem;
    }

    td:first-child {
        width: 60%;
    }

    td:last-child {
        text-align: right;
        font-family: 'Consolas', 'Monaco', monospace;
        color: var(--text-secondary);
    }

    a[target="_blank"]::after {
        content: " ↗";
        font-size: 0.8em;
        opacity: 0.6;
    }
</style>
{% endblock %}
