{% load seahub_tags i18n %}
<table>
    <tr>
        <th width="3%"><input type="checkbox" /></th>
        {% if is_pro %}
        <th width="21%">ID / {% trans "Name" %} / {% trans "Contact Email" %}</th>
        <th width="9%">{% trans "Status" %}</th>
        <th width="15%">{% trans "Role" %}</th>
        {% else %}
        <th width="33%">ID / {% trans "Name" %} / {% trans "Contact Email" %}</th>
        <th width="12%">{% trans "Status" %}</th>
        {% endif %}
        {% if show_institution %}
            <th width="14%">{% trans "Space Used / Quota" %}</th>
            <th width="10%">{% trans "Institution" %}</th>
            <th width="18%">{% trans "Create At / Last Login" %}</th>
            <th width="10%"></th>
        {% else %}
            <th width="16%">{% trans "Space Used / Quota" %}</th>
            <th width="22%">{% trans "Create At / Last Login" %}</th>
            <th width="14%"></th>
        {% endif %}
    </tr>

    {% for user in users %}
    <tr data-userid="{{user.email}}">
        <td><input type="checkbox" /></td>
        <td>
            <a href="{% url 'user_info' user.email %}">{{ user.email }}</a>
            {% if user.name %}<br />{{ user.name }}{% endif %}
            {% if user.contact_email %}<br />{{ user.contact_email }}{% endif %}
            {% if not is_admin_page %}
            {% if user.org %}
            <p style="font-size:11px;"><a href="{% url 'sys_org_info_user' user.org.org_id %}">({{user.org.org_name}})</a></p>
            {% endif %}
            {% if user.trial_info %}
            <p style="font-size:11px;">(Trial &nbsp;<a href="#" class="unset-trial" data-target="{{ user.email }}" data-url="{% url 'remove_trial' user.email %}">X</a>)</p>
            {% endif %}
            {% endif %}
        </td>
        <td>
            <div class="user-status">
              {% if user.is_active %}
                <span class="user-status-cur-value">{% trans "Active" %}</span>
              {% else %}
                <span class="user-status-cur-value">{% trans "Inactive" %}</span>
              {% endif %}
                <span title="{% trans "Edit"%}" class="user-status-edit-icon sf2-icon-edit op-icon vh"></span>
            </div>
            <select name="permission" class="user-status-select hide">
                <option value="1" {%if user.is_active %}selected="selected"{% endif %}>{% trans "Active" %}</option>
                <option value="0" {%if not user.is_active %}selected="selected"{% endif %}>{% trans "Inactive"%}</option>
            </select>
        </td>
        {% if is_pro %}
        <td>
            {% if not is_admin_page %}
            <div class="user-role">
                {% if user.is_guest %}
                    <span class="user-role-cur-value">{% trans "Guest" %}</span>
                {% elif user.is_default %}
                    <span class="user-role-cur-value">{% trans "Default" %}</span>
                {% else %}
                    <span class="user-role-cur-value">{{user.role}}</span>
                {% endif %}
                <span title="{% trans "Edit"%}" class="user-role-edit-icon sf2-icon-edit op-icon vh"></span>
            </div>
            <select name="role" class="user-role-select hide">
                <option value={{default_user}} {%if user.is_default %}selected="selected"{% endif %}>{% trans "Default" %}</option>
                <option value={{guest_user}} {%if user.is_guest %}selected="selected"{% endif %}>{% trans "Guest"%}</option>
                {% for role in extra_user_roles %}
                <option value={{role}} {%if user.role == role %}selected="selected"{% endif %}>{{ role }}</option>
                {% endfor %}
            </select>

            {% else %} {# else for `if not is_admin_page` #}
            <div class="admin-role">
                {% if user.admin_role == default_admin %}
                    <span class="admin-role-cur-value">{% trans "Default Admin" context "Default Administrator" %}</span>
                {% elif user.admin_role == system_admin %}
                    <span class="admin-role-cur-value">{% trans "System Admin" context "System Administrator" %}</span>
                {% elif user.admin_role == daily_admin %}
                    <span class="admin-role-cur-value">{% trans "Daily Admin" context "Daily Administrator" %}</span>
                {% elif user.admin_role == audit_admin %}
                    <span class="admin-role-cur-value">{% trans "Audit Admin" context "Audit Administrator" %}</span>
                {% else %}
                    <span class="admin-role-cur-value">{{user.admin_role}}</span>
                {% endif %}
                <span title="{% trans "Edit"%}" class="admin-role-edit-icon sf2-icon-edit op-icon vh"></span>
            </div>
            <select name="role" class="admin-role-select hide">
                <option value="{{ default_admin }}"{% if user.admin_role == default_admin %} selected="selected"{% endif %}>{% trans "Default Admin" context "Default Administrator" %}</option>
                <option value="{{ system_admin }}"{% if user.admin_role == system_admin %} selected="selected"{% endif %}>{% trans "System Admin" context "System Administrator" %}</option>
                <option value="{{ daily_admin }}"{% if user.admin_role == daily_admin %} selected="selected"{% endif %}>{% trans "Daily Admin" context "Daily Administrator" %}</option>
                <option value="{{ audit_admin }}"{% if user.admin_role == audit_admin %} selected="selected"{% endif %}>{% trans "Audit Admin" context "Audit Administrator" %}</option>
                {% for role in extra_admin_roles %}
                <option value="{{ role }}"{% if user.admin_role == role %} selected="selected"{% endif %}>{{ role }}</option>
                {% endfor %}
            </select>
            {% endif %}
        </td>
        {% endif %}
        <td style="font-size:11px;">
            {{ user.space_usage|seahub_filesizeformat }} /
            <span class="user-space-quota">
                {% if user.space_quota >= 0 %}
                {{ user.space_quota|seahub_filesizeformat }}
                {% elif user.space_quota == -2 %}
                --
                {% else %}
                <span class="error">{% trans "Error" %}</span>
                {% endif %}
            </span>
            <span title="{% trans "Edit Quota" %}" class="quota-edit-icon sf2-icon-edit op-icon vh"></span>
        </td>

        {% if show_institution %}
        <td>
            <div class="user-institution">
                <span class="user-institution-cur-value">{{ user.institution }}</span>
                <span title="{% trans "Edit"%}" class="user-institution-edit-icon sf2-icon-edit op-icon vh"></span>
            </div>
            <select name="institution" class="user-institution-select hide">
                <option value="" {% if user.institution == "" %} selected="selected"{% endif %}></option>
                {% for inst in institutions %}
                    <option value="{{inst}}" {% if user.institution == inst %} selected="selected"{% endif %}>{{inst}}</option>
                {% endfor %}
            </select>
        </td>
        {% endif %}

        <td>
            {% if user.source == "DB" %}
            {{ user.ctime|tsstr_sec }} /<br />
            {% else %}
            -- /
            {% endif %}
            {% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
        </td>
        <td>
          {% if not user.is_self %}
          <a href="#" class="remove-user-btn op vh" data-url="{% url 'user_remove' user.email %}" data-target="{{ user.email }}">{% trans "Delete" %}</a>
          <br />
          {% if user.source == "DB" %}
          <a href="#" class="reset-user-btn op vh" data-url="{% url 'user_reset' user.email %}" data-target="{{ user.email }}">{% trans "ResetPwd" %}</a>
          {% endif %}
          <br />
          {% if is_admin_page %}
          <a href="#" data-url="{% url 'user_remove_admin' user.email %}" data-target="{{ user.email }}" class="revoke-admin-btn op vh">{% trans "Revoke Admin" %}</a>
          {% endif %}
          {% endif %}
        </td>
    </tr>
    {% endfor %}
</table>

<form id="set-quota-form" method="post" action="" class="hide">{% csrf_token %}
    <h3>{% trans "Set quota" %}</h3>
    <input type="text" name="space_quota" class="input" /> MB
    <p class="tip">
    <span>{% trans "An integer that is greater than or equal to 0." %}</span><br />
    <span>{% trans "Tip: 0 means default limit" %}</span>
    </p>
    <p class="error hide"></p>
    <input type="submit" value="{% trans "Submit" %}" class="submit" />
</form>
