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

@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="description" content="Doxbin is a document sharing and publishing website for text-based information such us dox, code-snippets and other stuff.">
	
	<meta property="og:locale" content="en_US">
	<meta property="og:url" content="https://{{$currentDomain}}/users">
	<meta property="og:type" content="website">
	<meta property="og:title" content="Users - Doxbin">
	<meta property="og:description" content="Doxbin is a document sharing and publishing website for text-based information such us dox, code-snippets and other stuff.">
	<meta name="twitter:card" content="summary">
	<meta name="twitter:title" content="Users - Doxbin">
	<meta name="twitter:description" content="Doxbin is a document sharing and publishing website for text-based information such us dox, code-snippets and other stuff.">
	<meta name="twitter:url" content="https://{{$currentDomain}}/users">
	<meta name="twitter:image" content="">
	<meta name="twitter:site" content="Search - Doxbin">
	<meta name="twitter:creator" content="Doxbin">
	
    <title>Users - Doxbin</title>
    @include('_scripts')
    <link rel="stylesheet" href="/legacy/index.css">
	<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;
	}
    
	
    .dropbtn {
        color: white;
        padding-top: 15px;
        border: none;
        cursor: pointer;
        color: #888888;
    }

    .dropdown {
        position: relative;
        display: inline-block;
        float: right;
    }

    .dropdown-content {
        display: none;
        position: absolute;
        background-color: #3a3a3a;
        min-width: 160px;
        box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
        z-index: 1;
        border-radius: 3px;
    }

    .dropdown-content a {
        color: white;
        padding: 4px 10px;
        text-decoration: none;
        display: block;
    }

    .dropdown-content a:hover{
        color: gray;
    }

    .dropdown:hover .dropdown-content {
        display: block;
    }
    .dropbtn:hover{
        color: white;
    }
    .admin-text{
        color: red;
        font-weight: bold;
    }
	</style>
</head>

<body>
    {{ csrf_field() }}
    @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}}/admin/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..." value="{{ $query }}">
					<input type="submit" value="Search">
				</form>
				
				<br>
                <p>Showing {{ $users->count() }} results for '<b>{{ $query }}</b>'</p>
            </div>
        </div>
        <div class="col-md-6 col-md-offset-3">
            <table class="table table-striped table-hover" style="margin-top: 40px;">
                <thead>
                    <tr>
                        <th class="text-center">ID</th>
                        <th>Username</th>
                        <th class="text-center">Comments</th>
                        <th class="text-center">Pastes</th>
                        <th class="text-center">Join date</th>
                        @if($admin == 1)
						<th style="color: red;" class="text-center">Edit</th>
                        @endif
                    </tr>
                </thead>
                <tbody>
                    @foreach ($users as $user)
                        <tr class="doxentry">
                        <td class="text-center">{{ $user->id }}</td>
                        <td><a style="{!! $user->getNameStyle() !!}" href="https://{{$currentDomain}}/user/{{$user->username}}" target="_blank">{{ $user->username }}</a></td>
                        <td class="text-center">{{ $user->comments }}</td>
                        <td class="text-center">{{ $user->pastes }}</td>
                        <td class="text-center" title="{{ date('M jS, Y', floor($user->joindate / 1000)) }}">{{ age($user->joindate) }}</td>
                        @if($admin == 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>
        </div>
		
    </div>
	<div align="center">
		<p>Showing {{ $users->count() }} results for '<b>{{ $query }}</b>'</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)
    <script src="{{ asset('/legacy/admin.js') }}"></script>
    @endif
</body>
</html>