{% extends "base.html" %}
{% from 'macros/ui.html' import group_panel, member_panel %}

{% block heading %}
    <a href="/groups">Groups</a>
{% endblock %}

{% block subheading %}
    {{group.groupname}} {% if not group.enabled %}<small>(disabled)</small>{% endif %}
{% endblock %}

{% block headingbuttons %}
    {% if current_user.my_role(members) == "owner" %}
        {% if group.enabled %}
            <button class="btn btn-danger" data-toggle="modal" data-target="#disableModal">
                <i class="fa fa-minus"></i> Disable
            </button>
        {% else %}
            <button class="btn btn-warning" data-toggle="modal" data-target="#enableModal">
                <i class="fa fa-plus"></i> Enable
            </button>
        {% endif %}
    {% endif %}

    <div class="btn-group">
        <a href="/groups/{{group.name}}/requests"
           class="btn btn-default"><i class="fa fa-list"></i> Requests</a>
        {% if current_user.my_role(members) in ("manager", "owner") and num_pending %}
            <a href="/groups/{{group.name}}/requests?status=pending"
               title="Pending Requests"
               class="btn btn-default btn-pending">{{ num_pending }}</a>
        {% endif %}
    </div>

    <a href="/groups/{{group.name}}/join"
       class="btn btn-success"><i class="fa fa-user"></i> Join</a>

    {% if current_user.my_role(members) in ("manager", "owner") %}
        <a href="/groups/{{group.name}}/edit"
           class="btn btn-primary"><i class="fa fa-edit"></i> Edit</a>
    {% endif %}
{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-6">
        <blockquote><p>
            <em>{{group.description|default("&nbsp;", True)}}</em>
        </p></blockquote>
    </div>
    <div class="col-md-6">
        <h4>
            {% if group.canjoin == "canjoin" %}
                <span class="label label-success pull-right">
                    <i class="fa fa-group"></i> Open Membership
                </span>
            {% else %}
                <span class="label label-info pull-right">
                    <i class="fa fa-group"></i> Requires Approval
                </span>
            {% endif %}
        </h4>
    </div>
</div>

<div class="row">
    <div class="col-md-7">
        {{ member_panel(400, members) }}
    </div>
    <div class="col-md-5">
        {{ group_panel(400, groups) }}
    </div>
</div>

<div class="modal fade" id="enableModal" tabindex="-1" role="dialog"
      aria-labelledby="enableModal" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title">Enable Group</h4>
           </div>
            <div class="modal-body">
                <p>Are you sure you want to Enable this group?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">Close</button>
                <form action="/groups/{{group.id}}/enable" method="post"
                      style="display: inline;">
                    {{ xsrf_form() }}
                    <button type="submit" class="btn btn-primary">Enable</button>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="disableModal" tabindex="-1" role="dialog"
      aria-labelledby="disableModal" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title">Disable Group</h4>
           </div>
            <div class="modal-body">
                <p>
                    Are you sure you want to Disable this group? Only an Admin will
                    be able to re-enable.
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">Close</button>
                <form action="/groups/{{group.id}}/disable" method="post"
                      style="display: inline;">
                    {{ xsrf_form() }}
                    <button type="submit" class="btn btn-primary">Disable</button>
                </form>
            </div>
        </div>
    </div>
</div>

{% endblock %}
