@extends('layouts.app')

@section('content')
<?php usort($tableGrid, "SiteHelpers::_sort"); ?>
<div class="page-titles">
  <h2> {{ $pageTitle }} <small> {{ $pageNote }} </small></h2>
</div>
<style>
	.table td, .table th {
		vertical-align: middle;
	}
    .dataTables_length, .dataTables_filter{
        display: block !important;  
    }
</style>

	<div id="updatepetaklamaView"></div>	
	<div id="updatepetaklamaGrid">
		<div class="card">
			<div class="card-body">
			@include( $pageModule.'/toolbar')
		
		
			<div class="table-responsive">			
                <input type="text" class="form-control " id="searchInput" placeholder=" Type and hit enter to search " style="width:300px; float:right; margin-bottom:10px;" />
				<table id="updatepetaklamaTable" class="display table  table-striped table-hover" cellspacing="0" width="100%">
			        <thead>
			            <tr>
			            	<th>ID</th>	
			            	
			            @if($setting['view-method'] =='expand')<th></th>@endif
			           

			            
		            <?php foreach ($tableGrid as $t) :
						if($t['view'] =='1'):
							$limited = isset($t['limited']) ? $t['limited'] :'';
							if(SiteHelpers::filterColumn($limited ))
							{
								echo '<th align="'.$t['align'].'" width="'.$t['width'].'">'.\SiteHelpers::activeLang($t['label'],(isset($t['language'])? $t['language'] : array())).'</th>';				
							} 
						endif;
					endforeach; ?>
							 <th width="30" class="text-right" > Action </th>
						</tr>

					</thead>	
			               
			    </table>
			</div>	 
		</div>			
	</div>	
	</div>
	
</div>

<script type="text/javascript">
var table;
	$(document).ready(function() {
		$('.tips').tooltip();
		$('.dataselect').select2();
		var rows_selected = []; 			
	   	table = $('#updatepetaklamaTable').DataTable( {
	        "processing": true,
	       
	        "serverSide": true,

            "paging": true,    // Enable pagination
            "searching": true, // Enable search box
            "ordering": true,  // Enable sorting
            "info": true,  
	        "lengthMenu": [[10, 25, 50, 1000], [10, 25, 50, 1000]],
	        "ajax": {
	            "url": "{!! url('updatepetaklama')!!}",
	            "type": "POST"
	             
        	},
        	"columnDefs": [{ 
        		"targets": [0],
                "visible": false,
                orderable: false,
            	className: 'select-checkbox'
        	}],
        	"columns": [<?php echo $column;?>],
        	'order': [[1, 'asc']],
        	<?php if($access['is_excel'] ==1 ) { ?>
        	dom: 'Bfltip',
        	buttons: [
            	'copy', 'csv', 'excel', 'pdf', 'print'
        	]
        	<?php } ?>
        	
	    });

	   	<?php if($setting['view-method'] =='expand'): ?>
		$('#updatepetaklamaTable tbody').on('click', 'td.details-control', function () {
	        var tr = $(this).closest('tr');
	        var row = table.row( tr );
	        var id = row.data().rowId;

	        if ( row.child.isShown() ) {
	        	 row.child.hide();
            	tr.removeClass('shown');
	        }
	        else {
	            // Open this row
	            row.child.show();	            
	            row.child( expand_child(id) ).show();
	            tr.addClass('shown');
	            $.get('{{ url("updatepetaklama/")}}/'+id , function(callback){
	            	$('#'+id).html(callback);
	            	$('#'+id).addClass('data');
	            })
		        
	            
	        }
    	});
    	<?php endif; ?>
		$('.dosearch').keyup(function( e ){
			if (e.keyCode === 13) {
				val = $(this).val();
				table.search(val ).draw();
			}
		})  

	    $('#updatepetaklamaTable').Sdtable({
	    	tableId : '#updatepetaklama',
	    	table   : table,
	    	action  : '{{ url("updatepetaklama")}}' 
	    });

	   
	});


    $('#searchInput').on('keyup', function() {
        table.search(this.value).draw();
    });
    function expand_child( id )
    {
    	return '<div id="'+ id+'"><p class="text-center"> Loading Content .. Please wait</p></div>';	
    }

	
function setpetak(petaklama,petakbaru) {
		var dataIdLama = petaklama;
		var dataIdBaru = petakbaru;
		if (!dataIdLama || !dataIdBaru) {
			notyMessageError('Data ID tidak ditemukan');
			return;
		}

		// Tambahkan peringatan sebelum eksekusi
		if (!confirm('Apakah Anda yakin ingin mengubah data petak?')) {
			return;
		}

		$.ajax({
			url: '{{ url("updatepetaklama?action_task=ubahdatapetak") }}',
			type: 'POST',
			data: { idlama: dataIdLama, idbaru: dataIdBaru },
			dataType: 'json',
			success: function(response) {
                if (response.status === 'success') {
                    notyMessage(response.message);
                    var table = $('#updatepetaklamaTable').DataTable();
                    table.ajax.reload(null, false);
				} else {
					notyMessageError(response.message);
				}
			},
			error: function(xhr, status, error) {
				notyMessageError('Terjadi kesalahan saat memproses data');
			}
		});
	};

</script>


@endsection