@php
    $admin = 0;
    $isManagerOrHigher = 0;
    if($myUser != null){
        $admin = $myUser->admin;
        $isManagerOrHigher = $myUser->isManager(true);
    }

@endphp
        <!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="robots" content="noindex">

    <title>Users - Doxbin</title>
    <link rel="stylesheet" href="/legacy/index.css">
    @include('_scripts')
    <style>
        input[type=text] {
            line-height: 1.2;
            color: white;
            background: #282828;
            border: 0;
            border-radius: 2px;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 7px 5px;
            width: 200px;
        }

        input[type=text]::placeholder {
            color: rgb(167, 167, 167);
        }

        input[type=submit] {
            line-height: 1.2;
            color: white;
            background: #282828;
            border: 0;
            border-radius: 2px;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 7px 5px;
        }

        input {
            font-size: 100%;
        }

        .clear-search {
            line-height: 1.2;
            color: white;
            background: #282828;
            border: 0;
            border-radius: 2px;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 7px 5px;
        }

        .clear-search:hover, input[type=submit]:hover, .clear-search:focus {
            color: white;
            background: #3d3d3d;
            text-decoration: none;
        }

        .admin-text {
            color: red;
            font-weight: bold;
        }
    </style>
</head>

<body>
@include('_nav')
<div class="col-md-12" style="margin-top: 10px;">
    <div class="col-md-12" style="margin-top: 80px;">
        <div align="center">
            <h4>Users</h4>
            <noscript><p style="color: red; padding: 0px 0px 10px 0px; text-align: center; margin: 0;">Searching
                    requires JavaScript to function correctly.<br>Alternatively, you can type
                    <u>https://{{$currentDomain}}/users/search/{query}</u> in the address bar.</p></noscript>
            <div id="error-msg" style="color: red; padding: 0px 0px 10px 0px; text-align: center; margin: 0;"></div>

            <label for="search-form">Search for a user</label>
            <form id="search-form">
                <input id="search-query" type="text" placeholder="Username...">
                <input type="submit" value="Search">
            </form>

            <br>
            <p>Showing 100 (of {{ $userCount }}) users</p>
        </div>
    </div>
    <div class="col-md-6 col-md-offset-3">
        <h6>Admin</h6>
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th class="text-center">ID</th>
                <th>Username</th>
                <th class="text-center">Pastes</th>
                <th class="text-center">Comments</th>
                <th class="text-center">Joined</th>
                @if($isManagerOrHigher)
                    <th style="color: red;" class="text-center">Edit</th>
                @endif
            </tr>
            </thead>
            <tbody>
            @foreach ($rankedUsers->where('role', RoleId::ADMIN)->reverse() as $user)
                <tr class="doxentry">
                    <td style="width: 60px;" class="text-center">{{ $user->id }}</td>
                    <td style="width: 270px;">{!! $user->getNameHtml(false, true) !!}</td>
                    <td style="width: 90px;" class="text-center">{{ $user->pastes }}</td>
                    <td class="text-center">{{ $user->comments }}</td>
                    <td class="text-center"
                        title="{{ date('M jS, Y', floor($user->joindate / 1000)) }}">{{ age($user->joindate) }}</td>
                    @if($isManagerOrHigher)
                        <td class="text-center"><a style="color: red;"
                                                   href="https://{{$currentDomain}}/user/{{$user->username}}/edit"
                                                   target="_blank">Edit User</a></td>
                    @endif
                </tr>
            @endforeach
            </tbody>
        </table>

        <h6 style="margin-top: 50px;">Manager</h6>
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th class="text-center">ID</th>
                <th>Username</th>
                <th class="text-center">Pastes</th>
                <th class="text-center">Comments</th>
                <th class="text-center">Joined</th>
                @if($isManagerOrHigher)
                    <th style="color: red;" class="text-center">Edit</th>
                @endif
            </tr>
            </thead>
            <tbody>
            @foreach ($rankedUsers->where('role', RoleId::MANAGER)->reverse() as $user)
                <tr class="doxentry">
                    <td style="width: 60px;" class="text-center">{{ $user->id }}</td>
                    <td style="width: 270px;">{!! $user->getNameHtml(false, true) !!}</td>
                    <td style="width: 90px;" class="text-center">{{ $user->pastes }}</td>
                    <td class="text-center">{{ $user->comments }}</td>
                    <td class="text-center"
                        title="{{ date('M jS, Y', floor($user->joindate / 1000)) }}">{{ age($user->joindate) }}</td>
                    @if($isManagerOrHigher == 1)
                        <td class="text-center"><a style="color: red;"
                                                   href="https://{{$currentDomain}}/user/{{$user->username}}/edit"
                                                   target="_blank">Edit User</a></td>
                    @endif
                </tr>
            @endforeach
            </tbody>
        </table>

        <h6 style="margin-top: 50px;">Mod</h6>
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th class="text-center">ID</th>
                <th>Username</th>
                <th class="text-center">Pastes</th>
                <th class="text-center">Comments</th>
                <th class="text-center">Joined</th>
                @if($isManagerOrHigher == 1)
                    <th style="color: red;" class="text-center">Edit</th>
                @endif
            </tr>
            </thead>
            <tbody>
            @foreach ($rankedUsers->where('role', RoleId::MOD)->reverse() as $user)
                <tr class="doxentry">
                    <td style="width: 60px;" class="text-center">{{ $user->id }}</td>
                    <td style="width: 270px;">{!! $user->getNameHtml(false, true) !!}</td>
                    <td style="width: 90px;" class="text-center">{{ $user->pastes }}</td>
                    <td class="text-center">{{ $user->comments }}</td>
                    <td class="text-center"
                        title="{{ date('M jS, Y', floor($user->joindate / 1000)) }}">{{ age($user->joindate) }}</td>
                    @if($isManagerOrHigher == 1)
                        <td class="text-center"><a style="color: red;"
                                                   href="https://{{$currentDomain}}/user/{{$user->username}}/edit"
                                                   target="_blank">Edit User</a></td>
                    @endif
                </tr>
            @endforeach
            </tbody>
        </table>

        {{-- <h6 style="margin-top: 50px;">Developer</h6>
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th class="text-center">ID</th>
                <th>Username</th>
                <th class="text-center">Pastes</th>
                <th class="text-center">Comments</th>
                <th class="text-center">Joined</th>
                @if($isManagerOrHigher == 1)
                    <th style="color: red;" class="text-center">Edit</th>
                @endif
            </tr>
            </thead>
            <tbody>
            @foreach ($rankedUsers->where('role', RoleId::DEVELOPER)->reverse() as $user)
                <tr class="doxentry">
                    <td style="width: 60px;" class="text-center">{{ $user->id }}</td>
                    <td style="width: 270px;">{!! $user->getNameHtml(false, true) !!}</td>
                    <td style="width: 90px;" class="text-center">{{ $user->pastes }}</td>
                    <td class="text-center">{{ $user->comments }}</td>
                    <td class="text-center"
                        title="{{ date('M jS, Y', floor($user->joindate / 1000)) }}">{{ age($user->joindate) }}</td>
                    @if($isManagerOrHigher == 1)
                        <td class="text-center"><a style="color: red;"
                                                   href="https://{{$currentDomain}}/user/{{$user->username}}/edit"
                                                   target="_blank">Edit User</a></td>
                    @endif
                </tr>
            @endforeach
            </tbody>
        </table> --}}

        <h6 style="margin-top: 50px;">Council</h6>
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th class="text-center">ID</th>
                <th>Username</th>
                <th class="text-center">Pastes</th>
                <th class="text-center">Comments</th>
                <th class="text-center">Joined</th>
                @if($isManagerOrHigher)
                    <th style="color: red;" class="text-center">Edit</th>
                @endif
            </tr>
            </thead>
            <tbody>
            @foreach ($rankedUsers->where('role', RoleId::COUNCIL)->reverse() as $user)
                <tr class="doxentry">
                    <td style="width: 60px;" class="text-center">{{ $user->id }}</td>
                    <td style="width: 270px;">{!! $user->getNameHtml(false, true) !!}</td>
                    <td style="width: 90px;" class="text-center">{{ $user->pastes }}</td>
                    <td class="text-center">{{ $user->comments }}</td>
                    <td class="text-center"
                        title="{{ date('M jS, Y', floor($user->joindate / 1000)) }}">{{ age($user->joindate) }}</td>
                    @if($isManagerOrHigher)
                        <td class="text-center"><a style="color: red;"
                                                   href="https://{{$currentDomain}}/user/{{$user->username}}/edit"
                                                   target="_blank">Edit User</a></td>
                    @endif
                </tr>
            @endforeach
            </tbody>
        </table>
        @php
            $roles = DB::table('roles')->orderBy('weight', 'desc')->get();
        @endphp
        @foreach($roles as $role)
            <h6 style="margin-top: 50px;">{{$role->name}}</h6>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th class="text-center">ID</th>
                    <th>Username</th>
                    <th class="text-center">Pastes</th>
                    <th class="text-center">Comments</th>
                    <th class="text-center">Joined</th>
                    @if($isManagerOrHigher)
                        <th style="color: red;" class="text-center">Edit</th>
                    @endif
                </tr>
                </thead>
                <tbody>
                @foreach ($rankedUsers->where('role', $role->id)->reverse() as $user)
                    <tr class="doxentry">
                        <td style="width: 60px;" class="text-center">{{ $user->id }}</td>
                        <td style="width: 270px;">{!! $user->getNameHtml(false, true) !!}</td>
                        <td style="width: 90px;" class="text-center">{{ $user->pastes }}</td>
                        <td class="text-center">{{ $user->comments }}</td>
                        <td class="text-center"
                            title="{{ date('M jS, Y', floor($user->joindate / 1000)) }}">{{ age($user->joindate) }}</td>
                        @if($isManagerOrHigher)
                            <td class="text-center"><a style="color: red;"
                                                       href="https://{{$currentDomain}}/user/{{$user->username}}/edit"
                                                       target="_blank">Edit User</a></td>
                        @endif
                    </tr>
                @endforeach
                </tbody>
            </table>
        @endforeach
        <h6 style="margin-top: 50px;">All Users</h6>
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th class="text-center">ID</th>
                <th>Username</th>
                <th class="text-center">Pastes</th>
                <th class="text-center">Comments</th>
                <th class="text-center">Joined</th>
                @if($isManagerOrHigher)
                    <th style="color: red;" class="text-center">Edit</th>
                @endif
            </tr>
            </thead>
            <tbody>
            @foreach ($members as $user)
                <tr class="doxentry">
                    <td style="width: 60px;" class="text-center">{{ $user->id }}</td>
                    <td style="width: 270px;">{!! $user->getNameHtml(false, true, 'white') !!}</td>
                    <td style="width: 90px;" class="text-center">{{ $user->pastes }}</td>
                    <td class="text-center">{{ $user->comments }}</td>
                    <td class="text-center"
                        title="{{ date('M jS, Y', floor($user->joindate / 1000)) }}">{{ age($user->joindate) }}</td>
                    @if($isManagerOrHigher)
                        <td class="text-center"><a style="color: red;"
                                                   href="https://{{$currentDomain}}/user/{{$user->username}}/edit"
                                                   target="_blank">Edit User</a></td>
                    @endif
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>

</div>
<div align="center">
    <p>Showing 100 (of {{ $userCount }}) users</p>
    <br>
    <a href="#">Back to top</a>
    <br><br>
</div>
<script>
    $(document).ready(function () {
        $('#search-form').on('submit', function (e) {
            var query = $('#search-query').val();

            if (query == '') {
                window.location = '/users';
            } else if (!/^[a-zA-Z0-9_]+$/.test(query)) {
                $('#error-msg').text("Only alphanumeric characters and spaces can be searched.");
            } else {
                window.location = '/users/search/' + escape($('#search-query').val());
            }
            e.preventDefault();
        });
    });
</script>
@if ($admin == 1)
    <script src="{{ asset('/legacy/admin.js') }}"></script>
@endif
</body>
</html>