{% extends "base.html" %}
{% load static %}
{% block title %}
    文章详情:{{ article.title }}
{% endblock title %}
{% block content %}
    <div class="container">
        <div class="row">
            <div class="col-3 mt-4">
                <h4><strong>目录</strong></h4>
                <hr>
                <div>
                    {{ tor|safe }}
                </div>
            </div>
            <div class="col-9">
                <h1 class="mt-4 mb-4">
                    {{ article.title }}
                </h1>

                <div class="col-12 alert alert-success">
                    作者: {{ article.author }}
                    {% if user == article.author %}
                        · <a href="#" onclick="confirm_delete()">
                        删除文章
                    </a>
                        · <a href="{% url 'article:article_update' article.id %}">
                        编辑文章
                    </a>
                    {% endif %}
                    <div>
                        浏览:{{ article.total_views }}
                    </div>
                    <form style="display: none"
                          id="safa_delete"
                          action="{% url 'article:article_safe_delete' article.id %}"
                          method="post"
                    >
                        {% csrf_token %}
                        <button type="submit">
                            发送
                        </button>
                    </form>
                </div>
                {% if article.avatar %}
                    <div class="row mt-2">
                        <img src="{{ article.avatar.url }}"
                             alt="avatar"
                             style="max-width: 100%; border-radius: 20px;"
                        >
                    </div>
                    <hr/>
                {% endif %}
                <div class="col-12">
                    <p>
                        {{ article.body|safe }}
                    </p>
                </div>
                <hr>
                {% if user.is_authenticated %}
                    <div>
                        <form action="{% url 'comment:post_comment' article.id %}" method="post">
                            {% csrf_token %}
                            <div class="form-group">
                                <label for="body">
                                    <strong>
                                        发表评论
                                    </strong>
                                </label>
                                <!--<textarea type="text" class="form-control" id="body" name="body" rows="2"></textarea>-->
                                <div>
                                    {{ comment_form.media }}
                                    {{ comment_form.body }}
                                </div>
                            </div>
                            <button type="submit" class="btn btn-primary">发送</button>
                        </form>
                    </div>
                    <br>
                {% else %}
                    <br>
                    <h5 class="row justify-content-center">
                        请<a href="{% url 'userprofile:login' %}">登录</a>后回复
                    </h5>
                    <br>
                {% endif %}
                <h4>共有{{ comments.count }}条评论</h4>
                <div>
                    {% for comment in comments %}
                        <hr>
                        <p>
                            <strong style="color: pink">
                                {{ comment.user }}
                            </strong>于
                            <span style="color: green">
                        {{ comment.created|date:"Y-m-d H:i:s" }}
                    </span>时评论道:
                        </p>
                        <pre style="font-family: inherit;font-size: 1em;">
                    {{ comment.body|safe }}
                </pre>
                    {% endfor %}
                </div>
            </div>
        </div>
    </div>
    <script>
        function confirm_delete() {
            layer.open({
                title: "删除文章",
                content: "确认删除这篇文章吗？",
                yes: function (index, layero) {
                    $('form#safe_delete button').click();
                    layer.close(index);
                },
            })
        }
    </script>
    <script src="{% static 'ckeditor/ckeditor/plugins/prism/lib/prism/prism_patched.min.js' %}"></script>
    <link rel="stylesheet" href="{% static 'prism/prism.css' %}">
{% endblock content %}
{% block script %}
<script>
    $(".django-ckeditor-widget").removeAttr('style');
</script>
{% endblock script %}