{% extends 'members_template.html' %}

{% block title %}{{ member }}{% endblock %}

{% block members_content %}
    <div class="row xsd-member-profile">
        <div class="col-md-6">
            <div class="xsd-profile-card">
                {% if member.top_qual %}
                    <div class="qual-banner">
                        <div class="qual-banner__colour xsd-qual-banner--{{ member.top_qual.code }}">&nbsp;</div>
                    </div>
                {% endif %}

                <div class="profile-card__content">
                    {% if member.user %}
                        <img src="{{ member.avatar_md }}" alt="Profile Picture" class="avatar"/>
                    {% endif %}

                    <h2>{{ member }}</h2>

                    {% if is_members and not member.archived %}
                        <div class="btn-group btn-group-sm" role="group">
                            <a href="{% url 'xsd_members:MemberEdit' member.pk %}" class="btn btn-secondary">
                                <i class="fa fa-pencil"></i> Edit
                            </a>

                            <div class="btn-group" role="group">
                                <button id="member-dropdown" type="button"
                                        class="btn btn-sm btn-secondary dropdown-toggle"
                                        data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    <i class="fa fa-ellipsis-h"></i>
                                </button>
                                <div class="dropdown-menu" aria-labelledby="member-dropdown">
                                    {% if member_useraccount_form %}
                                        <a class="dropdown-item" href="#" data-toggle="modal"
                                           data-target="#member_useraccount_modal">
                                            <i class="fa fa-key"></i> Account Settings
                                        </a>
                                    {% endif %}

                                    {% if not member.archived %}
                                        <a href="{% url 'xsd_members:MemberArchive' member.pk %}"
                                           class="dropdown-item text-warning">
                                            <i class="fa fa-archive"></i> Archive
                                        </a>
                                    {% endif %}

                                    <a href="{% url 'xsd_members:MemberDelete' member.pk %}"
                                       class="dropdown-item text-danger">
                                        <i class="fa fa-trash"></i> Delete
                                    </a>

                                    <a href="{% url 'xsd_members:MemberHistory' member.pk %}" class="dropdown-item">
                                        <i class="fa fa-history"></i> Object History
                                    </a>
                                </div>
                            </div>
                        </div>

                    {% elif myself %}
                        <a href="{% url 'xsd_members:MyProfileEdit' %}" class="btn btn-sm btn-secondary">
                            <i class="fa fa-pencil"></i> Edit
                        </a>
                    {% endif %}

                    <div class="btn-group btn-group-sm">
                        {% if is_training %}
                            <a href="{% url 'xsd_training:TraineeNotes' member.pk %}" class="btn btn-secondary">
                                <i class="fa fa-share"></i> Trainee Profile
                            </a>
                        {% endif %}
                    </div>

                    {% if request.user.is_superuser and member.user %}
                        <form style="display:inline" action="/hijack/{{ member.user.pk }}/" method="post">
                            {% csrf_token %}
                            <button class="btn btn-sm btn-secondary" type="submit">
                                <i class="fa fa-user-secret"></i> Hijack
                            </button>
                        </form>
                    {% endif %}
                </div>
            </div>

            <div>
                {% if is_members and not member.verified %}
                    <div class="alert alert-warning">
                        <p><strong><i class="fa fa-flag"></i> This account is new and needs to
                            be verified.</strong></p>
                        <p>As anyone can create an account on this system new accounts must be approved to allow
                            access.</p>
                        <form action="action/approve/" method="POST">
                            {% csrf_token %}
                            <button type="submit" class="btn btn-sm btn-success">
                                <i class="fa fa-check"></i> Approve
                            </button>
                        </form>
                    </div>
                {% endif %}

                {% if is_members and member.archived %}
                    <div class="alert alert-warning">
                        <p><strong><i class="fa fa-archive"></i> {{ member.first_name }}'s record has been
                            archived</strong></p>
                        <p>Personal data has been expunged. If they sign into the site they'll be prompted to re-enter
                            these details and their record will be restored.</p>

                        <form action="action/reinstate/" method="POST">
                            {% csrf_token %}
                            <button type="submit" class="btn btn-success btn-sm" type="button">
                                <i class="fa fa-mail-forward"></i> Restore
                            </button>
                            this record
                        </form>
                    </div>
                {% endif %}

                <p>{{ member.first_name }} joined the database on {{ member.date_joined|date }} and last logged in
                    on {{ member.user.last_login }}</p>

                {% if member.membership_problem %}
                    <div class="alert alert-danger">
                        <i class="fa fa-exclamation-triangle"></i> <strong>Uh-oh</strong> There are currently issues
                        with {{ member.first_name }}'s membership. Until this is fixed {{ member.heshe|lower }} cannot
                        go diving.
                    </div>
                {% endif %}
            </div>

        </div>

        <div class="col-md-6">
            <h3><i class="fa fa-envelope"></i> Personal Details</h3>
            <table class="table">
                <tr>
                    <th>Address</th>
                    <td>{% if not member.address or member.post_code %}
                        <i class="fa fa-exclamation-triangle text-danger"></i>
                        {% else %}{{ member.formatted_address|safe }}<br/>{{ member.postcode }}{% endif %}</td>
                </tr>
                <tr>
                    <th>Email</th>
                    <td>{{ member.email }}{% if not member.email %}
                        <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                </tr>
                <tr>
                    <th>Home Phone</th>
                    <td>{{ member.home_phone }}{% if not member.home_phone %}
                        <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                </tr>
                <tr>
                    <th>Mobile Phone</th>
                    <td>{{ member.mobile_phone }}{% if not member.mobile_phone %}
                        <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                </tr>
                <tr>
                    <th>Date of Birth</th>
                    <td>{% if member.date_of_birth %}{{ member.date_of_birth }}{% else %}
                        <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                </tr>
                <tr>
                    <th>Allergies or other requirements</th>
                    <td>
                        {{ member.alergies| linebreaks }}{% if not member.alergies %}<em>None</em><br/>{% endif %}
                        {% if member.veggie %}Vegetarian{% else %}Omnivore{% endif %}
                    </td>
                </tr>

            </table>
        </div>
    </div>

    {# Second row #}
    <div class="row">
        <div class="col-md-6">
            <h3><i class="fa fa-home"></i> Club Details</h3>
            {% if member.club_expiry or not myself %}
                <table class="table">
                    <tr>
                        <th>Club ID</th>
                        <td>{{ member.uid }}</td>
                    </tr>
                    {% if member.student_id %}
                        <tr>
                            <th>Student ID</th>
                            <td>{{ member.student_id }}</td>
                        </tr>{% endif %}
                    <tr>
                        <th>Membership Type</th>
                        <td>{{ member.club_membership_type }}</td>
                    </tr>
                    <tr>
                        <th>Membership Expiry Date</th>
                        <td>{{ member.club_expiry }}{% if member.club_expired %}
                            <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                    </tr>
                    <tr>
                        <th>Medical Form Expiry Date</th>
                        <td>{{ member.medical_form_expiry }}{% if member.medical_form_expired %}
                            <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                    </tr>
                </table>
            {% else %}
                <div class="alert alert-info">
                    <strong>Joining The Club</strong> It looks like you're new here, in order to take part in club
                    activities you need to be a paying member, contact the committee for more information.
                </div>
            {% endif %}
        </div>

        <div class="col-md-6">
            <h3><i class="fa fa-user"></i> Next of Kin</h3>
            <table class="table">
                <tr>
                    <th>Name</th>
                    <td>{{ member.next_of_kin_name }}{% if not member.next_of_kin_name %}
                        <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                </tr>
                <tr>
                    <th>Relation</th>
                    <td>{{ member.next_of_kin_relation }}{% if not member.next_of_kin_relation %}
                        <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                </tr>
                <tr>
                    <th>Phone</th>
                    <td>{{ member.next_of_kin_phone }}{% if not member.next_of_kin_phone %}
                        <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                </tr>
            </table>
        </div>
    </div>

    {# Third row #}
    <div class="row">
        <div class="col-md-6">
            <h3><i class="fa fa-trophy"></i> Qualification Details</h3>
            <table class="table">
                <tr>
                    <th>Current Qualification</th>
                    <td>
                        <i class="fa fa-square xsd-qual-fg--{{ member.top_qual.code }}" aria-hidden="true"></i>
                        {{ member.top_qual }}
                    </td>
                </tr>
                <tr>
                    <th>Training For</th>
                    <td>{{ member.training_for }}</td>
                </tr>
                {% if member.top_instructor_qual or not myself %}
                    <tr>
                        <th>Instructor Qualification</th>
                        <td>{{ member.top_instructor_qual }}</td>
                    </tr>

                    {% if member.top_instructor_qual.rank >= 37 %}
                        <tr>
                            <th>Instructor Number</th>
                            <td>{{ member.top_instructor_qual.code }} {{ member.instructor_number }}</td>
                        </tr>
                    {% endif %}

                {% endif %}
                <tr>
                    <th>SDCs</th>
                    <td>
                        <ul class="xsd-member-sdc-list">
                            {% for sdc in member.sdcs.all %}
                                <li>{{ sdc }}</li>{% endfor %}
                        </ul>
                    </td>
                </tr>
                <tr>
                    <th>Other Qualifications</th>
                    <td>{{ member.other_qualifications | linebreaks }}</td>
                </tr>


            </table>
        </div>

        <div class="col-md-6">
            <h3><i class="icon-bsac"></i> BSAC Details</h3>
            {% if member.bsac_expiry or not myself %}
                <table class="table">
                    <tr>
                        <th>BSAC ID</th>
                        <td>{% if member.bsac_id %}A{{ member.bsac_id }}{% else %}
                            <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                    </tr>
                    <tr>
                        <th>Membership Type</th>
                        <td class="last-child-mb0">
                            {% if member.bsac_direct_debit %}<p>Pays by direct debit</p>{% endif %}
                            {% if member.bsac_direct_member %}<p>Member of BSAC directly</p>{% endif %}
                            {% if member.bsac_member_via_another_club %}<p>Member of BSAC through another club</p>{% endif %}
                            {% if not member.bsac_direct_member and not member.bsac_member_via_another_club %}
                                <p>Standard club member</p>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th>BSAC Expiry Date</th>
                        <td>{{ member.bsac_expiry }}{% if member.bsac_expired %}
                            <i class="fa fa-exclamation-triangle text-danger"></i>{% endif %}</td>
                    </tr>
                </table>
            {% else %}
                <div class="alert alert-info">
                    <strong>Joining BSAC</strong> This scuba club is a branch of the larger British Sub Aqua Club, you
                    must also hold a membership with BSAC to participate.
                </div>
            {% endif %}
        </div>
    </div>

    {% if member_useraccount_form %}
        {% include 'xsd_members/components/account_modal.html' %}
    {% endif %}

{% endblock %}
