{% include 'header.html' %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/users.css') }}"> {% include 'wrapper.html' %}
<div class="container-users">

    <h2 style="font-weight: bolder;font-size: 36px;" class="inline">Users</h2>

    <form action="{{ url_for('export_users') }}" method="POST" class="inline">
        <button style="float:right; margin-top: 10px;" name="type" value="csv" class="btn btn-primary export-users-btn inline">export to
      CSV</button>
    </form>
    <select value="None" onchange="sortUsers()" class="select-type" id="type" name="sort_ports">
    <option value="All" selected disabled hidden>All</option>
    <option>All</option>
    {% for userType in allUserTypes %}
        <option>{{ userType }}</option>
    {% endfor %}
  </select>
    </br>
    </br>

    <table id="users-table" class="table table-dark table-striped">
        <thead>
            <tr>
                <th>Username</th>
                <th>Password</th>
                <th>Permissions</th>
                <th>Found on</th>
                <th>User Type</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            {% for name in data %} {% for info in data[name] %}
            <tr style="overflow:scroll">
                <td><a class="hover-user-details" onclick="copyToClipboard(this.innerHTML)" style="padding: 5px 10px;" id="user-{{ info[5] }}" href="#">{{ name }}</a>
                </td>
                <td onclick="copyToClipboard(this.innerHTML)" style="cursor:pointer;">{{ info[0] }}</td>
                <td>{{ info[1] }}</td>
                <td>{{ info[2] }}</td>
                <td>{{ info[3] }}</td>
                <td style="display: none;">{{ info[4] }}</td>
                <td><a href="{{ url_for('delete_user') }}?id={{ info[5] }}" onclick="this.parentElement.parentElement.remove()"><i class="fas fa-trash"
                style="margin-left: 15px; color: rgb(212, 71, 71);"></i></a></td>
            </tr>
            {% endfor %} {% endfor %}
            <tr style="overflow:scroll">
                <form action="{{ url_for('create_user') }}" method="POST" id="user-form">
                    <td><input class="username-create-input modern-input" type="text" name="username" maxlength="" placeholder="Username"></td>
                    <td><input class="modern-input" type="text" name="password" placeholder="Password"></td>
                    <td><input class="modern-input" type="text" name="permissions" placeholder="Permissions"></td>
                    <td><input class="modern-input" type="text" name="found" placeholder="Found On"></td>
                    <td id="type_selector">
                        {% if allUserTypes|length %}
                        <select id="userTypeSelector" name="user_type_select" class="exec-users-input inline" id="select_type" onchange="addNewUserType(this)">
                            {% for userType in allUserTypes %}
                                <option>{{ userType }}</option>
                            {% endfor %}
                            <option>Other</option>
                        </select>
                        <input class="modern-input" type="text" name="user_type" style="display: none;" id="userType" placeholder="User Type"> {% else %}
                        <input class="modern-input" type="text" name="user_type" id="userType" placeholder="User Type"> {% endif %}


                    </td>
                    <td><a onclick="submitUserForm()" href="#"><i class="fas fa-plus" style="margin: 5px 15px;"></i></a>
                    </td>
                </form>
            </tr>
        </tbody>
    </table>
</div>
<form enctype="multipart/form-data" action="{{ url_for('add_users_from_file') }}" method="POST">
    <input type="hidden" id="root" name="location"></input>
    <input type="file" name="upload_file" id="file" onchange="document.getElementById('root').value=document.getElementById('type').value;form.submit()" class="import-btn" multiple />
    <label class="btn btn-primary" for="file"><i class="fas fa-upload"></i></label>
</form>

{% include 'user.html' %} {% include 'wrapper_end.html' %}
<script>
    key_sc($(".export-users-btn"), 'e');
    key_sc($(".username-create-input"), 'n');
    key_sc($(".import-btn"), 'u');
</script>
<script src="{{ url_for('static', filename='js/users.js') }}"></script>
{% include 'footer.html' %}