@php
    use App\Helpers\DateHelper;

    $pedestrians = collect($data['parti_coinvolte'])->filter(function ($item) {
        return $item->conducente_o_pedone == 1;
    });
    $infortunatoStatus = [
    0 => 'INCOLUME',
    1 => 'FERITO',
    2 => 'DECEDUTO ENTRO 24 ORE',
    3 => 'DECEDUTO ENTRO 30 GG.',
    ];

    $generalizzatoStatus = [
    1 => 'SUL LUOGO',
    2 => 'IN OSPEDALE',
    3 => 'ALTROVE',
    ];

    $documentoMap = [
    1 => 'Carta Identità',
    2 => 'Patente',
    4 => 'Passaporto',
    5 => 'Altro',
    ];
@endphp

@if ($pedestrians->count() > 0)
    <table width="100%" class="table-title">
        <tr>
            <td width="100%" valign="top" align="center">
                <h2>PEDONI</h2>
            </td>
        </tr>
    </table>

    @php $pedoneCounter = 0; @endphp
    @foreach ($pedestrians as $parte)
        @php
            $datiPedoni = $data['datiPedoni'][$parte->progressive];
        @endphp

        @foreach ($datiPedoni as $pedone)
            @if ($pedone->pedoni > 0)
                @php
                    $anagraficaPedone = \App\Models\Anagrafica::find($pedone->pedoni);
                    $pedoneLabel = chr(65 + $pedoneCounter);
                @endphp

                <table class="table-content striped-table" width="100%">
                    <tr>
                        <td width="20%" align="center" style="font-size: 20px;">
                            <table class="">
                                <tr class="tr-sub-title">
                                    <td class="bold" style="border: none!important">PEDONE {{ $pedoneLabel }}</td>
                                </tr>
                            </table>
                        </td>
                        <td width="80%">
                            <table class="striped-table">
                                @if ($anagraficaPedone)
                                    <tr>
                                        <td width="25%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">COGNOME E NOME:</td>
                                        <td width="40%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ $anagraficaPedone->lastname }}
                                            {{ $anagraficaPedone->firstname }}
                                        </td>

                                        <td width="15%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">NATO A:</td>
                                        <td width="20%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ optional($anagraficaPedone->birth_town_id_value)->title }}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td width="15%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">NATO IL:</td>
                                        <td width="25%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ (!empty($anagraficaPedone->birth_date) && Carbon\Carbon::parse($anagraficaPedone->birth_date)->year > 0) ? Carbon\Carbon::parse($anagraficaPedone->birth_date)->format('d/m/Y') : '-' }}

                                        </td>
                                    </tr>

                                    @if (!$anagraficaPedone->residenza_town_id)
                                        <tr>
                                            <td class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">RESIDENTE A:</td>
                                            <td class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                                {{ optional($anagraficaPedone->residenza_town_id_value)->title ?? '' }}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">RESIDENTE IN:</td>
                                            <td class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                                {{ $anagraficaPedone->residenza_address ?? '' }}
                                            </td>
                                        </tr>
                                    @endif

                                    <tr>
                                        <td class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">TELEFONO:</td>
                                        <td class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ $anagraficaPedone->mobile ?? '' }}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">INDIRIZZO:</td>
                                        <td class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ $anagraficaPedone->residenza_address ?? '' }}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">COMUNE:</td>
                                        <td class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ optional($anagraficaPedone->residenza_town_id_value)->title ?? '' }}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">PROVINCIA:</td>
                                        <td class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ optional($anagraficaPedone->residenza_prov_id_value)->title ?? '' }}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td width="30%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">GENERALIZZATO:</td>
                                        <td width="35%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ $generalizzatoStatus[$pedone->generalizzato] ?? '' }}
                                            @if ($pedone->generalizzato == 3)
                                                {{ $pedone->generalizzato_altrove }}
                                            @endif
                                        </td>
                                    </tr>

                                    <tr>
                                        <td width="20%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">DOCUMENTO:</td>
                                        <td width="20%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            @if ($anagraficaPedone)
                                                {{ $documentoMap[$anagraficaPedone->documento_tipo] ?? '' }}
                                            @endif
                                        </td>
                                        <td width="30%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">NUMERO:</td>
                                        <td width="25%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ $anagraficaPedone->documento_numero ?? '' }}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td width="25%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">SEDICENTE:</td>
                                        <td width="20%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            {{ $anagraficaPedone->sedicente ? 'SI' : 'NO' }}
                                        </td>
                                    </tr>
                                @endif

                                @if ($pedone->pedone_posizione > 0)
                                    <tr>
                                        <td width="30%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">POSIZIONE:</td>
                                        <td width="50%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                            @php
                                                $posizioneMap = [
                                                    1 => 'Presente e in posizione',
                                                    2 => 'Già soccorso e trasportato presso ospedale',
                                                ];
                                            @endphp
                                            {{ $posizioneMap[$pedone->pedone_posizione] ?? '' }}
                                        </td>
                                    </tr>
                                @endif


                                <tr>
                                    <td width="30%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">CONDIZIONI METEO:</td>
                                    <td width="35%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                        {{ $pedone->pedone_pioggia == 1 ? 'PIOGGIA' : 'SOLE' }}
                                    </td>
                                </tr>

                                <tr>
                                    <td width="30%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">CONDIZIONI LUCE:</td>
                                    <td width="35%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                        {{ $pedone->pedone_notte == 1 ? 'NOTTE' : 'GIORNO' }}
                                    </td>
                                </tr>

                                <tr>
                                    <td width="30%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">OMBRELLO PEDONE:</td>
                                    <td width="35%" class="veicolo-content-cell" style="padding-bottom: 10px !important;border: none!important">
                                        {{ $pedone->pedone_ombrello == 1 ? 'OMBRELLO AL SEGUITO' : 'NON AL SEGUITO' }}
                                    </td>
                                </tr>

                                <tr>
                                    <td width="30%" class="veicolo-title-cell" style="padding-bottom: 10px !important;border: none!important">ABITI SCURI PEDONE:</td>
                                    <td width="35%" class="veicolo-content-cell">
                                        {{ $pedone->pedone_abiti_scuri == 1 ? 'SCURI' : 'NON SCURI' }}
                                    </td>
                                </tr>

                                @if ($pedone->verbale_violazione_numero)
                                    <tr>
                                        <td width="100%" class="" style="padding-bottom: 10px !important;border: none!important">
                                            <b>VERBALE VIOLAZIONE NUMERO:</b>
                                            {{ $pedone->verbale_violazione_numero }}
                                        </td>
                                    </tr>
                                @endif

                                @if ($pedone->articolo_violato)
                                    <tr>
                                        <td width="100%" class="" style="padding-bottom: 10px !important;border: none!important">
                                            <b>ARTICOLO VIOLATO:</b>
                                            {{ $pedone->articolo_violato }}
                                        </td>
                                    </tr>
                                @endif

                                @if ($pedone->cds)
                                    <tr>
                                        <td width="100%" class="" style="padding-bottom: 10px !important;border: none!important">
                                            <b>CDS:</b>
                                            {{ $pedone->cds }}
                                        </td>
                                    </tr>
                                @endif
                            </table>
                        </td>
                    </tr>
                </table>

                @php $pedoneCounter++; @endphp
            @endif
        @endforeach
    @endforeach
@endif
