{% extends 'textdocs/base.html' %}

{% block title %}Version {{ version.version_number }} of {{ version.document.title }}{% endblock %}

{% block content %}

    <a href="{{ version.document.get_absolute_url }}" class="btn btn-secondary mb-3">‹ Back to Latest Version</a>

    {% if version.version_number != version.document.latest_version.version_number %}
    <div class="alert alert-warning" role="alert">
        <strong>Heads up!</strong> You are viewing an older version of this document (v{{ version.version_number }}).
    </div>
    {% endif %}

    <div class="card">
        <div class="card-header">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h2>{{ version.document.title }}</h2>
                    <h5 class="card-subtitle text-success">
                        Viewing Version {{ version.version_number }}
                    </h5>
                </div>
                <!-- --- NEW BUTTON --- -->
                <div>
                    <a href="{% url 'generate_version_pdf' pk=version.document.pk version_number=version.version_number %}" class="btn btn-info">
                        Export This Version to PDF
                    </a>
                </div>
            </div>
        </div>
        <div class="card-body">
            <h4 class="card-title">Introduction</h4>
            <div>{{ version.introduction|safe }}</div>
            <hr>
            <h4 class="card-title">Main Body</h4>
            <div>{{ version.main_body|safe }}</div>
            <hr>
            <h4 class="card-title">Conclusion</h4>
            <div>{{ version.conclusion|safe }}</div>
        </div>
    </div>
{% endblock %}