@extends('layouts.admin.theme')
@section("title", env("APP_NAME") . " :: Alterar Endereços")
@section('content')
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card shadow mx-0">  
                    @php $headLine = "<i class='fa-solid fa-location-dot'></i> Alterar Endereços"; @endphp

                    @include('components.buttons._headLineButtonsBackAdd', [
                                'headLine' => __($headLine),
                                'routeAdd' => 'admin.perfilEnderecos.create',
                                'routeAddParams' => [$user->id], 
                                'nameAdd' => __('Novo endereço'),
                                "permission" => "GUEST",
                            ])

                    <div class="card-body">
                        
                        @include("errors.messageFlash")
                        @include('components.modal._modelProfile')

                        <hr/>

                        <x-tables._table :thead="['#', 'Criado em', 'Tipo de domicílio', 'Endereco', 'Fixar', '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 . $index,
                                                "route" => "admin.perfilEnderecos.fixar",
                                                "id" => $endereco->id,
                                                "status" => $endereco->fixed,
                                                "permission" => "GUEST",
                                            ])
                                        </td>
                                        <td class="text-center align-middle">

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

                                        </td>
                                        <td>
                                            <div class="btn-group" role="group">

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

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

                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection