@php($title = 'Договоры')
@extends('layouts.app')
@section('content')
    <form method="get" class="bg-light rounded-3" action="{{ Request::fullUrl() }}">
        <div class="mb-3">
            <div class="sticky-top position-sticky d-flex flex-row">
                <div class="border rounded-3 border-1 p-1 bg-white">
                    <?php
                    $filterFormArray = [];
                    foreach ($filter as $key => $filterValue) {
                        if (!is_array($filterValue)) {
                            $filterFormArray['filter[' . $key . ']'] = $filterValue;
                        } else {
                            foreach ($filterValue as $num => $value) {
                                $filterFormArray['filter[' . $key . '][' . $num . ']'] = $value;
                            }
                        }
                    }
                    ?>
                    @foreach ($filterFormArray as $key => $filterValue)
                        <input type="hidden" name="{{ $key }}" value="{{ $filterValue }}">
                    @endforeach
                    <input type="radio" class="btn-check" name="mode" value="all" id="mode_all" autocomplete="off"
                        onclick="this.form.submit()" {{ $mode == 'all' ? 'checked' : '' }}>
                    <label class="btn p-2 fs-5" for="mode_all">Все</label>

                    <input type="radio" class="btn-check" name="mode" value="active" id="mode_active"
                        autocomplete="off" onclick="this.form.submit()" {{ $mode == 'active' ? 'checked' : '' }}>
                    <label class="btn p-2 fs-5" for="mode_active">Активные</label>

                    <input type="radio" class="btn-check" name="mode" value="successed" id="mode_successed"
                        autocomplete="off" onclick="this.form.submit()" {{ $mode == 'successed' ? 'checked' : '' }}>
                    <label class="btn p-2 fs-5" for="mode_successed">Успешные</label>

                    <input type="radio" class="btn-check" name="mode" value="declined" id="mode_declined"
                        autocomplete="off" onclick="this.form.submit()" {{ $mode == 'declined' ? 'checked' : '' }}>
                    <label class="btn p-2 fs-5" for="mode_declined">Отклоненные</label>
                </div>
                <div class="ms-auto hstack gap-2">
                    <button type="button" class="lh-1  btn bg-white p-3 fw-bold border rounded-3 border-1"
                        data-bs-toggle="modal" data-bs-target="#contractFilterModal">
                        <span class="d-none d-lg-inline">Фильтр</span>
                        <span class="position-relative">
                            <i class="bi bi-person-plus"></i>
                            @if ($filter)
                                <span class="notices-badge animation-blink"></span>
                            @endif
                        </span>
                    </button>
                </div>
            </div>
            <!-- Modal -->
            <div class="modal fade" id="contractFilterModal" tabindex="-1" aria-labelledby="contractFilterModalLabel"
                aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body" style="">
                            <div class="mb-3">
                                <div class="form_label">
                                    <label for="statusFilter" class="form-label">Статус</label>
                                    <div class="multiselect_block">
                                        <label for="select-1" class="field_multiselect">Выберите нужные статусы</label>
                                        <input id="checkbox-1" class="multiselect_checkbox" type="checkbox">
                                        <label for="checkbox-1" class="multiselect_label"></label>
                                        <select id="statusFilter" class="field_select form-select" name="filter[status][]"
                                            multiple style="w-100">
                                            @foreach ($statuses = GetContractStatuses() as $key => $status)
                                                <option @if (array_key_exists('status', $filter) && $filter['status'] == $key) checked @endif
                                                    value="{{ $key }}">{{ $status }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <span class="error_text"></span>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
                            <input type="submit" class="btn btn-primary" value="Применить">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div>
        @livewire('contracts.table', [
            'mode' => $mode,
            'filter' => $filter,
        ])
    </div>
@endsection
