<link href="{{ asset('css/navbar.css') }}" rel="stylesheet">
<nav class="navbar {{--fixed-top--}} navbar-expand-md navbar-dark bg-primary" id="">

    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#nav-content"
            aria-controls="nav-content" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <!-- Brand -->
    <a id="logo" class="navbar-brand pl-3" href="/">{{ config('app.name') }}</a>

    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#nav-search"
            aria-controls="nav-content" aria-expanded="false" aria-label="Toggle navigation">
        <span class="glyphicon glyphicon-search small"></span>
    </button>

   <!-- Links -->
    <div class="collapse navbar-collapse justify-content-sm-end" id="nav-content">
        <div class="collapse navbar-collapse justify-content-lg-center" id="nav-search">
            <form id="search-form" method="POST" action="{{ route('sphinx.search') }}" role="search"
            {{--<form id="search-form" method="POST" action="{{ route('debug') }}" role="search"--}}
                  class="form-inline justify-content-sm-center">
                {{ csrf_field() }}
                <!-- Search Form -->
                <!-- Old Search Form with Category List-->
                {{--@include('templates.search_input',['categories'=>\App\Models\Category::getCategoriesWithSubcategories()])--}}

                <div class="input-group">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="basic-addon">
                            <span class="glyphicon glyphicon-search"></span>
                        </span>
                        <button type="button" class="btn btn-warning dropdown-toggle dropdown-toggle-split"
                                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" {{--onclick="fillCatSelect()"--}}>
                            <span class="sr-only">Toggle Dropdown</span>
                        </button>
                        <div class="dropdown-menu">
                            <label for="subCat">Фильтровать по категории</label>
                            <div class="input-group mb-2 mt-2">

                                <select class="custom-select" name="subCat" id="subCat">
                                    <option value="" disabled selected hidden>Выберите категорию</option>
                                    @isset($categories)
                                        @foreach($categories as $category)
                                            <optgroup label="{{ $category->title }}">
                                                @foreach($category->subcategory as $subcategory )
                                                    <option value="{{ $subcategory->id }}">{{ $subcategory->title }}</option>
                                                @endforeach
                                            </optgroup>
                                        @endforeach
                                    @endisset
                                </select>

                            </div>
                        </div>
                    </div>

                    <input type="text" name="searchText" id="searchText" class="form-control"
                           placeholder="Поисковая строка" aria-label="Search" aria-describedby="basic-addon">
                    <div class="input-group-append">
                        <button class="btn btn-warning" type="submit">Поиск</button>
                    </div>
                </div>
            </form>
        </div>
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="{{ route('dashboard') }}">Обменник</a>
            </li>
            @guest
            <li class="nav-item">
                <a class="nav-link" href="{{ route('register') }}">Регистрация </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="{{ route('login') }}">Войти </a>
            </li>
            @else
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="{{ route('user.profile') }}" role="button"
                   aria-haspopup="true" aria-expanded="false">{{ auth()->user()->nickname }}</a>
                <div class="dropdown-menu dropdown-menu-right">
                    <a class="dropdown-item" href="{{ route('home') }}">Профиль</a>
                    <a class="dropdown-item" href="{{ route('user.item.create') }}">Добавить лот</a>
                    <a class="dropdown-item" href="{{ route('user.offers') }}">Сделки</a>
                    <a class="dropdown-item" href="{{ route('user.offers.archive') }}">Архив</a>

                    <div class="dropdown-divider"></div>
                    @if(auth()->user()->isAdmin())
                        <a class="dropdown-item" href="{{ route('admin.index') }}">Админ панель</a>
                    @endif
                </div>
            </li>
            <li class="nav-item">
                <a class="nav-link" onclick="event.preventDefault(); document.getElementById('logout-form').submit();"
                   href="#">Выход</a>
            </li>
            <form id="logout-form" action="/logout" method="POST" style="display: none;">
                {{ csrf_field() }}
            </form>
            @endauth
        </ul>
    </div>
</nav>