@extends('layouts.app')

@section('content')
{{--*/ usort($tableGrid, "SiteHelpers::_sort") /*--}}
<div class="page-titles"style="font-family: 'Segoe UI', 'Roboto', 'Arial', sans-serif;">
  <h2 style="font-size: 2.2rem; font-weight: 600;"> {{ $pageTitle }} <small style="font-size: 1.2rem; font-weight: 400;"> {{ $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 dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-bars"></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"> Export CSV </a></li>	
						@endif
				        </ul>
				    </div>	
				</div>    
			</div>
		<div>
		
		{!! Form::open(array('url'=>'cekmasterpetakrayon/delete/', 'class'=>'form-horizontal' ,'id' =>'SximoTable' )) !!}
		 <div class="table-responsive" style="overflow-x:auto; max-height: 500px; overflow-y: auto; min-height:300px;">

		<style>
			/* Modern table styling scoped here */
			.modern-table th{
				position: sticky;
				top: 0;
				z-index: 3;
				background: linear-gradient(180deg,#ffffff,#f7f9fb);
				border-bottom: 1px solid #e9eef3;
				color: #374151;
				font-weight: 600;
				text-transform: none;
				letter-spacing: 0;
			}
			.modern-table td, .modern-table th{
				vertical-align: middle;
				padding: .65rem .9rem;
				border-top: 0;
				font-size: .95rem;
				color: #334155;
			}
			.modern-table tbody tr:hover{
				background: #f1f5f9;
			}
			.modern-table tbody tr:nth-child(odd){
				background: #ffffff;
			}
			.modern-table tbody tr:nth-child(even){
				background: #fbfdff;
			}
			.modern-table .number{
				width: 60px;
				color: #6b7280;
				font-weight: 600;
			}
			.table-card{
				background: #ffffff;
				border-radius: .5rem;
				box-shadow: 0 1px 2px rgba(16,24,40,0.03), 0 1px 3px rgba(16,24,40,0.04);
				padding: .5rem;
			}
			.cell-muted{
				color: #6b7280;
				font-size: .88rem;
			}
			/* Highlight rows/cells that contain TOTAL */
			.total-cell{
				background: #e6f7ff; /* light blue */
				font-weight: 700;
			}
			/* Right align and monospaced/Tabular numbers for decimal columns */
			.text-right{ text-align: right !important; }
			.decimal{ font-variant-numeric: tabular-nums; -moz-font-feature-settings: "tnum"; -webkit-font-feature-settings: "tnum"; }
			@media (max-width: 575px){
				.modern-table th, .modern-table td{ padding: .5rem .6rem; font-size: .88rem; }
			}
		</style>

		<div class="table-card">
		<table class="table modern-table table-hover table-borderless mb-0" style="min-width: 900px;">
			<thead>
				<tr>
					<th class="number"> No </th>
					@foreach ($tableGrid as $t)
						@if($t['view'] =='1')
							<th class="{{ in_array($loop->iteration,[4,5,6]) ? 'text-right decimal' : '' }}">{{ $t['label'] }}</th>
						@endif
					@endforeach
				</tr>
			</thead>

			<tbody>
				@foreach ($rowData as $row)
					@php
						// Build a plain-text representation of the row to detect "TOTAL"
						$rowString = '';
						foreach($tableGrid as $field){
							if(isset($field['view']) && $field['view'] == '1'){
								$rowString .= strip_tags( SiteHelpers::formatRows($row->{$field['field']}, $field, $row) );
							}
						}
						$isTotalRow = (strpos(strtoupper($rowString),'TOTAL') !== false);
					@endphp
					<tr>
						<td class="number {{ $isTotalRow ? 'total-cell' : '' }}"> {{ ++$i }} </td>
						@foreach ($tableGrid as $field)
							 @if($field['view'] =='1')
								<?php $limited = isset($field['limited']) ? $field['limited'] :''; ?>
								@if(SiteHelpers::filterColumn($limited ))
								 <?php $isDecimalCol = in_array($loop->iteration, [4,5,6]); ?>
								 <td class="{{ $isTotalRow ? 'total-cell' : '' }} {{ $isDecimalCol ? 'text-right decimal' : '' }}">
									@if($isDecimalCol)
										@php
											$raw = $row->{$field['field']};
											// if numeric, format to 3 decimal places; otherwise fall back to formatted output
											if (is_numeric($raw)) {
												$display = number_format((float)$raw, 3, '.', ',');
											} else {
												$display = strip_tags(SiteHelpers::formatRows($raw, $field, $row));
											}
										@endphp
										@if($isTotalRow)
											<strong>{!! $display !!}</strong>
										@else
											{!! $display !!}
										@endif
									@else
										@if($isTotalRow)
											<strong>{!! SiteHelpers::formatRows($row->{$field['field']},$field ,$row ) !!}</strong>
										@else
											{!! SiteHelpers::formatRows($row->{$field['field']},$field ,$row ) !!}
										@endif
									@endif
								 </td>
								@endif	
							 @endif					 
						 @endforeach
					</tr>
				@endforeach
			</tbody>
		</table>
		</div>

		<input type="hidden" name="md" value="" />
		</div>
		{!! Form::close() !!}
		
		
		@include('footer')
	</div>  
</div>
@stop