@php
    $admin = 0;
    $mod = 0;
    $council = 0;
    $isDeveloperOrHigher = false;
    $modOrHigher = false;
    $canAccess = false;
    $isManager = false;

    if($myUser != null){
        $admin = $myUser->isAdmin();
        $mod = $myUser->isMod();
        $council = $myUser->isCouncil();
        $isDeveloperOrHigher = $myUser->isDeveloper(true);
        $modOrHigher = $myUser->isMod(true);
        // Utilized for checking page loading times
        $isManagerOrHigher = $myUser->isManager(true);
        $canAccess = $myUser->isDeveloper() || $isManagerOrHigher;
    }

    $enableHalloweenBats = false;

@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.">
    @if ($page != 1)
        <meta name="robots" content="noindex">
    @endif
    <title>Doxbin</title>
    <link rel="stylesheet" href="/legacy/index.css">
    <link rel="stylesheet" href="/legacy/css/main.css?r=44">
    @include('_scripts')
    @include('_favicons')

    <script>

        var order = '{{ $order }}';
        var type = '{{ $type }}';

    </script>
    @if(false)
        <script src="/files/snowflakes.js"></script>
    @endif
</head>

<body>

@include('_nav')
<div class="col-md-12">
    <div class="col-md-12" style="margin-top: 60px;float:none;">
        <div align="center">
            @include('_ascii')
            <noscript><p style="color: red; padding: 0px 0px 10px 0px; text-align: center; margin: 0;">Searching
                    requires JavaScript to function correctly.<br>
                    <!--Otherwise you can type <u>https://doxbin.org/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" style="font-size: 15px;margin:0;">Search for a paste</label><br>
            <form id="search-form" method="POST" action="search">
                @if(!is_null($myUser))
                    <input type="radio" name="search-option" id="search_title" value="title" checked="checked"
                           style="margin: 0;"><label for="search_title" style="margin: 0 0 0 5px;font-weight:normal;">Search
                        in title</label><br>
                    <input type="radio" name="search-option" id="search_paste" value="content" style="margin: 0;"><label
                            for="search_paste" style="margin: 0 0 0 5px;font-weight:normal;">Search in paste</label><br>
                @endif
                {!! csrf_field() !!}
                <input name="search-query" type="text" placeholder="Search for...">
                <input type="submit" value="Search"><br>
            </form>
            <br>
            <p>Showing {{$loaded}} (of {{$pasteCount}} total) pastes</p>
            <div class="center">
                <div class="pagination">
                    <a style="border-top-left-radius:3px;border-bottom-left-radius:3px;"
                       @if ($page == 1) class="disabled"
                       @else href="/?page={{$page - 1}}{{ ($order != 'none' ? '&orderby='.$order : '') }}"@endif>&laquo;</a>
                    @foreach ($pages as $i)
                        @if($i == "...")
                            <p>...</p>
                        @else
                            <a @if ($page == $i) class="active"
                               @else href="/?page={{$i}}{{ ($order != 'none' ? '&orderby='.$order : '') }}{{ $order != 'none' && $type != 'none' ? '&type='.$type : ''}}"@endif>{{$i}}</a>
                        @endif
                    @endforeach
                    <a style="border-top-right-radius:3px;border-bottom-right-radius:3px;"
                       @if ($page == $totalPages ) class="disabled"
                       @else href="/?page={{$page + 1}}{{ ($order != 'none' ? '&orderby='.$order : '') }}"@endif>&raquo;</a>
                </div>
                <br>
            </div>
        </div>
    </div>
    <div class="col-md-7" style="float:none;margin:auto;padding:0;">
        <!-- PINNED PASTES -->
        @if ($pinnedPastes->count() > 0)
            <h6 style="margin-top: 14px;">Pinned Pastes</h6>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th colspan="3">Title</th>
                    <th class="text-center auto-size">Comments</th>
                    <th class="text-center">Views</th>
                    <th colspan="2" class="text-center">Created by</th>
                    <th style="width: 120px" class="text-center r-hide">Added</th>
                    {{-- Added this to view the "Actions". Just ticked me off not seeing it, is all. --}}
                    @if ($isDeveloperOrHigher)
                        <th class="text-center" style="color: red;">Actions</th>
                    @endif
                </tr>
                </thead>
                <tbody>
                @foreach ($pinnedPastes as $pinnedPaste)
                    @if($pinnedPaste->private)
                        @if(is_null($myUser) || $myUser->id != $pinnedPaste->created_by)
                            @continue
                        @endif
                    @endif
                    @if (!$pinnedPaste->hidden || $isDeveloperOrHigher)
                        @php
                            if($pinnedPaste->created_by == 0){
                                $user = null;
                            }else{
                                $user = new App\User();
                                $user->fill([
                                    'id' => $pinnedPaste->created_by,
                                    'username' => $pinnedPaste->username,
                                    'name_color' => $pinnedPaste->name_color,
                                    'name_css' => $pinnedPaste->name_css,
                                    'role' => $pinnedPaste->role,
                                    'admin' => $pinnedPaste->admin,
                                    'is_manager' => $pinnedPaste->is_manager,
                                    'is_developer' => $pinnedPaste->is_developer,
                                    'mod' => $pinnedPaste->mod,
                                    'council' => $pinnedPaste->council,
                                    ]);
                            }
                        @endphp


                        <tr class="doxentry {{ $pinnedPaste->hidden == 1 ? 'hidden-post' : '' }} {{ !is_null($user) ? $user->pasteHighlightColor() : '' }}"
                            id="{{$pinnedPaste->id}}">


                            <td colspan="3" style="overflow: hidden; text-overflow: ellipsis;"><a
                                        title="{{ $pinnedPaste->title }}"
                                        href="https://{{$currentDomain}}/upload/{{$pinnedPaste->link}}">@if($pinnedPaste->private)
                                        <span style="color: red;font-weight:bold;">[Private]</span>
                                    @endif{{$pinnedPaste->title}}</a></td>
                            <td style="width: 105px;"
                                class="text-center">{{ $pinnedPaste->disable_cmts == 1 ? '-' : $pinnedPaste->comments }}</td>
                            <td class="text-center">{{$pinnedPaste->views}}</td>
                            <td colspan="2" style="padding-bottom: 0; max-width: 140px;" class="text-center">
                                {!! App\User::getNameHtmlOrAnonymous($user, true) !!}
                            </td>
                            <td style="width: 120px"
                                class="text-center r-hide">{{$pinnedPaste->created_at->format('M jS, Y')}}</td>
                            @if ($isDeveloperOrHigher)
                                <td class="text-center">
                                    <a id="hide{{$pinnedPaste->id}}" onclick="removePaste({{$pinnedPaste->id}})"
                                       style="color: red;"
                                       href="javascript:void(0)">{{ ($pinnedPaste->hidden == 1 ? 'Unhide' : 'Hide') }}</a>
                                </td>
                            @endif
                        </tr>
                    @endif
                @endforeach
                </tbody>
            </table>
        @endif




        <!-- normal pastes -->
        <table class="table table-striped table-hover" style="margin-top: 0px;">
            <thead>
            <tr>
                <th colspan="3">Title</th>
                <th class="clickable text-center auto-size" id="commentsorder" style="width: 105px;">
                    Comments @if ($order == "comments")
                        @if($type == "desc")
                            ⯆
                        @else
                            ⯅
                        @endif
                    @endif</th>
                <th class="clickable text-center auto-size" id="viewsorder">Views @if ($order == "views")
                        @if($type == "desc")
                            ⯆
                        @else
                            ⯅
                        @endif
                    @endif</th>
                <th colspan="2" class="text-center">Created by</th>
                <th class="clickable text-center r-hide" id="dateorder" style="width: 120px">
                    Added @if ($order == "date")
                        @if($type == "desc")
                            ⯆
                        @else
                            ⯅
                        @endif
                    @endif</th>
                @if ($isDeveloperOrHigher)
                    <th class="text-center" style="color:red;">Actions</th>
                @endif
            </tr>
            </thead>
            <tbody>
            @foreach ($pastes as $paste)
                @if($paste->private)
                    @if(is_null($myUser) || $myUser->id != $paste->created_by && !$isManagerOrHigher) {{-- Allow for managers+ to view private pastes on Front Page. Reiko, Mar 17 2024 --}}
                        @continue
                    @endif
                @endif
                @if (!$paste->hidden || $isDeveloperOrHigher)
                    @php
                        if ($paste->created_by == 0) {
                            $user = null;
                        } else {
                            $user = createUserFromObjectWithUserInfo($paste, 'created_by');
                        }
                    @endphp

                    <tr {!! $council && !is_null($recentPaste) && $recentPaste == $paste->id ? 'style="border-top: solid 2px white;"' : 'data-test="'.$recentPaste.'"' !!} class="doxentry {{ $council && ($paste->flagged == 1 || $paste->flagged == 2 && ($paste->last_edited == null || $paste->last_edited < $paste->flagdate)) ? 'hidden-post' : '' }}{{ $paste->hidden == 1 ? 'hidden-post' : '' }} {{ !is_null($user) ? $user->pasteHighlightColor() : '' }}"
                        id="{{$paste->id}}">

                        <td colspan="3" style="overflow: hidden;text-overflow: ellipsis;">
                            <a title="{{ $paste->title }}"
                               href="https://{{$currentDomain}}/upload/{{$paste->link}}">{!! $paste->getIcons() !!}{{$paste->title}}</a>
                        </td>

                        <td style="width: 105px;" class="text-center">
                            {{  $paste->disable_cmts == 1 ? '-' : $paste->comments   }}
                        </td>

                        <td class="text-center">
                            {{$paste->views}}
                        </td>

                        <td colspan="2" style="padding-bottom: 0; max-width: 140px;" class="text-center">
                            {!! App\User::getNameHtmlOrAnonymous($user, true) !!}
                        </td>


                        <td style="width: 120px"
                            class="text-center r-hide">{{$paste->created_at->format('M jS, Y')}}</td>
                        @if ($isDeveloperOrHigher)
                            <td class="text-center admin-select">
                                <a id="hide{{$paste->id}}" onclick="removePaste({{$paste->id}})" style="color:red;"
                                   href="javascript:void(0)">{{ ($paste->hidden == 1 ? 'Unhide' : 'Hide') }}</a>
                            </td>
                        @endif
                    </tr>
                @endif
            @endforeach
            </tbody>
        </table>
    </div>
</div>
<div class="center">
    <div class="pagination">
        <a style="border-top-left-radius:3px;border-bottom-left-radius:3px;" @if ($page == 1) class="disabled"
           @else href="/?page={{$page - 1}}{{ ($order != 'none' ? '&orderby='.$order : '') }}"@endif>&laquo;</a>
        @foreach ($pages as $i)
            @if($i == "...")
                <p>...</p>
            @else
                <a @if ($page == $i) class="active"
                   @else href="/?page={{$i}}{{ ($order != 'none' ? '&orderby='.$order : '') }}{{ $order != 'none' && $type != 'none' ? '&type='.$type : ''}}"@endif>{{$i}}</a>
            @endif
        @endforeach
        <a style="border-top-right-radius:3px;border-bottom-right-radius:3px;"
           @if ($page == $totalPages ) class="disabled"
           @else href="/?page={{$page + 1}}{{ ($order != 'none' ? '&orderby='.$order : '') }}"@endif>&raquo;</a>
    </div>
    <br>
    <p>Showing {{$loaded}} (of {{$pasteCount}} total) pastes</p>
    <br>
    <a href="#">Back to top</a>
    <br><br>
</div>
<script>
    var page = {{ $page }};
    $(document).ready(function () {

        $('#commentsorder').on('click', function (e) {
            if (type == "desc") {
                window.location = "/?page=" + page + '&orderby=comments&type=asc';
            } else if (type == "none") {
                window.location = "/?page=" + page + '&orderby=comments&type=desc';
            } else {
                window.location = "/?page=" + page;
            }
        });
        $('#viewsorder').on('click', function (e) {
            if (type == "desc") {
                window.location = "/?page=" + page + '&orderby=views&type=asc';
            } else if (type == "none") {
                window.location = "/?page=" + page + '&orderby=views&type=desc';
            } else {
                window.location = "/?page=" + page;
            }
        });
        $('#dateorder').on('click', function (e) {
            if (type == "desc") {
                window.location = "/?page=" + page + '&orderby=date&type=asc';
            } else if (type == "none") {
                window.location = "/?page=" + page + '&orderby=date&type=desc';
            } else {
                window.location = "/?page=" + page;
            }
        });

        // $('#search-form').on('submit', function(e){
        // 	var query = $('#search-query').val();

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

@if($canAccess)
    <div class="text-center">
        Page took
        @php
            $timeToLoad = microtime(true) - LARAVEL_START
        @endphp
        @if($timeToLoad < 0.5)
            <span style="color: green">{{ $timeToLoad }}</span>
        @elseif($timeToLoad <= 1.5)
            <span style="color: orange">{{ $timeToLoad }}</span>
        @elseif($timeToLoad > 1.5)
            <span style="color: red">{{ $timeToLoad }}</span>
        @endif
        seconds to load.
    </div><br>
    {{-- x-forwarded-for <span>{{ $_SERVER['X-FORWARDED-FOR'] }}</span> --}}
@endif

@if($enableHalloweenBats)
    <script src="/files/halloween-bats.js"></script>
    <script>
        $.halloweenBats({
            image: '/files/bats.png',
            amount: 30,
        });
    </script>
@endif
</body>
</html>
<!-- made by t.me/brenton br3nt0n@protonmail.com <3 doxbin <3 feb 2019 - jun 2023-->