@php
function age($time){
    $time = floor(microtime(true) * 1000) - $time;
    $result = "now";
    if($time > 31557600000)       return floor($time / 31557600000)." year".(floor($time / 31557600000) > 1 ? 's ago' : ' ago');
    if($time > 2592000000)        return floor($time / 2592000000)." month".(floor($time / 2592000000) > 1 ? 's ago' : ' ago');
    if($time > 604800000)         return floor($time / 604800000)." week".(floor($time / 604800000) > 1 ? 's ago' : ' ago');
    if($time > 86400000)          return floor($time / 86400000)." day".(floor($time / 86400000) > 1 ? 's ago' : ' ago');
    if($time > 3600000)           return floor($time / 3600000)." hour".(floor($time / 3600000) > 1 ? 's ago' : ' ago');
    if($time > 60000)             return floor($time / 60000)." minute".(floor($time / 60000) > 1 ? 's ago' : ' ago');
    if($time > 1000)              return floor($time / 1000)." second".(floor($time / 1000) > 1 ? 's ago' : ' ago');
    return $result;
}
function in($time){
    $time -= floor(microtime(true) * 1000);
    $result = "now";
    if($time > 60000)             return floor($time / 60000)." minute".(floor($time / 60000) > 1 ? 's' : '');
    if($time > 1000)              return floor($time / 1000)." second".(floor($time / 1000) > 1 ? 's' : '');
    return $result;
}
@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 as dox, code-snippets and other stuff.">
	<meta property="og:locale" content="en_US">
	<meta property="og:url" content="https://{{$currentDomain}}">
	<meta property="og:type" content="website">
	<meta property="og:title" content="Doxbin">
	<meta property="og:description" content="Doxbin is a document sharing and publishing website for text-based information such as dox, code-snippets and other stuff.">
	<meta name="twitter:card" content="summary">
	<meta name="twitter:title" content="Doxbin">
	<meta name="twitter:description" content="Doxbin is a document sharing and publishing website for text-based information such as dox, code-snippets and other stuff.">
	<meta name="twitter:url" content="https://{{$currentDomain}}">
	<meta name="twitter:image" content="">
	<meta name="twitter:site" content="Doxbin">
	<meta name="twitter:creator" content="Doxbin">
    <meta name="robots" content="noindex">
    <title>Admin - Doxbin</title>
    <link rel="stylesheet" href="/legacy/index.css">
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
	<style>
	input[type=text], select, option{
		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;
	}

    .order{
        margin-bottom: 10px;
        right: 0;
        position: absolute;
    }

	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, select, option{
		font-size: 100%;
	}
	
	input[type=submit]:hover{
		color: white;
		background: #3d3d3d;
		text-decoration: none;
	}
	.center {
	  text-align: center;
	}
	
	.pagination {
	  display: inline-block;
	  margin: 0px 0px 10px 0px;
	}

	.pagination a {
        color: white;
        float: left;
        min-width: 30px;
        min-height: 30px;
        padding-top: 5px;
        
        text-decoration: none;
        transition: background-color .3s;
        border: solid 1px #878787;
        margin: 0 4px 1px;
	}

	.pagination a.active {
        background-color: #a0a0a0;
        color: white;
        border: solid 1px #a0a0a0;
	}
	.pagination a:hover:not(.active):not(.disabled) {
		background-color: #383838;
	}
	
	.pagination .disabled, .pagination .active{
		cursor: not-allowed;
    }
    .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: #303030;
        min-width: 110px;
        box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
        z-index: 1;
        border-radius: 3px;
        right: 0;
    }

    .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>Admin - 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 or email...">
					<input type="submit" value="Search">
				</form>
				
				<br>
                <p>Showing {{ $users->count() }} users</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>Email</th>
                        <th class="text-center">Join date</th>
						<th style="color: red;" class="text-center">Edit</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($users as $user)
                        <tr class="doxentry">
                        <td class="text-center">{{ $user->id }}</td>
                        <td>{!! $user->getNameHtml(false, true) !!}</td>
                        <td>{{ $user->email }}</td>
                        <td class="text-center" title="{{ date('M jS, Y H:m', floor($user->joindate / 1000)) }}">{{ age($user->joindate) }}</td>
                        <td class="text-center"><a style="color: red;" href="https://{{$currentDomain}}/user/{{$user->username}}/edit" target="_blank">Edit User</a></td>
                      </tr> 
                    @endforeach
                </tbody>
            </table>
        </div>
		
    </div>
	<div class="center">
		<p>Showing {{ $users->count() }} results.</p>
		<br>
		<a href="#">Back to top</a>
		<br><br>
	</div>
    <script src="{{ asset('/legacy/jquery.min.js') }}"></script>
    <script src="{{ asset('/legacy/jquery-ui-1.10.3.custom.min.js') }}"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="{{ asset('/legacy/logout.js') }}"></script>
    <script>
	$(document).ready(function(){
		$('#search-form').on('submit', function(e){
			var query = $('#search-query').val();
			
			if(query == ''){
				window.location = '/admin/users';
			}else if(!/^[a-zA-Z0-9\@\.\-_]+$/.test(query)){
				$('#error-msg').text("Only alphanumeric characters and spaces can be searched.");
			}else{
				window.location = '/admin/users/search/' + escape($('#search-query').val());
			}
			e.preventDefault();
		});
	});
	</script>
    <script src="{{ asset('/legacy/admin.js') }}"></script>
</body>
</html>