<div >
    @include('parts.overlay', ['target' => 'store, back, checkInsurer'])

    <form wire:submit.prevent="{{ $form_insurers['action'] }}" autocomplete="off">
        <div class="row match-height mt-5">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h4 class="card-title">{{  $form_insurers['title']  }}</h4>
                    </div>
                    <div class="card-content" id="card-insurers" x-data="{
                        cardClick: function (event) {
                            let card = event.target.closest('.card');
                            let checkbox = card.querySelector('.customCheck');
                            checkbox.checked = !checkbox.checked;
                            checkbox.dispatchEvent(new Event('click'));
                        }
                    }">
                        <div class="card-body">
                            <div class="row">
                                @forelse ($list_insurers as $insurer_key => $insurer)
                                    <div class="col- mb-3 px-2">
                                        <div class="card" style="width: 18rem;" x-on:click="cardClick">
                                            <div class="divImg d-flex align-items-sm-center justify-content-center">
                                                <img class="img-thumbnail border-0" src="{{ $insurer['image'] }}" alt="{{ $insurer['name'] }}">
                                            </div>
                                            <div class="card-body">
                                              <h5 class="card-title">{{ ucfirst($insurer['name']) }}</h5>
                                              <div class="custom-control custom-checkbox mt-2">
                                                <input type="checkbox" class="custom-control-input customCheck" id="customCheck1-{{ $insurer['id'] }}" wire:click="checkInsurer({{ $insurer_key }})" {{ $insurer['selected'] == true ? 'checked' : 'unchecked' }}>
                                                <label class="custom-control-label" for="customCheck1-{{ $insurer['id'] }}">Seleccionar</label>
                                            </div>
                                            </div>
                                        </div>
                                    </div>
                                @empty
                                    <div class="col-12">
                                        <p>No hay aseguradoras registradas</p>
                                    </div>
                                @endforelse
                            </div>

                            <div class="row">
                                <div class="col-12 d-flex justify-content-end">
                                    <button id="btn-submit" type="submit" class="btn btn-primary mr-1 mb-1" wire:loading.attr="disabled"
                                        wire:target="{{ $form_insurers['action'] }}">
                                        {{ $form_insurers['label'] }}
                                        <i class="fas fa-arrow-circle-right"></i>
                                    </button>
                                    <a type="button" class="btn btn-secondary mr-1 mb-1" wire:click="back" >
                                        <i class="fa fa-angle-double-left" aria-hidden="true"></i>
                                        Regresar
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
@push('styles')
    <style>
        #card-insurers .divImg {
            height: 200px;
        }
        #card-insurers .divImg img {
            object-fit: cover;
        }

        #card-insurers .card {
            cursor: pointer;
            height: 92%;
        }
    </style>
@endpush

@push('scripts')
    <script>

    </script>
@endpush
