<div class="table-responsive">
    <table id="PekZoznamPoctuKontrolPodlaStavuDataTable" class="table table-hover" style="width:100%">
      <thead class="bg-secondary">
      <tr>
        <th class="text-left">Stav kontroly</th>
        <th class="text-center">Počet</th>
      </tr>
      </thead>
      <tbody></tbody>
      <tfoot>
      <tr>
        <th class="text-left">Spolu</th>
        <th class="text-center"></th>
      </tr>
      </tfoot>
    </table>
</div>

@push('scripts')
    <script type="text/javascript">
      $(document).ready(function () {
        $('#PekZoznamPoctuKontrolPodlaStavuDataTable').DataTable({
          dom: '<"wrapper"<"row"<"col"B><"col"f>><t>>',
          language: {
            url: 'https://cdn.datatables.net/plug-ins/1.10.24/i18n/Slovak.json',
          },
          data: @json($PekZoznamPoctuKontrolPodlaStavuDataTableComposer),
          info: false,
          paging: false,
          searching: true,
          buttons: [
            {
              extend: 'print',
              text: 'Tlačiť',
              title: 'Počet kontrol podľa stavu za obdobie od {{ $datumOd }} do {{ $datumDo }}',
              footer: true,
            },
            {
              extend: 'pdfHtml5',
              orientation: 'landscape',
              pageSize: 'A4',
              title: 'Počet kontrol podľa stavu za obdobie od {{ $datumOd }} do {{ $datumDo }}',
              footer: true,
              filename: 'pek_pocet_kontrol_podla_stavu_{{ $datumOd }}_{{ $datumDo }}',
            },
            {
              extend: 'excelHtml5',
              footer: false,
              filename: 'tek_pocet_kontrol_podla_stavu_{{ $datumOd }}_{{ $datumDo }}',
              sheetName: 'zoznam',
            },
          ],
          columns: [
            {
              title: 'Stav kontroly',
              data: 'label',
              class: 'text-left',
            },
            {
              data: 'data.pocet',
              class: 'text-center',
            },
          ],
          footerCallback: function (row, data, start, end, display) {
            const total = {
              pocet: this.api().column(1, {page: 'current'}).data().reduce(function (a, b) {
                return a + b
              }, 0),
            }

            $(this.api().column(1).footer()).html(total.pocet)
          },
        })
      })
    </script>
@endpush