@php

    function calc_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;
    }
    $auth = (isset($myUser) && $myUser != "invalid" && $myUser != null);
    if($auth){
        $notifs = DB::table('notifications')->where(['uid' => $myUser->id, 'seen' => 0])->latest('date')->get();
        $notif_count = $notifs->count();
    }

    function navNameStyle($user){
        $color = '';

        if ($user->name_color != null) {
            $color = 'color: #' . $user->name_color . '; font-weight: bold;';
        } else if ($user->role == RoleId::ADMIN) {
            $color = 'color: #' . RoleColor::ADMIN . '; font-weight: bold;';
        } else if ($user->role == RoleId::MANAGER) {
            $color = 'color: #' . RoleColor::MANAGER . '; font-weight: bold;';
        } else if ($user->role == RoleId::MOD) {
            $color = 'color: #' . RoleColor::MOD . '; font-weight: bold;';
        } else if ($user->role == RoleId::DEVELOPER) {
            $color = 'color: #' . RoleColor::DEVELOPER . '; font-weight: bold;';
        } else if ($user->role == RoleId::COUNCIL) {
            $color = 'color: #' . RoleColor::COUNCIL . '; font-weight: bold;';
        } else if ($user->role != 0) {
            $role = DB::table('roles')->where('id', $user->role)->first();

            if (!is_null($role)) {
                $color = 'color: #' . $role->color . '; font-weight: bold;'.$role->css;
            }
        }

        return $color;
    }


@endphp

<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="https://{{$currentDomain}}/">Doxbin</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li {!! Request::path() == '/' || intval(Request::path()) != null ? 'class="active"' : '' !!}><a
                            href="https://{{$currentDomain}}">Home</a></li>
                <li><a href="https://{{$currentDomain}}/upload">Add Paste</a></li>
                <li {!! Request::path() == 'users' ? 'class="active"' : '' !!}><a
                            href="https://{{$currentDomain}}/users">Users</a></li>
                <li {!! Request::path() == 'upgrade' ? 'class="active"' : '' !!}><a
                            href="https://{{$currentDomain}}/upgrade">Upgrades<p class="notif_count"
                                                                                 style="display: none;margin-top: 4px; left:65px;height: 8px;top:8px;"></p>
                    </a></li>
                <li {!! Request::path() == 'hoa' ? 'class="active"' : '' !!}><a href="https://{{$currentDomain}}/hoa">Hall
                        of Autism</a></li>
                <li {!! Request::path() == 'tos' ? 'class="active"' : '' !!}><a href="https://{{$currentDomain}}/tos">TOS</a>
                </li>
                <li><a target="_blank" rel="nofollow" href="{{ env("TELEGRAM_LINK") }}">Telegram</a></li>
                @if ($auth && $myUser->isCouncil(true))
                    <li {!! substr(Request::path(), 0, 5) == 'admin' ? 'class="active"' : '' !!}><a id="adminnotifs"
                                                                                                    href="https://{{$currentDomain}}/admin">Admin
                            <p id="admin_notif" class="notif_count" style="display:none;left:50px;"></p></a></li>
                @endif
            </ul>
            <div class="sidebar-right">
                @if ($auth)
                    {!! csrf_field() !!}
                    <ul class="nav navbar-nav r-hide">
                        <li style="width: 60px; height: 50px;" id="notif-btn"><a href="/notifications"
                                                                                 style="padding-top: 12px;"><i
                                        class="material-icons">notifications_none</i>@if($notif_count > 0)
                                    <p class="notif_count">{{ $notif_count }}</p>
                                @endif</a></li>
                    </ul>
                    <div class="dropdown r-hide">
                        {!! $myUser->getNavNameHtml('', '', true) !!}
                        <div class="dropdown-content">
                            <a href="/user/{{$myUser->username}}">Profile</a>
                            <a href="/user/{{$myUser->username}}/pastes">My Pastes</a>
                            <a href="/settings">Settings</a>
                            <a class="logout-btn" href="#">Logout</a>
                        </div>
                    </div>
                    <ul class="nav navbar-nav r-show">
                        <li><a href="/user/{{$myUser->username}}">Profile</a></li>
                        <li><a href="/user/{{$myUser->username}}/pastes">My Pastes</a></li>
                        <li><a href="/settings">Settings</a></li>
                        <li class="logout-btn"><a href="#">Logout</a></li>
                    </ul>
                @else
                    <ul class="nav navbar-nav">
                        <li {!! Request::path() == 'login' ? 'class="active"' : '' !!}><a href="/login">Login</a></li>
                        <li {!! Request::path() == 'register' ? 'class="active"' : '' !!}><a
                                    href="/register">Register</a></li>
                    </ul>
                @endif
            </div>
        </div>
    </div>
</nav>
@if($auth)
    <script src="/legacy/notifs.js"></script>
    <div id="notif">
        <div id="notif-modal-bg" class="notif-background">
        </div>
        <div class="notif-container" style="top: 25vh; position: fixed; margin-top: 0;">
            <p style="font-size: 20px; font-weight: bold; margin-top: 0px;">Notifications</p>
            @if($notif_count < 1)
                No unseen notifications.
            @else
                <div style="max-height: 210px; overflow: auto;">
                    @foreach($notifs as $notif)
                        <div style="margin-top: 3px; padding-bottom: 5px; border-bottom: solid 1px #494949; font-size: 14px; padding: 3px;">
                            <p style="margin: 0;padding:0; font-weight: bold; font-size: 14px;">{!! ($notif->type == 3 ? '<b style="color:#ed3e3e;display:inline;margin:0;padding:0;">Announcement</b> - ' : '') !!} {{ calc_age($notif->date) }}</p>
                            {!! str_replace("{plural}", ($notif->type == 4 ? "ies" : "s"), str_replace("{count}", $notif->count, $notif->text)) !!}
                            <br/>
                        </div>
                    @endforeach
                </div>
            @endif
            <a style="left: 0; position: absolute; margin-left: 15px;" class="btn view-all" href="/notifications">View
                All</a>
            <a style="right: 0; position: absolute; margin-right: 15px;" class="btn cancel" id="notif-modal-close"
               href="#">Close</a>
        </div>
    </div>
@endif
