<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>Laporan Hasil Perhitungan Bantaran Sungai</title>
    <style>
        * {
            font-family: 'Times New Roman', Times, serif;
        }
        @page {
  size: auto;  /* auto is the initial value */
  margin: 0mm; /* this affects the margin in the printer settings */
}
html {
  margin: 0px; /* this affects the margin on the HTML before sending to printer */
}
body {
  margin: 10mm 15mm 10mm 15mm; /* margin you want for the content */
}
    </style>
  </head>
  <body>
    <table class=" table-hover table-bordered  table tables-responsive" style="width:100% !important" id="table">
      <h6>Nama Device : {{ $nama_device->nama_device }}</h6>
      <h6>Waktu Awal : {{ date("d, F Y",strtotime($awal)) }}</h6>
      <h6>Waktu Akhir :  {{ date("d, F Y",strtotime($akhir)) }}</h6>
      <thead>
        <tr>
            <th>#</th>
            <th class="bor text-center" colspan="4" >Bantaran Sungai</th>
            <th class="bor text-center" colspan="4"  >Hulu Sungai</th>
        </tr>
        <tr>
            <th></th>
            <th class="text-center">Nama</th>
            <th  class="text-center">Kecamatan</th>
            <th  class="text-center">Ketinggian Air</th>
            <th  class="text-center">Status</th>

            {{-- hulu --}}
            <th  class="text-center">Nama</th>
            <th  class="text-center">Ketinggian Air</th>
            <th  class="text-center">Status</th>
            <th  class="text-center">Waktu</th>
        </tr>
    </thead>
      <tbody>
        @foreach ($result  as $row)
        <tr>
          <td>{{ $loop->iteration }}</td>
          <td>{{ $row->pengaturan_bantaran_sungai->bantaran_sungai->nama }}</td>
          <td>{{ $row->pengaturan_bantaran_sungai->bantaran_sungai->kecamatan->nama }}</td>
          <td>{{ $row->ketinggian_air_bantaran_sungai . ' CM' }}</td>
          <td>
            @php
                if ($row) {
                  $tinggi = $row->status_bantaran_sungai;
                  if ($row->status_bantaran_sungai == "Normal") {
                      $namaio = "<span class='badge badge-pill badge-success bg-success'>
                  $tinggi
                  </span>";
                  } elseif ($row->status_bantaran_sungai == "Waspada") {
                      $namaio = "<span class='badge badge-pill badge-warning bg-warning'>
                  $tinggi
                  </span>";
                  } elseif ($row->status_bantaran_sungai == "Meluap") {
                      $namaio = "<span class='badge badge-pill badge-danger bg-danger'>
                  $tinggi
                  </span>";
                  } else {
                      $namaio = "-";
                  }
              } else {
                  $namaio = '-';
              }
              echo $namaio;
            @endphp
          </td>
          <td>{{ $row->pengaturan_bantaran_sungai->bantaran_sungai->device->nama_device }}</td>
          <td>
            {{ $row->ketinggian_air_perangkat . ' CM' }}
          </td>
          <td>
            @php
              if ($row) {
                        $jk = $row->status_perangkat;
                        if ($jk == "Normal") {
                            $span = "<span class='badge badge-pill badge-success bg-success'>
                        $jk
                        </span>";
                        } elseif ($jk == "Siaga 4") {
                            $span = "<span class='badge badge-pill badge-warning bg-warning'>
                        $jk
                        </span>";
                        } elseif ($jk == "Siaga 3") {
                            $span = "<span class='badge badge-pill badge-warning bg-warning'>
                        $jk
                        </span>";
                        } elseif ($jk == "Siaga 2") {
                            $span = "<span class='badge badge-pill badge-warning bg-warning'>
                        $jk
                        </span>";
                        } elseif ($jk == "Siaga 1") {
                            $span = "<span class='badge badge-pill badge-danger bg-danger'>
                        $jk
                        </span>";
                        } else {
                            $span = "";
                        }
                    } else {
                        $span = '-';
                    }
                    echo $span;
            @endphp
          </td>
          <td>
            {{ date("d M Y H:i:s", strtotime($row->datetime_calculate)) }}
          </td>
        </tr>
        @endforeach
      </tbody>
    </table>

    <script>
        window.print();
    </script>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
  </body>
</html>