<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- CSRF Token -->
        <meta name="csrf-token" content="{{ csrf_token() }}">

        <title>{{ config('app.name', 'Laravel') }}</title>

        <!-- Scripts -->
        <script src="{{ asset('/js/app.js') }}" defer></script>

        <!-- Fonts -->
        <link rel="dns-prefetch" href="//fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

        <!-- Styles -->
        <link href="{{ asset('/css/app.css') }}" rel="stylesheet">
    </head>
    <body>
        <div id="app">
            <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
                <div class="container">
                    <a class="navbar-brand" href="{{ url('/') }}">
                        {{ config('app.name', 'Laravel') }}
                    </a>
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent">
                        <span class="navbar-toggler-icon"></span>
                    </button>

                    <div class="collapse navbar-collapse" id="navbarSupportedContent">
                        <!-- Left Side Of Navbar -->
                        <ul class="navbar-nav me-auto">
                            @auth
                            @if (Auth::user()->hasRole('Administrator'))
                            <li class="nav-item dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                                    Books
                                </a>

                                <div class="dropdown-menu">
                                    <a class="dropdown-item" href="{{ route('books.index') }}">List all</a>
                                    <a class="dropdown-item" href="{{ route('books.create')}}">Create new</a>
                                </div>
                            </li>

                            <li class="nav-item dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                                    Categories
                                </a>

                                <div class="dropdown-menu">
                                    <a class="dropdown-item" href="{{ route('categories.index') }}">List all</a>
                                    <a class="dropdown-item" href="{{ route('categories.create') }}">Create new</a>
                                </div>
                            </li>

                            <li class="nav-item dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                                    Loans
                                </a>

                                <div class="dropdown-menu">
                                    <a class="dropdown-item" href="{{ route('loans.index') }}">List all</a>
                                    <a class="dropdown-item" href="{{ route('loans.create') }}">Create new</a>
                                </div>
                            </li>

                            <li class="nav-item dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                                    Penalties
                                </a>

                                <div class="dropdown-menu">
                                    <a class="dropdown-item" href="{{ route('penalties.index') }}">List all</a>
                                    <a class="dropdown-item" href="{{ route('penalties.create') }}">Create new</a>
                                </div>
                            </li>

                            <li class="nav-item dropdown">
                                <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                                    Users
                                </a>

                                <div class="dropdown-menu">
                                    <a class="dropdown-item" href="{{ route('users.index') }}">List all</a>
                                    <a class="dropdown-item" href="{{ route('users.create') }}">Create new</a>
                                </div>
                            </li>
                            @else
                            <li class="nav-item">
                                <a href="{{ route('books.index') }}" class="nav-link">Books</a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('categories.index') }}" class="nav-link">Categories</a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('loans.index') }}" class="nav-link">Loans</a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('penalties.index') }}" class="nav-link">Penalties</a>
                            </li>
                            @endif
                            @else
                            <li class="nav-item">
                                <a href="{{ route('books.index') }}" class="nav-link">Books</a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('categories.index') }}" class="nav-link">Categories</a>
                            </li>
                            @endauth
                        </ul>

                        <!-- Right Side Of Navbar -->
                        <ul class="navbar-nav ms-auto">
                            <!-- Authentication Links -->
                            @guest
                            @if (Route::has('login'))
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                            </li>
                            @endif

                            @if (Route::has('register'))
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                            </li>
                            @endif
                            @else
                            <li class="nav-item dropdown">
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">
                                    <img src="{{ Auth::user()->image }}" class="me-1 rounded-circle" alt="{{ Auth::user()->name }}" width="32" height="32"/>
                                    <span class="align-middle">{{ Auth::user()->name }}</span>
                                </a>

                                <div class="dropdown-menu dropdown-menu-end">
                                    <a class="dropdown-item" href="{{ route('profiles.show', Auth::user()->id) }}">Profile</a>

                                    <a class="dropdown-item" href="{{ route('logout') }}"
                                       onclick="event.preventDefault();document.getElementById('logout-form').submit();">
                                        {{ __('Logout') }}
                                    </a>

                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
                                        @csrf
                                    </form>
                                </div>
                            </li>
                            @endguest
                        </ul>
                    </div>
                </div>
            </nav>

            <main class="py-4 text-break">
                @yield('content')
            </main>
        </div>
    </body>
</html>
