@extends('layouts.admin.theme')
@section("title", env("APP_NAME") . " :: Cadastro de Ambulantes - Lista de Ambulantes")
@section('content')

    <div class="card shadow-sm">
        
        @include('components.buttons._headLineButtonsBackAdd', [
            'headLine' => __("Cadastro de Ambulantes - Lista de Ambulantes"),
//            'routeBack' => 'admin.turismoNautico.index',
//            'routeBackParams' => [], 
//            'nameBack' => __("Voltar"),
            'routeAdd' => 'admin.cadastroDeAmbulantes.ambulantes.verify',
            'routeAddParams' => [], 
            'nameAdd' => __('Novo ambulante')
        ])
        
        <div class="card-body">
            
            @include("errors.messageFlash")

            @include('components/forms/_filtroPesquisaDefault', [ 
                "id" => "turismoCadastroAmbulantesLista", 
                "placeholder" => "Pesquisar por ambulantes..."
            ])

            <div class="row">
                <div class="col-12">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover table-striped align-middle text-center">
                            @include('components.tables._thead', ['thead' => ['#', 'Criado em', 'Nome/Razão social', 'CPF/CNPJ', 'E-mail', 'Status', 'Ações']])
                            <tbody>
                                @php $index = 0; @endphp
                                @forelse($ambulantes as $ambulante)
                                    <tr>
                                        <td style="width: 150px">
                                            @include('components.tables._openPhoto',[
                                                'asset' => $ambulante?->proprietario->photo,
                                                'alt' => $ambulante?->proprietario->firstName." ".$ambulante?->proprietario->lastName,
                                                'title' => $ambulante?->proprietario->firstName." ".$ambulante?->proprietario->lastName,
                                                'text' => 'Visualizar foto',
                                            ])
                                        </td>
                                        <td>{{ date("d/m/Y H:m", strtotime($ambulante?->created_at)) }}</td>
                                        <td>
                                            @if(isset($ambulante?->proprietario->firstName))
                                                <strong>Nome: </strong>{{ $ambulante?->proprietario->firstName }} {{ $ambulante?->proprietario->lastName }}
                                            @endif
                                            @if(isset($ambulante?->comercio?->nomeFantasia))
                                                <br><strong>Razão social:</strong> {{ $ambulante?->comercio?->nomeFantasia }}
                                            @endif
                                        </td>
                                        <td>
                                            @if(isset($ambulante?->proprietario?->cpf))
                                                <strong>CPF:</strong> {{ $ambulante?->proprietario?->cpf }}
                                            @endif
                                            @if(isset($ambulante?->comercio?->cnpj))
                                                <br><strong>CNPJ:</strong> {{ $ambulante?->comercio?->cnpj }}
                                            @endif
                                        </td>
                                        <td>{{ $ambulante?->proprietario->email }}</td>
                                        <td class="text-center align-middle">
                                            @include('components/buttons/_status', [
                                                "index" => $index,
                                                "route" => "admin.cadastroDeAmbulantes.ambulantes.status",
                                                "id" => $ambulante?->id,
                                                "status" => $ambulante->status,
                                            ])
                                        </td>
                                        <td>
                                            <div class="btn-group" role="group">
                                                @include('components/buttons/_editButton', [
                                                    "route" => "admin.cadastroDeAmbulantes.ambulantes.proprietarioEdit",
                                                    "id" => $ambulante->id,
                                                    "fontawesome" => null,
                                                    "title" => "Editar",
                                                ])
                                                
                                                @include('components/buttons/_editButton', [
                                                    "route" => "admin.cadastroDeAmbulantes.ajudantes.index",
                                                    "id" => $ambulante->id,
                                                    "fontawesome" => '<i class="fa-solid fa-handshake-angle"></i>',
                                                    "title" => "Ajudantes",
                                                ])
                                                
                                                @include('components/buttons/_editButton', [
                                                    "route" => "admin.cadastroDeAmbulantes.penalidades.index",
                                                    "id" => $ambulante->id,
                                                    "fontawesome" => '<i class="fa-solid fa-file-invoice"></i>',
                                                    "title" => "Penalidades",
                                                ])
                                                
                                                @include('components/buttons/_editButton', [
                                                    "route" => "admin.cadastroDeAmbulantes.registros.index",
                                                    "id" => $ambulante->id,
                                                    "fontawesome" => '<i class="fa-solid fa-address-card"></i>',
                                                    "title" => "Registros",
                                                ])

                                                @include('components/buttons/_deleteButton', [
                                                    "message" => "* Este guia turístico será excluído e esta ação não poderá ser desfeita?",
                                                    "route" => "admin.cadastroDeAmbulantes.ambulantes.destroy",
                                                    "id" => $ambulante->id,
                                                    "fontawesome" => null,
                                                    "title" => "Excluir",
                                                ])
                                            </div>
                                        </td>

                                    </tr>
                                    @php $index++; @endphp
                                @empty
                                    <tr>
                                        <td colspan="7">* Nenhum registro encontrado</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-12 my-3">
                    <div class="d-flex justify-content-center">{!! $ambulantes->links() !!} </div>
                </div>
            </div>
        </div>
    </div>
@endsection