@php
$flagQuota = env("COUNCIL_WEEKLY_FLAG_QUOTA") * 1;
function flagStatus($num){
    switch($num){
        case 0:
            return '-';
        case 1:
            return 'Accepted';
        case 2:
            return 'Denied';
    }
}
@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">
    <title>Doxbin (Admin) - Flags</title>
    @include('_scripts')
    <meta name="robots" content="noindex">
    <script src="https://{{$currentDomain}}/legacy/jscolor.js"></script>
    <link rel="stylesheet" href="https://{{$currentDomain}}/legacy/index.css">
    <script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
    <script src="{{ asset('/legacy/modal.js?r=47433') }}"></script>
    <link rel="stylesheet" href="/files/admin.css?r=33">
    <style>
        .modalContainer {
            display: none;
        }

        .modalContainer .modal-background {
            background-color: rgba(0, 0, 0, 0.4);
            position: fixed;
            width: 100%;
            height: 100vh;
            left: 0;
            top: 0;
        }

        .modalContainer .modal-container {
            height: 180px;
            width: 380px;
            position: fixed;
            background-color: #383838;
            top: 50%;
            left: 50%;
            margin-top: -140px;
            margin-left: -190px;
            border-radius: 5px;
            color: #cecece;
            padding: 25px 20px;
            font-size: 15px;
            box-shadow: 0 0 30px #0d0e14;
        }

        .modalContainer .modal-container .confirm, .confirm {
            background-color: green;
            color: white;
            font-size: 15px;
            font-weight: bold;
            padding: 7px 10px;
        }

        .modalContainer .modal-container .confirm:hover, .confirm:hover {
            background-color: #1b6610;
        }

        .modalContainer .modal-container .cancel {
            background-color: gray;
            font-size: 15px;
            font-weight: bold;
            padding: 7px 10px;
        }

        .accept-flags {
            line-height: 1.2;
            color: white;
            background: #0c4a18;
            border: 0;
            border-radius: 2px;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 5px 5px 3px 5px;
            vertical-align: top;
            margin-top: 8px;
        }
		
        .nav-space{
            height: 50px;
            width: 100%;
        }
        
        div.page-content{
            display: block;
            margin-left: 250px;
            transition: margin-left .4s;
            padding: 21px;
        }
        body{
            position:relative;
        }
        .dropdown-li > a{
            padding-left: 13px;
        }
        .dropdown-li > a > i{
            font-size: 18px;
            padding-right: 7px;
        }
        .dropdown-li > a > span{
            font-size: 14px;
        }
        div.admin-sidebar > ul{
            padding-left: 0;
        }
        *{
            box-sizing: border-box;
        }
        @media only screen and (max-width: 992px){
        }
        textarea{
            background-color: #282828;
            border: none;
            border-radius: 2px;
            color: white;
        }
        .blacklist-container td{
            padding: 3px;
        }
        .blacklist-container tr:hover{
            background-color: #323232;
        }
        .blacklist-container tr{
            background-color: #444444;
        }
        a.button{
            display: inline-block;
            padding: 5px 8px;
            background-color: #272727;
            color: white;
            border-radius: 2px;
            text-transform: uppercase;
            font-size: 15px;
            font-weight: bold;
            margin: 0;
            width: auto;
        }
        a.button:focus{
            text-decoration: none;
        }
        a.button:hover{
            background-color: #232323;
            text-decoration:none;
        }
        a.button.button-red{
            border: solid 1px #ff0000;
        }
        a.button.button-green{
            border: solid 1px #00ff00;
        }
        a.button.button-green{
            border: solid 1px #0000ff;
        }
        .add-to-blacklist > div > a.button{
            display: inline-block;
            padding: 5px 8px;
            border: solid 1px #00ff00;
            background-color: #272727;
            color: white;
            border-radius: 2px;
            text-transform: uppercase;
            font-size: 15px;
            font-weight: bold;
            margin: 0;
            width: 50%;
        }
        .add-to-blacklist > div > a.button:hover{
            text-decoration: none;
            color: white;
            background-color: #1D1D1D;
        }
        .add-to-blacklist{
            width: 50%;
        }
        @media only screen and (max-width: 600px){
            .add-to-blacklist > div > a.button{
                width: 100%;
            }
            .add-to-blacklist{
                width: 100%;
            }
        }
        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;
        }

        input[type=text]::placeholder{
            color: rgb(167, 167, 167);
        }
        input, select, option{
            font-size: 100%;
        }

        input[type=submit]:hover{
            color: white;
            background: #3d3d3d;
            text-decoration: none;
        }
        .center {
            text-align: center;
        }
        .add{
            background-color: green;
        }
        .add:hover{
            background-color: #1b6e10;
        }

        a.confirm{
            background-color: green;
            font-size: 15px;
            font-weight: bold;
            padding: 7px 10px;
        }
        a.confirm:hover{
            background-color: #1b6e10;
        }
        .word-container{
            background-color: #282828;
            width: 50%;
            border-radius: 7px;
            margin-top: 20px;
            box-shadow: 0 1px 3px #181a1f;
            padding: 0px 10px;
            position:relative;
            display: inline-block;
            -webkit-box-shadow: inset 0px 0px 3px 0px rgba(0,0,0,0.75);
            -moz-box-shadow: inset 0px 0px 3px 0px rgba(0,0,0,0.75);
            box-shadow: inset 0px 0px 3px 0px rgba(0,0,0,0.75);
        }

        .word-container .word-row{
            padding: 10px 10px;
            border-bottom: solid 1px gray;
        }
        .word-container .word-row:last-of-type{
            border: none;
        }
        .row {
            display: -ms-flexbox;
            display: flex;
            -ms-flex-wrap: wrap;
            flex-wrap: wrap;
            margin-right: -15px;
            margin-left: -15px;
        }
        .col {
            position: relative;
            width: 100%;
            padding-right: 15px;
            padding-left: 15px;
            -ms-flex-preferred-size: 0;
            flex-basis: 0;
            -ms-flex-positive: 1;
            flex-grow: 1;
            max-width: 100%;
        }
        .top-btn, .top-btn p{
            display: block;
            outline: none;
            background: #303030;
            letter-spacing: .5px;
            line-height: 1.5;
            border-right: 1px solid #26282e;
            padding: 12px 0;
            font-size: 14px;
            font-weight: 600;
            text-align: center;
            cursor: pointer;
            color: #a8a8a8;
            margin: 0;
        }

        .top-btn-disabled, .top-btn-disabled p{
            display: block;
            outline: none;
            background: #292929;
            letter-spacing: .5px;
            line-height: 1.5;
            border-right: 1px solid #26282e;
            padding: 12px 0;
            font-size: 14px;
            font-weight: 600;
            text-align: center;
            cursor: not-allowed;
            color: #5d5d5d;
            margin: 0;
        }
        .top-btn:hover, .top-btn p:hover{
            color: white !important;
            text-decoration: none;
        }
        .top-btn p:focus{
            color: #a8a8a8;
            text-decoration: none;
        }
        .active p{
            color: white;
        }
        .checkbox{
            height: 0;
            width: 0;
            visibility: hidden;
        }
        .checkbox-label {
            cursor: pointer;
            text-indent: -9999px;
            width: 60px;
            height: 30px;
            background: grey;
            display: block;
            border-radius: 100px;
            position: relative;
            transition: 0.3s;
        }
        .checkbox-label:after {
            content: '';
            position: absolute;
            top: 3px;
            left: 4px;
            width: 24px;
            height: 24px;
            background: #fff;
            border-radius: 90px;
            transition: 0.3s;
        }
        .checkbox:checked + label {
            background: #4cba30;
            transition: 0.3s;
        }
        .checkbox:checked + .checkbox-label:after {
            left: calc(100% - 5px);
            transform: translateX(-100%);
        }
        /* .checkbox-label:active:after {
            width: 30px;
        } */
        input{
            margin-bottom: 4px;
        }
        .word-container input[type=text]{
            background-color: rgb(31,31,31);
            border: solid 1px rgb(26,26,26);  
        }
        .word-row input.role-weight{
            color: white;
            background: #282828;
            border: none;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            outline: none;
            padding: 2px;
            width: 30px;
            height: 100%;
            float: left;
            text-align: center;
            margin-right: 7px;
            border-right: solid 1px gray;
            border-radius: 0;
        }
        label.redirect-label{
            margin:0;
            display:inline-block;
            background-color:#272727;
            padding:6px 0 6px 6px;
            line-height: 1.2;
            border-radius: 2px 0 0 2px;
            font-weight:400;
        }
        input.redirect-input{
            padding: 6px 6px 6px 0;
            background-color: #272727;
            border-radius: 0 2px 2px 0;
        }

        .anx{
            font-size: 17px;
        }

        .anxs{
            font-size: 19px;
        }

        .b-wrd{
            display: inline;
            color: white;
            font-size: 15px;
        }
        @media only screen and (max-width: 900px) {
        .word-container {
            width:100%;
        }
        }

        @media screen and (max-width:500px){
            body{
                font-size: 10px;
            }
            .col-md-12{
                padding: 0;
                width: 100%;
            }
            .col-md-7{
                padding: 0;
                width: 100%;
            }
            .top-btn, .top-btn p{
                font-size: 10px;
            }
            .anx{
                font-size: 14px;
            }
            .anxs{
                font-size: 16px;
            }
            a.confirm{
                font-size: 13px;
            }
            .b-wrd{
                font-size: 12px;
            }
        }
        .flag-row td{
            padding: 5px;
        }
        td.flag-under{
            background-color: rgb(75, 22, 22);
        }
        .flag-words{
            float:right;
            width: 50%;
        }
        .council-info{
            float: left;
            width: 50%;
        }
        .flag-row th{
            padding: 2px 5px;
        }
        .council-info table{
            border-radius: 3px;
            border: solid 1px rgb(47, 47, 47);
        }
        </style>
</head>
<body style="min-height: 100%;height:100%">
    {!! csrf_field() !!}
    @include('_nav')
    <div class="nav-space"></div>
    <div class="page">
        @if(!$myUser->isCouncil())
            @include('_admin_sidebar')
        @endif
        <div class="page-content" {!! $myUser->isCouncil() ? 'style="margin-left: 0;padding: 0"' : '' !!}>
            @if($myUser->isDeveloper(true))
                <div class="council-info">
                    <h5>Flags</h5>
                    

  @if(empty($councilFlags))
    None
  @else
                            <table style="width: auto;">
                                <tr class="flag-row">
                                    <th>Username</th>
                                    <th>Total flags</th>
                                    <th>Total denied flags</th>
                                    <th>Last 7 days (flags)</th>
                                    @if($myUser->isDeveloper(true))
                                    <th></th>
                                    @endif
                                </tr>
    @foreach($councilFlags as $council => $cflags)
                            <tr class="flag-row">
                                <td>
                                    <a href="/user/{{ $council }}" style="{{ $cflags['nameStyle'] }}"><b>{{ $council }}</b></a>
                                </td>
                                <td>
                                    {{ $cflags['totalFlags'] }}
                                </td>
                                <td>
                                    {{ $cflags['totalDenies'] }}
                                </td>
                                <td {!! $cflags['pastWeek'] < $flagQuota ? 'class="flag-under" title="Below flag target of "' . $flagQuota : '' !!}>
                                    {{ $cflags['pastWeek'] }}
                                </td>
                                @if($myUser->isDeveloper(true))
                                <td style="width: 120px;text-align:right;">
                                    <a href="/admin/logs/flags?search=1&userid={{$cflags['userID']}}">View Flag History</a>
                                </td>
                                @endif
                            </tr>
    @endforeach
                    </table>
                </div>
                @if($myUser->isAdmin())
                    <div class="flag-words">
                        <h5>Words</h5>
                        <div class="word-container" style="position:relative;display:block;height: 230px;overflow:auto;margin-top:0;width: 100%;" id="blacklist-words">
                            @foreach ($flagWords as $word)
                            <div class="word-row" style="padding: 6px;position:relative;">
                                <p class="b-wrd" title="{{ $word->created_at }}" style="font-size: 14px;">{{ $word->word }}</p><a class="button button-red" style="margin-left: 10px;right:20px;top: 3px;position:absolute;padding: 3px 8px 1px;font-size: 14px;" onclick="delFlagWord({{ $word->id }})" href="javascript:void(0)">Delete</a>
                            </div>
                            @endforeach
                        </div>
                        @if($flags->count() > 0)
                            <span style="cursor: pointer;" class="accept-flags"
                                onclick="modal('Accept All Flags', 'Are you sure you want to accept all {{ $flags->count() }} flag(s)?', '', 'Confirm', 'Cancel', 'confirmAcceptFlags')">Accept All Flags</span>
                        @endif
                    </div>
                @endif

                    <br>
                @endif
                
                @if($flags->count() > 0)
                @php
                    $usercache = array();
                @endphp
                <table class="table table-striped table-hover" style="text-align:left;margin-top:300px;">
                    <thead>
                        <tr>
                            <th style="width: 50%;">Title</th>
                            <th class="text-center">Flagged by</th>
                            <th class="text-center">Flagged at</th>
                            <th class="text-center">Created</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($flags as $flag)
                            @php
                            $name = "Anonymous";
                            if(!isset($usercache[$flag->uid])){
                                if($flag->uid == 0){
                                    $name = "Doxbin";
                                    $usercache[0] = "Doxbin";
                                }else{
                                    $temp_user = App\User::find($flag->uid);
                                    if(!is_null($temp_user)){
                                        $name = $temp_user->username;
                                        $usercache[$flag->uid] = $temp_user->username;
                                    }else{
                                        continue;
                                    }
                                }
                            }else{
                                $name = $usercache[$flag->uid];
                            }
                            $paste = App\Paste::find($flag->pid);
                            if(is_null($paste)){
                                continue;
                            }
                            @endphp
                            <tr class="doxentry" id="{{$paste->title}}">
                                <td><a href="/admin/flag/{{$paste->link}}">{{$paste->title}}</a></td>
                                <td class="text-center">@if($name != "Doxbin") <a style="color: cyan; font-weight: bold;" href="/user/{{ $name }}">{{ $name }}</a> @else <b style="color: red">Doxbin</b> @endif</td>
                                <td class="text-center">{{age($flag->date)}}</td>
                                <td class="text-center">{{Carbon\Carbon::parse($paste->created_at)->format('M jS, Y')}}</td>
                            </tr> 
                        @endforeach
                    </tbody>
                </table>
                @else
                Currently no flags.
                @endif
            @endif
            @if($myUser->isCouncil())
                <div class="container" style="padding: 15px;background-color: #111111; min-height: 100vh;">
                    <h5>Flags</h5>
                    <p style="margin-bottom: 0;"><b>Flagged (last 7 days):</b> {{ $myflagcountthisweek }}</p>
                    <p style="margin-bottom: 0;"><b>Flagged:</b> {{ $myflagcount->count() }}</p>
                    <p style="margin-bottom: 0;"><b>Accepted:</b> {{ $myacceptedflagcount->count() }}</p>
                    <p style="margin-bottom: 0;"><b>Denied:</b> {{ $mydeniedflagcount->count() }}</p>
                    
                    (Most recent 100)
                    @if($flags->count() > 0)
                    <table class="table table-striped table-hover" style="text-align:left;">
                        <thead>
                            <tr>
                                <th style="width: 50%;">Title</th>
                                <th class="text-center">Status</th>
                                <th class="text-center">Flagged at</th>
                                <th class="text-center">Created</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($flags as $flag)
                                @php
                                $name = "Anonymous";
                                $temp_user = App\User::find($flag->uid);
                                if(is_null($temp_user)){
                                    continue;
                                }
                                $paste = App\Paste::find($flag->pid);
                                if(is_null($paste)){
                                    continue;
                                }
                                @endphp
                                <tr class="doxentry" id="{{$paste->title}}">
                                    <td><a href="/upload/{{$paste->link}}" target="_blank">{{$paste->title}}</a></td>
                                    <td class="text-center">{{ flagStatus($flag->status) }}</td>
                                    <td class="text-center">{{age($flag->date)}}</td>
                                    <td class="text-center">{{Carbon\Carbon::parse($paste->created_at)->format('M jS, Y')}}</td>
                                </tr> 
                            @endforeach
                        </tbody>
                    </table>
                    @else
                    Currently no flags.
                    @endif
                </div>
            @endif
        </div>          
    </div>
    <script src="https://{{$currentDomain}}/legacy/admin.js"></script>
    <script>
        $(document).ready(function(e){
            
            var logsDropdown = false;
            $('#logs-button').on('click', function(e){
                if(!logsDropdown){
                    $('.logs-dropdown').show();
                    logsDropdown = true;
                }else{
                    $('.logs-dropdown').hide();
                    logsDropdown = false;
                }
                e.preventDefault();
            });
        });
        
        function delFlagWord(wordId) {
            $.post('/admin/api/flagger-remove', {
                _token: $('input[name=_token]').val(),
                id: wordId
            }, function(resp) {
                if (resp.status == "done") {
                    location.reload();
                } else {
                    alert(resp.msg);
                }
            });
        }
		
        function confirmAcceptFlags() {
            $.post('/admin/api/accept-all-flags', {
                _token: $('input[name=_token]').val()
            }, function(resp) {
                if (resp.status === "done") {
                    location.reload();
                } else {
                    alert(resp.msg);
                }
            });
        }
		
    </script>
</body>
</html>