{% load static %}
{% load i18n %}
{% load admin_url %}
{% load mastodon %}
{% load oauth_token %}
{% load truncate %}

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{{ site_name }} - {% if form.instance.id %}{% trans '编辑' %} {{ form.instance.title }} {% else %}{% trans '添加' %}{% endif %}</title>
  {% include "common_libs.html" with jquery=0 %}
</head>

<body>
  <div id="page-wrapper">
    <div id="content-wrapper">
      {% include "partial/_navbar.html" %}

      <section id="content" class="container">
        <div class="grid">
          <div style="float:right;padding-left:16px">
          {% if item %}
            <div class="aside-section-wrapper">
              {% for res in form.instance.external_resources.all %}
              <div class="action-panel">
                <div class="action-panel__label">{% trans '源网站' %}: <a href="{{ res.url }}">{{ res.site_name.label }}</a></div>
                <div class="action-panel__button-group">
                  <form method="post" action="{% url 'catalog:refetch' %}">
                    {% csrf_token %}
                    <input type="hidden" name="id" value="{{ res.id }}" >
                    <input type="hidden" name="url" value="{{ res.url }}" >
                    <input class="button" type="submit" value="{% trans '重新抓取' %}">
                  </form>
                </div>
                {% if request.user.is_staff %}
                <div class="action-panel__button-group">
                  <form method="post" action="{% url 'catalog:unlink' %}">
                    {% csrf_token %}
                    <input type="hidden" name="id" value="{{ res.id }}" >
                    <input class="button" type="submit" value="{% trans '取消关联' %}">
                  </form>
                </div>
                {% endif %}
              </div>
              {% endfor %}
            </div>

            {% if item.class_name == "movie" or item.class_name == "tvshow" %}
            <div class="aside-section-wrapper">
              <div class="action-panel">
                <div class="action-panel__label">{% trans '切换分类' %} </div>
                <div class="action-panel__button-group">
                  <form method="post" action="{% url 'catalog:recast' item.url_path item.uuid %}" onsubmit="return confirm('确认切换吗？');">
                    {% csrf_token %}
                    {% if item.class_name == "movie" %}
                    <input type="hidden" value="tvshow" name="class">
                    <input class="button" type="submit" value="{% trans '更改为剧集' %}">
                    {% endif %}
                    {% if item.class_name == "tvshow" %}
                    <input type="hidden" value="movie" name="class">
                    <input class="button" type="submit" value="{% trans '更改为电影' %}">
                    {% endif %}
                  </form>
                </div>
              </div>
            </div>
            {% endif %}

            {% if request.user.is_staff %}
            <div class="aside-section-wrapper">
              <div class="action-panel">

\
                <div class="action-panel__label">{% trans '合并到另一条目' %} </div>
                <div class="action-panel__button-group">
                  <form method="post" action="{% url 'catalog:merge' item.url_path item.uuid %}" onsubmit="return confirm('Confirm merging?');">
                    {% csrf_token %}
                    <input type="url" name="new_item_url" placeholder="目标条目URL" value="{{ item.merged_to_item.absolute_url }}" required><br>
                    <input class="button" type="submit" value="{% trans '提交' %}">
                  </form>
                </div>

                <div class="action-panel__label">{% trans '删除' %} </div>
                <div class="action-panel__button-group">
                  <form method="post" action="{% url 'catalog:delete' item.url_path item.uuid %}" onsubmit="return confirm('Confirm deletion?');">
                    {% csrf_token %}
                    <input class="button" type="submit" value="{% trans '提交' %}">
                  </form>
                </div>
              </div>

              {% if item.is_deteled %}
              <!-- TODO undelete -->
              {% endif %}
            </div>
            {% endif %}

          {% endif %}
          </div>
          <div class="single-section-wrapper" id="main">
            <form class="entity-form" action="{{ submit_url }}" method="post" enctype="multipart/form-data">
              {% csrf_token %}
              {{ form.media }}
              {{ form }}
              <hr/>
              <input class="button" type="submit" value="{% trans '提交' %}">
              <a href="{{ item.url | default:'javascript:history.go(-1)' }}" style="float:right;">返回</a>
            </form>
          </div>

          </section>
        </div>
        {% include "partial/_footer.html" %}
      </div>
    </body>


    </html>
