<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title>TPC | Portal</title>
    <meta content="" name="description">
    <meta content="" name="keywords">

    <link href="assets/img/favicon.png" rel="icon">
    <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">


    <link href="https://fonts.gstatic.com" rel="preconnect">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

    <link href="<?= base_url(); ?>assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="<?= base_url(); ?>assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">

    <link href="<?= base_url(); ?>assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
    <link href="<?= base_url(); ?>assets/vendor/quill/quill.snow.css" rel="stylesheet">
    <link href="<?= base_url(); ?>assets/vendor/quill/quill.bubble.css" rel="stylesheet">
    <link href="<?= base_url(); ?>assets/vendor/remixicon/remixicon.css" rel="stylesheet">
    <link href="<?= base_url(); ?>assets/vendor/simple-datatables/style.css" rel="stylesheet">
    <link href="<?= base_url(); ?>assets/css/style.css" rel="stylesheet">
    <link href="<?= base_url(); ?>assets/css/sweetalert.css" rel="stylesheet">
    <link href="<?= base_url(); ?>assets/css/sweetalert2.min.css" rel="stylesheet">
</head>

<body>

    <main>
        <div class="container">

            <section class="section register min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
                <div class="container">
                    <div class="row justify-content-center">
                        <div class="col-lg-4 col-md-6 d-flex flex-column align-items-center justify-content-center">



                            <div class="card mb-3">

                                <div class="card-body">

                                    <div class="pt-4 pb-2">
                                        <h5 class="card-title text-center pb-0 fs-4"><i class="bi bi-printer"></i>&nbsp;OPEN PRINT</h5>
                                    </div>

                                    <div class="row g-3 needs-validation" novalidate>

                                        <div class="col-12">
                                            <label for="yourPassword" class="form-label">Please enter your ID</label>
                                            <input type="text" name="print_id" class="form-control" id="yourID">
                                            <div class="invalid-feedback">Please enter your ID</div>
                                        </div>
                                        <div class="col-12">
                                            <button class="btn btn-primary w-100" type="button" onclick="buka()"><i class="bi bi-shield-lock"></i>&nbsp;Open</button>
                                        </div>
                                    </div>

                                </div>
                            </div>

                            <div class="credits">
                                Supported by IT TPC
                            </div>

                        </div>
                    </div>
                </div>

            </section>

        </div>
    </main><!-- End #main -->

    <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>

    <!-- Vendor JS Files -->
    <script src="<?= base_url(); ?>assets/js/jquery-3.5.1.js"></script>
    <script src="assets/vendor/apexcharts/apexcharts.min.js"></script>
    <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="assets/vendor/chart.js/chart.umd.js"></script>
    <script src="assets/vendor/echarts/echarts.min.js"></script>
    <script src="assets/vendor/quill/quill.js"></script>
    <script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
    <script src="assets/vendor/tinymce/tinymce.min.js"></script>
    <script src="assets/vendor/php-email-form/validate.js"></script>

    <!-- Template Main JS File -->
    <script src="<?= base_url(); ?>assets/js/main.js"></script>

    <script src="<?= base_url(); ?>assets/js/sweetalert2.min.js"></script>
    <link href="<?= base_url(); ?>vendor/select2/select2.min.css" rel="stylesheet" />
    <script src="<?= base_url(); ?>vendor/select2/select2.min.js"></script>

</body>

</html>

<script>
    function buka() {
        var id = $("#yourID").val();
        $.ajax({
            url: "<?= base_url('Produksi/cari_id_print'); ?>",
            type: 'POST',
            cache: false,
            data: {
                id: id
            },
            success: function(data) {
                if (data == 0) {
                    msg('ID Print tidak ditemukan', 'error');
                    document.getElementById('yourID').value = "";
                }

                if (data == 1) {
                    $.ajax({
                        url: "<?= base_url('Produksi/allow_print_barcode'); ?>",
                        type: 'POST',
                        cache: false,
                        data: {
                            id: id
                        },
                        success: function() {
                            msg('ID Print Telah dibuka', 'success');
                            document.getElementById('yourID').value = "";
                        }
                    });
                }
            }
        });
    }

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

<script>
    document.addEventListener('DOMContentLoaded', function() {
        var searchInput = document.getElementById('yourID');

        searchInput.addEventListener('keyup', function(event) {
            if (event.keyCode === 13) { // 13 adalah kode key untuk Enter                
                buka();
            }
        });
    });
</script>