@extends('layouts.admin.theme')
@section("title", env("APP_NAME") . " :: Lista de endereços de {$user->name} sob CPF nº {$user->cpf}")
@section('content') 

    @include("errors.messageFlash")

    <div class="card shadow-sm">

        @php $headLine = "<i class='fa-solid fa-location-dot'></i> Lista de endereços de <strong>{$user->name}</strong> sob CPF nº <strong>{$user->cpf}</strong>"; @endphp
        
        @include('components.buttons._headLineButtonsBackAdd', [
            'headLine' => __($headLine),
            'routeBack' => 'admin.contas.index',
            'routeBackParams' => [], 
            'nameBack' => __("Voltar"),
            'routeAdd' => 'admin.contas.enderecos.create',
            'routeAddParams' => [$user->id], 
            'nameAdd' => __('Novo endereço'),
            "permission" => "SYSADMIN",
        ])
        
        
         <x-tables._table :thead="['#', 'Criado em', 'Tipo de domicílio', 'Endereco', 'Status', 'Ações']" :pagination="$enderecos->links()">
            <x-slot name="body">
                @php  $index = 0;  @endphp
                @foreach($enderecos as $endereco)
                    <tr>
                        <td>
                            @if(isset($endereco->id))
                                <div style="width: 120px;">
                                    @include('components.tables._openPhotoAndPdf',[
                                        'asset' => $endereco->comprovante,
                                        'alt' => "Comprovante de {$user->name}",
                                        'title' => "Comprovante de {$user->name}",
                                        'text' => 'Visualizar foto',
                                        'index' => $index,
                                    ])
                                </div>
                            @endif
                        </td>
                        <td>{{ date("d/m/Y H:m", strtotime($endereco->created_at)) }}</td>
                        <td>
                            @include("components.tables._getEnumValue", [
                                "EnumClass" => App\Enums\StatusDomicilio::cases(),
                                "arg" => $endereco->domicilio,
                            ])
                        </td>
                        <td>
                            {!! $endereco->address !!}
                        </td>
                        <td class="text-center align-middle">

                            @include('components/buttons/_status', [
                                "index" => $index,
                                "route" => "admin.contas.enderecos.status",
                                "id" => [$user->id, $endereco->id],
                                "status" => $endereco->status,
                                "permission" => "SYSADMIN",
                            ])

                        </td>
                        <td>
                            <div class="d-flex gap-2 justify-content-center">

                                @include('components/buttons/_editButton', [
                                    "route" => "admin.contas.enderecos.edit",
                                    "id" => [$user->id, $endereco->id],
                                    "fontawesome" => null,
                                    "title" => "Editar",
                                    "permission" => "SYSADMIN",
                                ])

                                
                                    @include('components/buttons/_deleteButton', [
                                        "message" => __("* Este endereço será excluído e esta ação não poderá ser desfeita, deseja continuar?"),
                                        "route" => "admin.contas.enderecos.destroy",
                                        "id" => [$user->id, $endereco->id],
                                        "fontawesome" => null,
                                        "title" => "Excluir",
                                        "permission" => "SYSADMIN",
                                    ])
                                
                                
                            </div>
                        </td>
                    </tr>
                    @php $index++; @endphp
                @endforeach
            </x-slot>
        </x-tables._table>

    </div>
@endsection
