@extends('layouts.app')
@section('content')

<div class="page-titles">
  <h2> {{ $pageTitle }} <small> {{ $pageNote }} </small></h2>
</div>


	<div id="petaktebangView"></div>	
	<div id="petaktebangGrid">
		<div class="card">
			<div class="card-body">

		
			<div class="table-responsive" id="pjax-container">			
				
			</div>	 
		</div>			
	</div>	
	</div>
	
</div>

<script type="text/javascript">
    loadtable();
   function loadtable(){ 
    $.ajax({
        url: '{{ url("petaktebang/getLuasTertebangByKebun") }}',
        type: 'GET',
        dataType: 'text',
        success: function(response) {
            // Handle the response data here
            console.log(response);
            // Example: display data in #petaktebangView
            $('#pjax-container').html(response);
        },
        error: function(xhr, status, error) {
            console.error('AJAX Error:', error);
        }
    });
    }


    function insertAffTebang(lahan_id) {
        Swal.fire({
            title: 'Input Tanggal AFF',
            html: '<input type="date" id="swal-input-date" class="swal2-input" value="' + new Date().toISOString().split('T')[0] + '">',
            showCancelButton: true,
            confirmButtonText: 'Simpan',
            cancelButtonText: 'Batal',
            preConfirm: () => {
                const tanggal = document.getElementById('swal-input-date').value;
                if (!tanggal) {
                    Swal.showValidationMessage('Tanggal harus diisi');
                    return false;
                }
                return tanggal;
            }
        }).then((result) => {

            if (result.value) {
                $.ajax({
                    url: '{{ url("petaktebang/insertAffTebang") }}',
                    type: 'GET',
                    data: {
                        lahan_id: lahan_id,
                        tanggal_aff: result.value
                    },
                    dataType: 'json',
                    success: function(response) {
                        if (response.status === 'success') {
                            notyMessage(response.message);
                            loadtable();
                        } else {
                            notyMessageError(response.message);
                        }
                    },
                    error: function(xhr, status, error) {
                        console.error('Insert AJAX Error:', error);
                    }
                });
            }
        });
    }
</script>


@endsection