@extends('layouts.app')

@section('content')

    <div class="row mb-3">
        <div class="col-6">
            <h3>Каталог</h3>
        </div>
        <div class="col-6 text-end">
            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#importModal">
                Импорт
            </button>
            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exportModal">
                Экспорт
            </button>
            <a href="{{ route('catalog.create') }}" class="btn btn-primary">Добавить</a>

        </div>
    </div>


    @include('partials.table', [
        'id'        => $id,
        'header'    => $header,
        'strings'   => $products,
        'routeName' => 'catalog.show',
    ])

    <div class="row pt-3 px-3">
        <div class="col-12 pagination">
            {{ $products->links() }}
        </div>
    </div>


    <!-- Модальное окно импорта-->
    <div class="modal fade" id="importModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-fullscreen-sm-down">
            <div class="modal-content">
                <div class="modal-header">
                    <h1 class="modal-title fs-5" id="exampleModalLabel">Выберите год и файл для импорта</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
                </div>
                <div class="modal-body">
                    <form action="{{ route('catalog.import') }}" method="post" enctype="multipart/form-data">
                        @csrf
                        @include('partials.input', ['title' => 'XLSX файл', 'name' => 'import_file', 'type' => 'file', 'required' => true])
                        @include('partials.submit', ['name' => 'Импорт'])
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- Модальное окно экспорта-->
    <div class="modal fade" id="exportModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h1 class="modal-title fs-5" id="exampleModalLabel">Экспорт</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
                </div>
                <div class="modal-body">
                    <form action="{{ route('catalog.export') }}" method="post" enctype="multipart/form-data">
                        @csrf
                        @include('partials.checkbox', ['title' => 'С учётом текущего фильтра и поиска', 'name' => 'withFilter', 'type' => 'checkbox', 'value' => 'yes', 'checked' => false])
                        <div class="d-none">
                            @if(request()->s)
                                @include('partials.input', ['name' => 'filters[s]', 'title' => 'поиск', 'value' => request()->s])
                            @endif
                            @if(request()->filters)
                                @foreach(request()->filters as $filterName => $filterValue)
                                    @include('partials.input', ['name' => 'filters[' . $filterName .']', 'title' => $filterName, 'value' => $filterValue])
                                @endforeach
                            @endif
                        </div>
                        @include('partials.submit', ['name' => 'Экспорт'])
                    </form>
                </div>
            </div>
        </div>
    </div>

    @if($errors->count())
        @dump($errors)
    @endif
@endsection

