{% extends "core/base.jinja" %}
{% from "core/macros.jinja" import user_link_with_pict, delete_godfather %}

{%- block additional_css -%}
  <link rel="stylesheet" href="{{ static('user/user_godfathers.scss') }}">
{%- endblock -%}

{% block title %}
  {% trans user_name=profile.get_display_name() %}{{ user_name }}'s family{% endtrans %}
{% endblock %}

{% block content %}
  <div class="container">
    {% if godchildren or godfathers %}
      <a
        href="{{ url('core:user_godfathers_tree', user_id=profile.id) }}"
        class="btn btn-blue"
        id="family-tree-link"
      >
        {% trans %}Show family tree{% endtrans %}
      </a>
    {% endif %}

    <h4>{% trans %}Godfathers / Godmothers{% endtrans %}</h4>
    {% if godfathers %}
      <ul class="users">
        {% for u in godfathers %}
          <li class="users-card">
            <a href="{{ url('core:user_godfathers', user_id=u.id) }}" class="mini_profile_link">
              {{ u.get_mini_item() | safe }}
            </a>
            {% if user == profile or user.is_root or user.is_board_member %}
              <form
                method="post"
                class="no-margin"
                action="{{ url("core:user_godfathers_delete", user_id=profile.id, godfather_id=u.id, is_father=True) }}"
              >
                {% csrf_token %}
                <input type="submit" class="link-like" value="{% trans %}Delete{% endtrans %}">
              </form>
            {% endif %}
          </li>
        {% endfor %}
      </ul>

    {% else %}
      <p>{% trans %}No godfathers / godmothers{% endtrans %}
    {% endif %}

    <h4>{% trans %}Godchildren{% endtrans %}</h4>
    {% if godchildren %}
      <ul class="users">
        {% for u in godchildren %}
          <li class="users-card">
            <a href="{{ url('core:user_godfathers', user_id=u.id) }}" class="mini_profile_link">
              {{ u.get_mini_item()|safe }}
            </a>
            {% if user == profile or user.is_root or user.is_board_member %}
              <form
                method="post"
                class="no-margin"
                action="{{ url("core:user_godfathers_delete", user_id=profile.id, godfather_id=u.id, is_father=False) }}"
              >
                {% csrf_token %}
                <input type="submit" class="link-like link-red" value="{% trans %}Delete{% endtrans %}">
              </form>
            {% endif %}
          </li>
        {% endfor %}
      </ul>
    {% else %}
      <p>{% trans %}No godchildren{% endtrans %}
    {% endif %}

    {% if profile == user or user.is_root %}
      <form action="" method="post">
        {% csrf_token %}
        {{ form.as_p() }}
        <p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
      </form>
    {% endif %}
  </div>
{% endblock %}

