<main id="main" class="main">
    <div class="pagetitle">
        <h1>Selamat Datang <?= $this->session->strNama; ?></h1>
        <nav>
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                <li class="breadcrumb-item active">Pengiriman</li>
            </ol>
        </nav>
    </div>

    <section class="section dashboard">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                    <br>
                    <button onclick="tampildata()" type="button" id="btnview" class="btn btn-primary btn-sm" type="button"><i class="bi bi-arrow-clockwise"></i>&nbsp;Reload</button>
                    <button type="button" style="display:none;float:left;margin: 2px;" id="btnloading" class="btn btn-primary" type="button" disabled="">
                        <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
                        Loading...
                    </button>
                </div>
            </div>
        </div>
        <div class="row">
            <div id="tb_fc"></div>
        </div>
    </section>
</main>

<div class="modal fade" id="f_lot" tabindex="-1" style="display: none;" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Detail LOT</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <input type="hidden" id="doc_id">
                <input type="hidden" id="blc">
                <div class="row mb-1">
                    <label class="col-sm-2 col-form-label">No.ITO</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control form-control-sm" id="docno">
                    </div>
                    <label class="col-sm-2 col-form-label">Qty : </label>
                    <div class="col-sm-3">
                        <input type="number" class="form-control form-control-sm" id="qty" placeholder="0">
                    </div>
                    <label class="col-sm-2 col-form-label">Status : </label>
                    <div class="col-sm-5">
                        <select class="form-control form-control-sm" id="sts_kirim">
                            <option value="1">Kirim</option>
                            <option value="2">Void</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                <button type="button" class="btn btn-primary" onclick="kirim_fg()">Simpan</button>
            </div>
        </div>
    </div>
</div>

<!-- Toast -->
<div class="toast-container position-fixed top-0 end-0 p-3">
    <div id="liveToast" class="toast fade" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="toast-header">
            <strong class="me-auto"><i class="bi bi-envelope"></i>&nbsp;Pesan</strong>
            <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
        <div class="toast-body">
            Jumlah kirim terlalu banyak
        </div>
    </div>
</div>
</div>



<script>
    function ubah(pilihan) {
        if (pilihan == 1) {
            $("#pilihan_kirim").html("<input type='text' class='form-control form-control-sm' name='nama_customer' name='nama_customer'>");
        }


        if (pilihan == 2) {
            $.ajax({
                url: '<?= base_url("Sub_gpc/get_gudang"); ?>',
                type: 'GET',
                success: function(response) {
                    $("#pilihan_kirim").html(response);
                },
                error: function() {
                    alert("Terjadi kesalahan saat memuat data gudang.");
                }
            });
        }
    }

    function ubah_kendaraan(pilihan) {
        if (pilihan == 2) {
            $("#pilihan_kendaraan").html("<input type='text' class='form-control form-control-sm' name='no_pol' name='no_pol'>");
            $("#pilihan_sopir").html("<input type='text' class='form-control form-control-sm' name='nama_sopir' name='nama_sopir'>");
        }

        if (pilihan == 1) {
            $.ajax({
                url: '<?= base_url("Sub_gpc/get_kendaraan"); ?>',
                type: 'GET',
                success: function(response) {
                    $("#pilihan_kendaraan").html(response);
                },
                error: function() {
                    alert("Terjadi kesalahan saat memuat data gudang.");
                }
            });

            $.ajax({
                url: '<?= base_url("Sub_gpc/get_sopir"); ?>',
                type: 'GET',
                success: function(response) {
                    $("#pilihan_sopir").html(response);
                },
                error: function() {
                    alert("Terjadi kesalahan saat memuat data gudang.");
                }
            });
        }
    }

    function tampildata() {
        document.getElementById("btnloading").style.display = "block";
        document.getElementById("btnview").style.display = "none";
        $.get("<?= base_url('sub_gpc/tb_pengiriman'); ?>", function(data, status) {
            $("#tb_fc").html(data);
            document.getElementById("btnloading").style.display = "none";
            document.getElementById("btnview").style.display = "block";
        });
    }

    function pesan(txt, tipe) {
        const Toast = Swal.mixin({
            toast: true,
            position: "top-end",
            showConfirmButton: false,
            timer: 2000,
            timerProgressBar: true,
            didOpen: (toast) => {
                toast.onmouseenter = Swal.stopTimer;
                toast.onmouseleave = Swal.resumeTimer;
            }
        });
        Toast.fire({
            icon: tipe,
            title: txt
        });
    }
</script>



<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    $(document).ready(function() {
        //tampildata();        
    });
</script>


<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script>
    function pesan_error() {
        var toastElement = new bootstrap.Toast(document.getElementById('liveToast'));
        var showToastBtn = document.getElementById('showToastBtn');
        showToastBtn.addEventListener('click', function() {
            toastElement.show();
        });
    }
</script>