@extends('layouts.app')

@section('content')
{{--*/ usort($tableGrid, "SiteHelpers::_sort") /*--}}
<div class="page-titles">
<h2 style="font-size: 1.5rem; font-weight: bold; color: #007bff;">
	{{ $pageTitle }} 
	<small style="font-size: 1rem; font-weight: bold; color: #3399ff;">
		{{ $pageNote }}
	</small>
</h2>
</div>
<div  class="card">
	<div class="card-body">
		<div class="toolbar-nav">
			<div class="row">
				<div class="col-md-6">
					<div class="btn-group">
						<button type="button" class="btn btn-primary dropdown-toggle shadow-sm px-4 py-2 d-flex align-items-center gap-2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="background: linear-gradient(90deg, #007bff 0%, #00c6ff 100%); border: none; border-radius: 30px; font-weight: 600;">
							<i class="fa fa-tasks me-2"></i> Bulk Action
						</button>
				        <ul class="dropdown-menu">
						 @if($access['is_excel'] == 1)
							<li class="nav-item">
								<a href="{{ url($pageModule . '/export?do=excel&return=' . $return) }}" class="nav-link text-success" style="font-weight: bold; font-size: 1.05em;">
									<i class="fa fa-file-excel-o" style="color:#28a745;"></i> Export CSV
								</a>
							</li>
						@endif
				        </ul>
				    </div>	
				</div> 
				
				<div class="col-md-6 text-right">
				{!! Form::open(['method' => 'GET', 'url' => request()->url(), 'class' => 'form-inline', 'style' => 'display:inline-block;']) !!}
					<div class="form-group">
						<label for="filter_rayon" class="mr-2">Filter Rayon:</label>
						<select name="filter_rayon" id="filter_rayon" class="form-sm-control mr-2">
						</select>
						<button type="submit" class="btn btn-primary btn-sm">Filter</button>
					</div>
				{!! Form::close() !!}
				</div>


			</div>
		<div class="table-responsive" style="position:relative;">
			<style>
				.table-responsive {
					overflow-y: auto;
					max-height: 600px;
					position: relative;
				}
				.table thead th {
					position: sticky;
					top: 0;
					background: #fff;
					z-index: 2;
				}
				/* Freeze columns up to "id Lahan" (kolom ke-7) */
				.table th.freeze-col,
				.table td.freeze-col {
					position: sticky;
					background: #fff;
					z-index: 3;
				}
				.table th.freeze-col-1, .table td.freeze-col-1 { left: 0; z-index: 4; }
				.table th.freeze-col-2, .table td.freeze-col-2 { left: 60px; z-index: 4; }
				.table th.freeze-col-3, .table td.freeze-col-3 { left: 120px; z-index: 4; }
				.table th.freeze-col-4, .table td.freeze-col-4 { left: 180px; z-index: 4; }
				.table th.freeze-col-5, .table td.freeze-col-5 { left: 240px; z-index: 4; }
				.table th.freeze-col-6, .table td.freeze-col-6 { left: 300px; z-index: 4; }
				.table th.freeze-col-7, .table td.freeze-col-7 { left: 360px; z-index: 4; }
			</style>
			{!! Form::open(['url' => 'monitoringlkpumur/delete/', 'class' => 'form-horizontal', 'id' => 'SximoTable']) !!}
			<table class="table table-hover table-striped table-bordered align-middle shadow-sm" style="min-width: 600px;">
				<thead class="thead-dark bg-primary text-white">
					<tr>
						<th class="number text-center">No</th>
						@foreach ($tableGrid as $t)
							@if($t['view'] == '1')
								<th class="text-center">{{ $t['label'] }}</th>
							@endif
						@endforeach
					</tr>
				</thead>
				<tbody>
					@foreach ($rowData as $row)
						<tr>
							<td class="text-center fw-bold" width="30">{{ ++$i }}</td>
							@php $colIndex = 1; @endphp
							@foreach ($tableGrid as $field)
								@if($field['view'] == '1')
									<?php 
										$limited = isset($field['limited']) ? $field['limited'] : ''; 
										$value = SiteHelpers::formatRows($row->{$field['field']}, $field, $row);
										$containsSaatnya = stripos(strip_tags($value), 'SAATNYA') !== false;
										$containsTerlambat = stripos(strip_tags($value), 'TERLAMBAT') !== false;
										$containsBelum = stripos(strip_tags($value), 'BELUM SAATNYA DIKERJAKAN') !== false;
										$cellStyle = '';
										if ($containsSaatnya) {
											$cellStyle = 'background: #ffe066; color: #d35400; font-weight: bold;';
										}
										if ($containsTerlambat) {
											$cellStyle = 'background: #ff3860; color: #fff; font-weight: bold;';
										}
										if ($containsBelum) {
											$cellStyle = 'background: #e0e0e0; color: #222; font-weight: bold;';
										}
										// Format decimal 3 angka untuk kolom 12-23, jika 0 tampilkan '-'
										$displayValue = $value;
										if ($colIndex >= 12 && $colIndex <= 23 && is_numeric(strip_tags($value))) {
											$numValue = (float)strip_tags($value);
											$displayValue = ($numValue == 0) ? '-' : number_format($numValue, 3);
										}
									?>
									@if(SiteHelpers::filterColumn($limited))
										<td @if($cellStyle) style="{{ $cellStyle }}" @endif>
											{!! $displayValue !!}
										</td>
									@endif
									@php $colIndex++; @endphp
								@endif
							@endforeach
						</tr>
					@endforeach
				</tbody>
			</table>
			<input type="hidden" name="md" value="" />
			{!! Form::close() !!}
		</div>
		<style>
			.table thead th {
				vertical-align: middle;
				background: linear-gradient(90deg, #007bff 0%, #0056b3 100%);
				color: #fff;
				border-bottom: 2px solid #dee2e6;
			}
			.table-striped tbody tr:nth-of-type(odd) {
				background-color: #f8f9fa;
			}
			.table-striped tbody tr:nth-of-type(even) {
				background-color: #e9ecef;
			}
			.table-hover tbody tr:hover {
				background-color: #d1ecf1;
				transition: background 0.2s;
			}
			@media (max-width: 768px) {
				.table-responsive {
					font-size: 0.95rem;
				}
				.table th, .table td {
					white-space: nowrap;
				}
			}
		</style>
		
		
		@include('footer')
	</div>  
</div>

<script>
	$("#filter_rayon").jCombo("{!! url('dataprodisconsole/comboselect?filter=master_rayon:kode_rayon:nama_rayon') !!}", {
		initial_text: 'Pilih Rayon'
	});
</script>

@stop