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

{% block title %}New Version for {{ document.title }}{% endblock %}

{% block content %}
    <h2>Create New Version for: <span class="text-primary">{{ document.title }}</span></h2>
    <p class="text-muted">
        You are editing the content from version {{ document.latest_version.version_number }}. 
        Saving will create version {{ document.latest_version.version_number|add:1 }}.
    </p>
    <hr>

    <form method="post">
        {% csrf_token %}

        {% if form.errors %}
            <div class="alert alert-danger">
                <strong>Please correct the errors below:</strong>
                <ul>
                    {% for field, errors in form.errors.items %}
                        {% for error in errors %}
                            <li>{{ field|title }}: {{ error }}</li>
                        {% endfor %}
                    {% endfor %}
                </ul>
            </div>
        {% endif %}

        {{ form.as_p }}
        
        <div class="mt-3">
            <button type="submit" class="btn btn-success">Save as New Version</button>
            <a href="{{ document.get_absolute_url }}" class="btn btn-secondary">Cancel</a>
        </div>
    </form>
{% endblock %}