@extends('layouts.layout-user')
@section('content')

<table id="table-register" class="table table-bordered table-hover">
    <thead>
        <tr>
            <th colspan="10">
                <h2 style="display: inline-block; margin-right: 10px;">Data Pelaporan Bahaya</h2>
                <span style="margin:1%; float: right;"></span>
                <form class="w-72" action="{{route('pelaporan.index')}}" method="GET">
                    <div class="input-group input-group-merge" style="max-width: 300px">
                        <span class="input-group-text" id="basic-addon-search31"><i class="fa fa-search"></i></span>
                        <input name="search" class="form-control" placeholder="Search..." aria-label="Search..." aria-describedby="basic-addon-search31"></input>
                    </div>
                </form>
                <a href="{{ route('pelaporan.create') }}" class="btn btn-primary btn-delete" style="float: left; margin-top:1%;">Buat Pelaporan</a>
            </th>
        </tr>
        <tr style="background-color: #155dfa;">
            <th style="vertical-align: middle; color: white; text-align: center; padding: 10px;">No</th>
            <th style="vertical-align: middle; color: white; text-align: center; padding: 10px;">Judul Laporan</th>
            <th style="vertical-align: middle; color: white; text-align: center; padding: 10px;">Keterangan Laporan</th>
            <th style="vertical-align: middle; color: white; text-align: center; padding: 10px;">Tanggal Dibuat</th>
            <th style="vertical-align: middle; color: white; text-align: center; padding: 10px;">Lokasi</th>
            <th style="vertical-align: middle; color: white; text-align: center; padding: 10px;">Tingkat Bahaya</th>
            <th style="vertical-align: middle; color: white; text-align: center; padding: 10px;">Status Tindakan</th>
            <th style="vertical-align: middle; color: white; text-align: center; padding: 10px;">Saran Tindakan</th>
            <th style="vertical-align: middle; color: white; text-align: center; padding: 10px;">Foto</th>
            <th style="vertical-align: middle; text-align: center; color: white; padding: 10px; width: 100px;">Action</th>
        </tr>
    </thead>
    <tbody>
        @php
            $i = 1;
        @endphp
        @if($pelaporan->count() > 0)
            @foreach ($pelaporan as $pelaporan)
            <tr>
                <td style="text-align: center; vertical-align: middle;">{{ $i++ }}</td>
                <td style="text-align: center; vertical-align: middle;">{{$pelaporan->judul}}</td>
                <td style="text-align: center; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 10em;">
                    {{$pelaporan->keterangan}}
                </td>
                <td style="text-align: center; vertical-align: middle;">{{$pelaporan->tanggal}}</td>
                <td style="text-align: center; vertical-align: middle;">{{$pelaporan->lokasi}}</td>
                <td style="text-align: center; vertical-align: middle;">
                    <div style="
                        @if ($pelaporan->status === 'Ringan')
                            background-color: #1593fa;
                            width: 80px;
                            height: 30px;
                            border-radius: 10px;
                            display: flex;
                            justify-content: center;
                            align-items: center;
                            font-weight: bold;
                            color: white;
                        @elseif ($pelaporan->status === 'Sedang')
                            background-color: rgb(156, 196, 54);
                            width: 80px;
                            height: 30px;
                            border-radius: 10px;
                            display: flex;
                            justify-content: center;
                            align-items: center;
                            font-weight: bold;
                            color: white;
                        @elseif ($pelaporan->status === 'Berat')
                            background-color: rgba(219, 71, 71, 0.799);
                            width: 80px;
                            height: 30px;
                            border-radius: 10px;
                            display: flex;
                            justify-content: center;
                            align-items: center;
                            font-weight: bold;
                            color: white;
                        @else
                            background-color: #ffffff;
                        @endif
                    ">
                        • {{ $pelaporan->status }}
                    </div>
                </td>
                <td style="text-align: center; vertical-align: middle;">
                    <div style="
                         @if ($pelaporan->tindakan->statusTindakan === 'Belum ditindak')
                                background-image: linear-gradient(to right, #0867E9, #6BA3F0);
                                width: 150px;
                                height: 30px;
                                border-radius: 10px;
                                display: flex;
                                justify-content: center;
                                align-items: center;
                                font-weight: bold;
                                color: white;
                         @elseif ($pelaporan->tindakan->statusTindakan === 'Diverifikasi')
                                background-image: linear-gradient(to right, #F76D2E, #EEA45D);
                                width: 150px;
                                height: 30px;
                                border-radius: 10px;
                                display: flex;
                                justify-content: center;
                                align-items: center;
                                font-weight: bold;
                                color: white;
                         @elseif ($pelaporan->tindakan->statusTindakan === 'Ditindak lanjuti')
                                background-image: linear-gradient(to right, #F84B67, #F86E85);
                                width: 150px;
                                height: 30px;
                                border-radius: 10px;
                                display: flex;
                                justify-content: center;
                                align-items: center;
                                font-weight: bold;
                                color: white;
                         @elseif ($pelaporan->tindakan->statusTindakan === 'Selesai')
                                background-image: linear-gradient(to right, #08976B, #47D5A7);
                                width: 150px;
                                height: 30px;
                                border-radius: 10px;
                                display: flex;
                                justify-content: center;
                                align-items: center;
                                font-weight: bold;
                                color: white;
                         @endif
                     ">
                         • {{ $pelaporan->tindakan->statusTindakan }}
                     </div>
                </td>
                <td style="text-align: center; vertical-align: middle; max-width: 10em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
                    {{$pelaporan->saran}}
                </td>
                <td style="text-align: center; vertical-align: middle;"><img src="{{ asset('foto/' . $pelaporan->foto) }}" alt="Foto Pelaporan" style="width: 100px; height: 100px; object-fit: cover;"></td>
                <td style="text-align: center; vertical-align: middle; width: 100px;">
                    <div style="display: flex; flex-direction: column; align-items: center;">
                        <a href="{{ route('pelaporan.edit', ['id' => $pelaporan->id]) }}" class="btn btn-delete" style="padding: 8px 16px; background-color: rgb(0, 106, 255); color: #fff; border: none; border-radius: 4px; margin-bottom: 5px;">Update</a>
                        <a href="{{ route('pelaporan.destroy', ['id' => $pelaporan->id]) }}" class="btn btn-delete" style="padding: 8px 16px; background-color: red; color: #fff; border: none; border-radius: 4px;">Delete</a>
                    </div>
                </td>
            </tr>
            @endforeach
        @else
            <tr>
                <td class="text-center" colspan="10">Laporan not found</td>
            </tr>
        @endif
    </tbody>
</table>


@endsection
