{% extends "admin/base_site.html" %}
{% load i18n static %}

{% block extrastyle %}
{{ block.super }}
<style>
    .restore-container {
        max-width: 900px;
        margin: 20px auto;
    }

    .warning-box {
        background: #fff3cd;
        border: 1px solid #ffc107;
        border-radius: 4px;
        padding: 15px;
        margin-bottom: 20px;
    }

    .warning-box h3 {
        margin-top: 0;
        color: #856404;
    }

    .version-info {
        background: #f8f9fa;
        border: 1px solid #dee2e6;
        border-radius: 4px;
        padding: 20px;
        margin-bottom: 20px;
    }

    .version-info h3 {
        margin-top: 0;
        border-bottom: 2px solid #007bff;
        padding-bottom: 10px;
    }

    .info-grid {
        display: grid;
        grid-template-columns: 150px 1fr;
        gap: 10px;
        margin-bottom: 15px;
    }

    .info-label {
        font-weight: bold;
        color: #495057;
    }

    .content-preview {
        background: #ffffff;
        border: 1px solid #dee2e6;
        border-radius: 4px;
        padding: 15px;
        max-height: 300px;
        overflow-y: auto;
        margin-top: 10px;
    }

    .action-buttons {
        margin-top: 20px;
        padding-top: 20px;
        border-top: 1px solid #dee2e6;
    }

    .btn-restore {
        background: #28a745;
        color: white;
        padding: 10px 20px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        font-size: 14px;
        margin-right: 10px;
    }

    .btn-restore:hover {
        background: #218838;
    }

    .btn-cancel {
        background: #6c757d;
        color: white;
        padding: 10px 20px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        font-size: 14px;
    }

    .btn-cancel:hover {
        background: #5a6268;
    }

    .btn-compare {
        background: #007bff;
        color: white;
        padding: 10px 20px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        font-size: 14px;
        text-decoration: none;
        display: inline-block;
    }

    .btn-compare:hover {
        background: #0056b3;
        color: white;
    }
</style>
{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
    &rsaquo; <a href="{% url 'admin:blog_articleversion_changelist' %}">文章版本</a>
    &rsaquo; 恢复版本 v{{ version.version_number }}
</div>
{% endblock %}

{% block content %}
<div class="restore-container">
    <h1>恢复文章版本</h1>

    <div class="warning-box">
        <h3>⚠️ 重要提示</h3>
        <ul>
            <li>恢复版本会将文章内容替换为所选版本的内容</li>
            <li>当前版本的内容会被自动保存到历史记录中</li>
            <li>此操作可以撤销（通过恢复到其他版本）</li>
        </ul>
    </div>

    <div class="version-info">
        <h3>版本信息</h3>

        <div class="info-grid">
            <div class="info-label">版本号:</div>
            <div>v{{ version.version_number }}</div>

            <div class="info-label">标题:</div>
            <div>{{ version.title }}</div>

            <div class="info-label">创建时间:</div>
            <div>{{ version.creation_time|date:"Y-m-d H:i:s" }}</div>

            <div class="info-label">创建者:</div>
            <div>{{ version.created_by|default:"系统" }}</div>

            <div class="info-label">变更说明:</div>
            <div>{{ version.change_summary|default:"无" }}</div>

            <div class="info-label">分类:</div>
            <div>{{ version.category_name }}</div>

            <div class="info-label">状态:</div>
            <div>
                {% if version.status == 'p' %}已发布
                {% elif version.status == 'd' %}草稿
                {% else %}{{ version.status }}
                {% endif %}
            </div>
        </div>

        <div>
            <strong class="info-label">内容预览:</strong>
            <div class="content-preview">
                {{ version.body|truncatewords:200|safe }}
            </div>
        </div>
    </div>

    <div class="version-info">
        <h3>当前版本信息</h3>

        <div class="info-grid">
            <div class="info-label">标题:</div>
            <div>{{ current.title }}</div>

            <div class="info-label">最后修改:</div>
            <div>{{ current.last_mod_time|date:"Y-m-d H:i:s" }}</div>

            <div class="info-label">分类:</div>
            <div>{{ current.category.name }}</div>
        </div>
    </div>

    <form method="post">
        {% csrf_token %}
        <div class="action-buttons">
            <button type="submit" class="btn-restore">✓ 确认恢复此版本</button>
            <a href="{% url 'admin:compare_article_version' version.id %}" class="btn-compare">📊 查看详细对比</a>
            <a href="{% url 'admin:blog_articleversion_changelist' %}" class="btn-cancel">取消</a>
        </div>
    </form>
</div>
{% endblock %}
