@extends('layouts.app')

@section('content')
<?php usort($tableGrid, "SiteHelpers::_sort"); ?>
<style>
	.table>tbody>tr>td {
		/* background: #f2f2f2; */
		border-bottom: 1px solid #d2cdcd;
	    padding: 13px 0px;
	}
	.table td{
		padding: 0px 9px;
	}
	</style>
<div class="page-titles">
  <h2> {{ $pageTitle }} <small> {{ $pageNote }} </small></h2>
</div>


	<div id="pipicaView"></div>	
	<div id="pipicaGrid">
		<div class="card border-0 shadow-sm">
			<div class="card-body p-4">
			@include( $pageModule.'/toolbar')
		
		
			<div class="table-responsive">			
				<table id="pipicaTable" class="display table table-sm  table-hover" cellspacing="0" width="100%">
					<thead class="table-light">
						<tr class="align-middle">
							<th class="fw-bold text-uppercase small" style="width:40px">
								<div class="form-check">
									<input class="form-check-input" type="checkbox" id="select_all_rows">
								</div>
							</th>
                
						@if($setting['view-method'] =='expand')<th class="w-1"></th>@endif

						<?php foreach ($tableGrid as $t) :
							if($t['view'] =='1'):
								$limited = isset($t['limited']) ? $t['limited'] :'';
								if(SiteHelpers::filterColumn($limited ))
								{
									echo '<th class="fw-bold text-uppercase small" align="'.$t['align'].'" width="'.$t['width'].'">'.\SiteHelpers::activeLang($t['label'],(isset($t['language'])? $t['language'] : array())).'</th>';                
								} 
							endif;
						endforeach; ?>
									 <th width="80" class="text-end fw-bold text-uppercase small">Actions</th>
								</tr>

							</thead>
			               
			    </table>
			</div>	 
		</div>			
	</div>	
	</div>
	
</div>

<script type="text/javascript">
	var table;
	$(document).ready(function() {

		$("#filter_afdeling").jCombo("{!! url('dataprodisconsole/comboselect?filter=master_afd:kode_afd:nama_asman|kode_afd') !!}",
				{  initial_text : 'Pilih Afdeling'});
		$("#filter_afdeling").select2({ width:"100%"});
			
		$('.tips').tooltip();
		$('.dataselect').select2();
		var rows_selected = []; 			
	   	table = $('#pipicaTable').DataTable( {
	        "processing": true,
	       
	        "serverSide": true,
	        // "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
	        "ajax": {
	            "url": "{!! url('pipica')!!}",
	            "type": "POST",
				"data": function ( d ) {
					d.afdeling = $('#filter_afdeling').val();
				}
	             
        	},
        	"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'): ?>
		$('#pipicaTable 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("pipica/")}}/'+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();
			}
		})  

	    $('#pipicaTable').Sdtable({
	    	tableId : '#pipica',
	    	table   : table,
	    	action  : '{{ url("pipica")}}' 
	    });

	   
	});

	$("#filter_afdeling").change(function() {
		table.ajax.reload();
	});


    function expand_child( id )
    {
    	return '<div id="'+ id+'"><p class="text-center"> Loading Content .. Please wait</p></div>';	
    }

</script>


@endsection