<div>
    @include('parts.loading')
    @include('parts.alerts')


    <div class="row mt-5">
        <div class="col-12">
            <div class="card">
                <div class="card-header bg-gray-100">
                    <div class="form-row form-row-filter">
                        <div class="col-md-5">
                            <div class="wrapper-search">
                                <input type="text" id="search" class="form-control" wire:model.debounce.1000ms="params.search" placeholder="Buscar...">
                                @if (!empty($search))
                                <button type="button" class="btn" id="btn-search">
                                    <i class="fa fa-times"></i>
                                </button>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-2">
                            <select class="form-control" wire:model="params.brand_id">
                                <option value="">.:: Seleccionar marca ::.</option>
                                @foreach ($brands_items as $key => $value)
                                    <option value="{{ $value['id'] }}">{{ $value['name'] }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-md-2">
                            <select class="form-control" wire:model="params.types_use_id">
                                <option value="">.:: Seleccionar tipo ::.</option>
                                @foreach ($types_use_items as $key => $value)
                                    <option value="{{ $value['id'] }}">{{ $value['name'] }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-md-3">
                            <a href="{{ route('vehicle-quote.manage-vehicle.create') }}" class="btn btn-primary btn-block float-right">
                                <i class="fas fa-plus"></i>
                                Nuevo vehículo
                            </a>
                        </div>
                    </div>
                </div>
                <div class="card-content">
                    <div class="card-body">
                        @if ($items->count())
                        <div class="table-responsive">
                            <table class="table">
                                <thead class="thead-light">
                                    <tr>
                                        <th>Marca</th>
                                        <th>Modelo</th>
                                        <th class="text-center" style="width:150px;">Año</th>
                                        <th class="text-center" style="width:150px;">Pasajeros</th>
                                        <th class="text-center" style="width:150px;">Tipo</th>
                                        <th class="text-center"  style="width:150px;">Imagen</th>
                                        <th class="text-center" style="width: 80px;">Acciones</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($items as $item)
                                    <tr>
                                        <td>{{ $item->brand->name }}</td>
                                        <td>{{ $item->model->name }}</td>
                                        <td class="text-center">{{ $item->year }}</td>
                                        <td class="text-center">{{ $item->pax }}</td>
                                        <td class="text-center">{{ $item->type_use->name }}</td>
                                        <td class="text-center align-middle">
                                            @if ($item->image)
                                            <a class="single_image" href="{{ $item->image_path }}">
                                                <img src="{{ $item->image_path }}" alt="{{ $item->name }}" class="img-fluid"
                                                style="width:38px; height:34px;object-fit: cover;">
                                            </a>

                                            @else
                                                <i class="la la-image text-dark" style="font-size: 45px;"></i>
                                            @endif
                                        </td>
                                        <td class="text-center">
                                            <div class="btn-group btn-group-sm">
                                                <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                                                    aria-haspopup="true" aria-expanded="false">
                                                    <i class="fas fa-ellipsis-h"></i>
                                                </a>
                                                <div class="dropdown-menu dropdown-menu-right">
                                                    <a  href="{{ route('vehicle-quote.manage-vehicle.edit', $item->id) }}"
                                                        class="dropdown-item btn-link">
                                                        <i class="fas fa-pencil-alt mr-1"></i> Editar
                                                    </a>
                                                    <button wire:click="$emit('triggerDestroy',{{ $item->id }})"
                                                        class="dropdown-item btn-link text-danger">
                                                        <i class="far fa-trash-alt mr-1"></i> Eliminar
                                                    </button>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    @endforeach
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <th colspan="7">
                                            {{ $items->links() }}
                                        </th>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                        @else
                        <div class="alert alert-secondary" role="alert">
                            No se encontraron resultados
                        </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

@push('styles')
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.css" type="text/css" media="screen" />
@endpush

@section('js')
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>
@include('parts.js-destroy')
{{-- @include('parts.js-preview') --}}
{{-- @include('parts.js-search') --}}

<script type="text/javascript">
    $(document).ready(function() {

        function init() {

            $("a.single_image").off('click');
            $("a.single_image").on('click', function(e) {
                e.preventDefault();
                $.fancybox.open({
                    src: $(this).attr('href'),
                    type: 'image'
                });
            });
        }

        init()

        Livewire.hook('message.processed', (message, component) => { init(); });

        const element = $('#mydiv');
        element.animate({
            scrollTop: element.prop("scrollHeight")
        }, 500);

    });
</script>
@endsection
