{{-- resources/views/components/testimoni/index.blade.php --}}
@php
    use App\Helpers\VerbaleHelper;
    $hasValidWitnesses = isset($data['testi_oculari']) &&
        count($data['testi_oculari']) > 0 &&
        collect($data['testi_oculari'])->some(fn($teste) => $teste->testi_oculari > 0);
@endphp

@if ($hasValidWitnesses)
    <table width="100%">
        <tr>
            <td width="100%" valign="top" align="center">
                <h2>TESTE OCULARI</h2>
            </td>
        </tr>
        <tr><td></td></tr>
    </table>

    @foreach ($data['testi_oculari'] as $i => $teste)
        @if ($teste->testi_oculari > 0)
            <table class="table-content" width="100%">
                <tr>
                    <td width="20%" align="center" style="font-size: 20px;">
                        <table>
                            <tr class="tr-sub-title">
                                <td class="bold">TESTE</td>
                            </tr>
                        </table>
                    </td>
                    <td width="80%">
                        <table>
                            <tr>
                                <td width="25%" class="veicolo-title-cell">COGNOME E NOME:</td>
                                <td width="15%" class="veicolo-content-cell">
                                    {{ @$teste->teste->lastname }} {{ @$teste->teste->firstname }}
                                </td>
                                <td width="15%" class="veicolo-title-cell">NATO A:</td>
                                <td width="20%" class="veicolo-content-cell">
                                    {{ @$teste->teste->birth_town_id_value->title }}
                                </td>
                            </tr>

                            @if ($teste->teste->birth_date != '')
                                <tr>
                                    <td width="15%" class="veicolo-title-cell">NATO IL:</td>
                                    <td width="25%" class="veicolo-content-cell">
                                        {{ App\Helpers\DateHelper::formatDate(@$teste->teste->birth_date) }}
                                    </td>
                                </tr>
                            @endif

                            @if ($teste->stato_testi_oculari != '')
                                <tr>
                                    <td width="25%" class="veicolo-title-cell">STATO TESTE:</td>
                                    <td width="70%" class="veicolo-content-cell">
                                        {{ VerbaleHelper::getStatusText($teste->stato_testi_oculari,VerbaleHelper::getWitnessStatusMap()) }}
                                    </td>
                                </tr>
                            @endif

                            <tr><td></td></tr>
                        </table>
                    </td>
                </tr>
            </table>
        @endif
    @endforeach
@endif
