<!DOCTYPE html>
<html lang="fa">
<head>
    <meta charset="UTF-8">
    <title>کشوری</title>
</head>
<body dir="rtl" style="text-align:center;">

@php
    // show a dot if key missing or value is 0/empty
    function cell($row, $key) {
        return array_key_exists($key, $row) ? ($row[$key] ?: '0') : '0';
    }
@endphp

<table>
    <thead>
    <tr>
        <th colspan="{{ 2 + (count($axisOrder) * 3) }}"
            style="background-color:#DAEEF3;text-align:center;border-right:1px solid black;font-weight:bolder;">
            تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
        </th>
    </tr>
    <tr>
        <th colspan="{{ 2 + (count($axisOrder) * 3) }}"
            style="background-color:#DAEEF3;text-align:center;border-right:1px solid black;font-weight:bolder;font-size:13px;">
            گزارش نگهداری حریم راه برای راه دسترسی غیر مجاز
        </th>
    </tr>

    <tr class="headercolortable">
        <th rowspan="2" style="border:1px solid black;text-align:center;background-color:#C4D79B;">
            اداره کل
        </th>
        <th rowspan="2" style="border:1px solid black;text-align:center;background-color:#EBF1DE;">
            تعداد کل
        </th>
        @foreach($axisOrder as $aid)
            <th colspan="3" style="border:1px solid black;text-align:center;background-color:#EBF1DE;">
                {{ $axis[$aid] }}
            </th>
        @endforeach
    </tr>
    <tr>
        @foreach($axisOrder as $aid)
            <th style="border:1px solid black;text-align:center;background-color:#EBF1DE;">گام اول (شناسایی)</th>
            <th style="border:1px solid black;text-align:center;background-color:#EBF1DE;">گام دوم (مستندات قضایی)</th>
            <th style="border:1px solid black;text-align:center;background-color:#EBF1DE;">گام سوم (برخورد)</th>
        @endforeach
    </tr>
    </thead>

    <tbody>
    @foreach ($rows as $r)
        <tr>
            <td style="border:1px solid black;text-align:center;">{{ $r['province_name'] }}</td>
            <td style="border:1px solid black;text-align:center;">{{ $r['total'] ?: '0' }}</td>

            @foreach ($axisOrder as $aid)
                @php $group = $axis[$aid]; @endphp
                <td style="border:1px solid black;text-align:center;">{{ cell($r, "{$group}_1") }}</td>
                <td style="border:1px solid black;text-align:center;">{{ cell($r, "{$group}_2") }}</td>
                <td style="border:1px solid black;text-align:center;">{{ cell($r, "{$group}_3") }}</td>
            @endforeach
        </tr>
    @endforeach
    </tbody>
</table>

</body>
</html>
