@php
    $verticaleAreas = [
        'segnaletica_verticale_1',
        'segnaletica_verticale_2',
        'segnaletica_verticale_3',
        'segnaletica_verticale_4'
    ];
@endphp

@foreach ($verticaleAreas as $index => $area)
    @php
        $viaKey = $area . '_via';
        $direzioneKey = $area . '_direzione';
        $altroKey = $area . '_altro';

        $hasData = isset($data['record']->{$viaKey}) && $data['record']->{$viaKey} != '' ||
                   isset($data['record']->{$direzioneKey}) && $data['record']->{$direzioneKey} != '' ||
                   isset($data['record']->{$altroKey}) && $data['record']->{$altroKey} != '' ||
                   (isset($data[$area]) && count($data[$area]) > 0);
    @endphp

    @if ($hasData)
        <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%" class="table-title">
            <tr>
                <td style="{{ $index !== 0 ? 'border: none;' : '' }}" align="center">
                    <h2>SEGNALETICA VERTICALE {{$index + 1}}</h2>
                </td>
            </tr>
        </table>
        <table class="table-content striped-table" width="100%">
            @if (isset($data['record']->{$viaKey}) && $data['record']->{$viaKey} != '')
                <tr>
                    <td width="100%" align="center" style="padding-bottom: 10px !important;border: none!important">
                        <b>VIA DI RIFERIMENTO:</b>
                        {{ optional($data['record']->{$viaKey . '_value'})->TOPONIMO }}
                        {{ optional($data['record']->{$viaKey . '_value'})->DESCRIZIONE }}
                    </td>
                </tr>
            @endif

            @if (isset($data['record']->{$direzioneKey}) && $data['record']->{$direzioneKey} != '')
                <tr>
                    <td width="100%" align="center" style="padding-bottom: 10px !important;border: none!important">
                        <b>DIREZIONE:</b> {{ $data['record']->{$direzioneKey} }}
                    </td>
                </tr>
            @endif

            @if (isset($data[$area]) && count($data[$area]) > 0)
                @foreach ($data[$area] as $index => $segnaletica_verticale)
                    <tr>
                        <td align="center" width="100%" style="padding-bottom: 10px !important;border: none!important">
                            <b>DETTAGLIO SEGNALETICA VERTICALE: {{$index + 1}}</b>
                            {{ optional($segnaletica_verticale->segnaletica_verticale)->name }}
                        </td>
                    </tr>
                @endforeach
            @endif

            @if (isset($data['record']->{$altroKey}) && $data['record']->{$altroKey} != '')
                <tr>
                    <td width="100%" align="center" style="padding-bottom: 10px !important;border: none!important">
                        <b>ALTRO:</b>{{ $data['record']->{$altroKey} }}
                    </td>
                </tr>
            @endif
        </table>
    @endif
@endforeach
