{{-- 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)
<style>
    .striped-table {
        width: 100%;
        border-collapse: collapse;
    }

    .striped-table th, .striped-table td {
        border: 1px solid #000;
        padding: 8px;
    }

    .striped-table tr:nth-child(even) {
        background-color: #f2f2f2;
    }

    .striped-table tr:nth-child(odd) {
        background-color: #fff;
    }
</style>
    <table width="100%">
        <tr>
            <td width="100%" valign="top" align="center">
                <h2>TESTE OCULARI</h2>
            </td>
        </tr>
    </table>

    @foreach ($data['testi_oculari'] as $i => $teste)
        @if ($teste->testi_oculari > 0)
            <table class="table-content striped-table" width="100%">
                <tr>
                    <td width="20%" align="center" style="font-size: 20px;">
                        <table>
                            <tr class="tr-sub-title">
                                <td class="bold" style="border: none!important">TESTE</td>
                            </tr>
                        </table>
                    </td>
                    <td width="80%">
                        <table class="striped-table">
                            <tr>
                                <td width="40%" class="veicolo-title-cell" style="padding-bottom: 10px !important;">COGNOME E NOME:</td>
                                <td width="60%" class="veicolo-content-cell" style="padding-bottom: 10px !important;">
                                    {{ @$teste->teste->lastname }} {{ @$teste->teste->firstname }}
                                </td>
                            </tr>

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

                                    </td>
                                </tr>
                            @endif

                            @if ($teste->stato_testi_oculari != '')
                                <tr>
                                    <td width="30%" class="veicolo-title-cell" style="padding-bottom: 10px !important;">STATO TESTE:</td>
                                    <td width="70%" class="veicolo-content-cell" style="padding-bottom: 10px !important;">
                                        {{ VerbaleHelper::getStatusText($teste->stato_testi_oculari,VerbaleHelper::getWitnessStatusMap()) }}
                                    </td>
                                </tr>
                            @endif

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