{% load i18n %}
{% load lfc_tags %}

{% ifhasperm edit %}
    <h2>
        {{ form.allow_comments.label_tag }}
    </h2>

    <form action="{% url 'lfc_update_comments' obj.id %}"
          method="POST">
        <div class="field">
            <div>
                {{ form.allow_comments }}
                <input class="ajax-submit"
                       name="allow_comments"
                       type="submit"
                       value="{% trans 'Save' %}" />
            </div>
        </div>
    </form>

    <h2 class="middle-heading">
        {% trans 'Comments' %}
    </h2>

    {% if comments %}
        <form action="{% url 'lfc_update_comments' obj.id %}"
              method="post">

            <table class="lfs-manage-table large">
                <tr>
                    <th class="tiny">
                        <input type="checkbox"
                               class="select-all"
                               value="comments" />
                    </th>
                    <th class="small">
                        {% trans 'Name' %}
                    </th>
                    <th class="small">
                        {% trans 'URL' %}
                    </th>
                    <th>
                        {% trans 'Comment' %}
                    </th>
                    <th class="tiny right-padding">
                        {% trans 'Public' %}
                    </th>
                    <th class="tiny right-padding">
                        {% trans 'Edit' %}
                    </th>
                </tr>
                {% for comment in comments %}
                    <tr>
                        <td>
                            <input type="hidden"
                                   name="comment_id-{{ comment.id }}" />
                            <input type="checkbox"
                                   class="select-comments"
                                   name="delete-{{ comment.id }}"
                                   style="float:left" />
                        </td>
                        <td>
                            {% if comment.email %}
                                <a href="mailto:{{ comment.email }}">
                                    {{ comment.name }}
                                </a>
                            {% else %}
                                {{ comment.name }}
                            {% endif %}
                        </td>
                        <td>
                            {% if comment.user_url %}
                                <a target="_blank" href="{{ comment.user_url }}">{{ comment.user_url }}</a>
                            {% endif %}
                        </td>
                        <td>
                            {{ comment.comment|truncatewords:6 }}
                        </td>
                        <td>
                            <input type="checkbox"
                                   name="is_public-{{ comment.id }}"
                                   style="float:left"
                                   {% if comment.is_public %}checked="checked"{% endif %} />
                        </td>
                        <td class="right-padding">
                            <a class="ajax-link"
                               href="{% url 'lfc_edit_comment' comment.id %}">
                                <img src="{{ STATIC_URL }}lfc/icons/edit.png"
                                     alt="{% trans 'Edit' %}"
                                     title="{% trans 'Edit object' %}" />
                            </a>
                        </td>
                    </tr>
                {% endfor %}
            </table>
            <div class="manage-form-buttons">
                <input class="ajax-submit"
                       type="submit" name="update" value="{% trans 'Update comments' %}" />
                <input class="ajax-submit"
                       type="submit" name="delete" value="{% trans 'Delete comments' %}" />
            </div>
        </form>
    {% else %}
        <span>{% trans 'There are no comments' %}</span>
    {% endif %}
{% else %}
    <h2 class="first-heading">
        {% trans 'Allow comments' %}
    </h2>
    <div class="padding-b">
        {{ obj.get_allow_comments_display }}
    </div>

    <h2 class="first-heading">
        {% trans 'Comments' %}
    </h2>

    {% if comments %}
        <table class="lfs-manage-table half">
            <tr>
                <th class="middle">
                    {% trans 'Name' %}
                </th>
                <th>
                    {% trans 'Public' %}
                </th>
            </tr>
            {% for comment in comments %}
                <tr>
                    <td>
                        {{ comment.name }}
                    </td>
                    <td>
                        {% if comment.is_public %}
                            {% trans "Yes" %}
                        {% else %}
                            {% trans "No" %}
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        </table>
    {% else %}
        <span>{% trans 'There are no comments' %}</span>
    {% endif %}
{% endifhasperm %}
