<html>

<x-head />

<body>

    <x-header />

    <div class="bradcam_area bradcam_bg_1">
        <div class="container">
            <div class="row">
                <div class="col-xl-12">
                    <div class="bradcam_text">
                        <h3>{{$jobs->total()}}+ Вакансий доступно</h3>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="job_listing_area plus_padding">
        <div class="container">
            <div class="row">
                <div class="col-lg-3">
                    <div class="job_filter white-bg">
                        <div class="form_inner white-bg">
                            <h3>Фильтр</h3>
                            <form action="">
                                <div class="row">
                                    <div class="col-lg-12">
                                        <div class="single_field">
                                            <input type="text" id="name" name="name" placeholder="Вакансия" value="{{$req->name}}">
                                        </div>
                                    </div>
                                    <div class="col-lg-12">
                                        <div class="single_field">
                                            <select class="wide" id="jobnature" name="jobnature">
                                                @if($req->jobnature)
                                                    <option value="{{$req->jobnature}}">{{$req->jobnature}}</option>
                                                    @foreach($all_jobs->unique('jobnature') as $job)
                                                        @if($job->jobnature!= $req->jobnature)
                                                            <option value="{{$job->jobnature}}">{{$job->jobnature}}</option>
                                                        @endif
                                                    @endforeach
                                                    <option value="{{NULL}}">Все</option>
                                                @else
                                                    <option value="{{NULL}}">Тип занятости</option>
                                                    @foreach($jobs->unique('jobnature') as $job)
                                                        <option value="{{$job->jobnature}}">{{$job->jobnature}}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-lg-12">
                                        <div class="single_field">
                                            <select class="wide" id="city_id" name="city_id">
                                                @if($req->city_id)
                                                    <option value="{{$req->city_id}}">{{$cityreq->name}}</option>
                                                    @foreach($cities as $city)
                                                    @if($city->id != $req->city_id)
                                                    <option value="{{$city->id}}">{{$city->name}}</option>
                                                    @endif
                                                    @endforeach
                                                    <option value="{{NULL}}">Все</option>
                                                @else
                                                    <option value="{{NULL}}">Город</option>
                                                    @foreach($cities as $city)
                                                        <option value="{{$city->id}}">{{$city->name}}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-lg-12">
                                        <div class="single_field">
                                            <select class="wide" id="category_id" name="category_id">
                                            @if($req->category_id)
                                                    <option value="{{$req->category_id}}">{{$categoryreq->name}}</option>
                                                    @foreach($categories as $category)
                                                    @if($category->id != $req->category_id)
                                                    <option value="{{$category->id}}">{{$category->name}}</option>
                                                    @endif
                                                    @endforeach
                                                    <option value="{{NULL}}">Все</option>
                                                @else
                                                    <option value="{{NULL}}">Категория</option>
                                                    @foreach($categories as $category)
                                                        <option value="{{$category->id}}">{{$category->name}}</option>
                                                    @endforeach
                                                @endif

                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="range_wrap">
                                    <label for="salary">Price range:</label>
                                    <div id="slider-range"></div>
                                    <p>
                                        <input type="text" id="salary" name="salary" readonly style="border:0; color:#7A838B; font-size: 14px; font-weight:400;">
                                    </p>
                                </div>
                                <button class="boxed-btn3 w-100" type="submit">Принять</button>
                            </form>
                        </div>
                    </div>
                </div>

                <div class="col-lg-9">
                    <div class="recent_joblist_wrap">
                        <div class="recent_joblist white-bg ">
                            <div class="row align-items-center">
                                <div class="col-md-6">
                                    <h4>Список вакансий</h4>
                                </div>
                                <div class="col-md-6">
                                    <div class="serch_cat d-flex justify-content-end">
                                        <select>
                                            <option data-display="Most Recent">Most Recent</option>
                                            <option value="1">Marketer</option>
                                            <option value="2">Wordpress </option>
                                            <option value="4">Designer</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="job_lists m-0">
                        <div class="row">
                            @foreach($jobs as $job)
                            <div class="col-lg-12 col-md-12">
                                <div class="single_jobs white-bg d-flex justify-content-between">
                                    <div class="jobs_left d-flex align-items-center">
                                        <div class="thumb">
                                            <img src="public/{{ $job->icon }}" alt="">
                                        </div>
                                        <div class="jobs_conetent">
                                            <a href="{{Route('jobs_details', $job->id)}}">
                                                <h4>{{ $job->name }}</h4>
                                            </a>
                                            <div class="links_locat d-flex align-items-center">
                                                <div class="location">
                                                    <p> <i class="fa fa-map-marker"></i>{{ $job->city->name }}</p>
                                                </div>
                                                <div class="location">
                                                    <p> <i class="fa fa-clock-o"></i>{{ $job->jobnature }}</p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="jobs_right">
                                        <div class="apply_now">
                                            <p class="heart_mark">{{ $job->salary }} руб.</p>
                                            <a href="{{Route('jobs_details', $job->id)}}" class="boxed-btn3">Подробнее</a>
                                        </div>
                                        <div class="date">
                                            <p>Дата создания: {{ $job->created_at }}</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            @endforeach
                        </div>
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="pagination_wrap">
                                    {{$jobs->links('vendor.pagination.simple-default')}}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <x-footer />

    <x-scripts />

    <script>
        $(function() {
            var minSalary = <?php echo $all_jobs->min('salary'); ?>;
            var maxSalary = <?php echo $all_jobs->max('salary'); ?>;

            $("#slider-range").slider({
                range: true,
                min: minSalary,
                max: maxSalary,
                values: [<?php echo ($minsalary == 0) ? $all_jobs->min('salary') : $minsalary; ?>, <?php echo ($minsalary == 0) ? $all_jobs->max('salary') : $maxsalary; ?>],
                slide: function(event, ui) {
                    $("#salary").val(ui.values[0] + " - " + ui.values[1] + "р./мес.");
                }
            });
            $("#salary").val($("#slider-range").slider("values", 0) +
                " - " + $("#slider-range").slider("values", 1) + "р./мес.");
        });

        const citySelect = document.getElementById('city_id');
        citySelect.addEventListener('change', () => {
            localStorage.setItem('selectedCity', citySelect.value);
        });

        window.addEventListener('load', () => {
            const storedCity = localStorage.getItem('selectedCity');
            if (storedCity) {
                citySelect.value = storedCity;
            }
        });
    </script>


</body>

</html>