<?php include '../src/session_check.php'; ?>

<html lang="en" data-bs-theme="light">
<head>
	<!-- Required meta tags -->
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!--favicon-->
	<link rel="icon" href="../assets/images/favicon-32x32.png" type="image/png">
	<!--plugins-->
	<link href="../assets/plugins/vectormap/jquery-jvectormap-2.0.2.css" rel="stylesheet">
	<link href="../assets/plugins/simplebar/css/simplebar.css" rel="stylesheet">
	<link href="../assets/plugins/perfect-scrollbar/css/perfect-scrollbar.css" rel="stylesheet">
	<link href="../assets/plugins/metismenu/css/metisMenu.min.css" rel="stylesheet">
	<!-- loader-->
	<link href="../assets/css/pace.min.css" rel="stylesheet"/>    
	<script src="../assets/js/pace.min.js"></script>
	<!-- Bootstrap CSS -->
	<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
	<link href="../assets/css/bootstrap-extended.css" rel="stylesheet">
	<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
	
	<link href="../assets/sass/app.css" rel="stylesheet">
	<link href="../assets/css/icons.css" rel="stylesheet">
	<link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
	<!-- Theme Style CSS -->
	<link rel="stylesheet" href="../assets/sass/dark-theme.css">
	<link rel="stylesheet" href="../assets/sass/semi-dark.css">
	<link rel="stylesheet" href="../assets/sass/bordered-theme.css">
	
	<title>TOD Dashboard</title>
</head>

<body>
	<!--wrapper-->
	<div class="wrapper">
		<!--sidebar wrapper -->
		<?php include '../src/nav.php'; ?>
		<!--end sidebar wrapper -->
		<!--start header -->
		<?php include '../src/header.php'; ?>
		<!--end header -->

		<!--start page wrapper -->
		<div class="page-wrapper">
			<div class="page-content">
		<!--start page content -->		

					<!--breadcrumb-->
					<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
					<div class="breadcrumb-title pe-3">User Settings</div>
					<div class="ps-3">
						<nav aria-label="breadcrumb">
							<ol class="breadcrumb mb-0 p-0">
								<li class="breadcrumb-item"><a href="index.php"><i class="bx bx-home-alt"></i></a>
								</li>
								<li class="breadcrumb-item active" aria-current="page">Add Printer</li>
							</ol>
						</nav>
					</div>
				</div>
				<!--end breadcrumb-->

				<div class="row">
    <div class="col-lg-8 mx-auto">
        <div class="card">
            <div class="card-header px-4 py-3">
                <h5 class="mb-0">Add New Printer</h5>
            </div>
            <div class="card-body p-4">
                <!-- Alert Banner (Hidden Initially) -->
                <div id="alertBanner" class="alert d-none" role="alert"></div>

                <form id="printerForm">
                    <div class="row mb-3">
                        <label for="printerName" class="col-sm-3 col-form-label">Printer Name</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="printerName" name="printerName" placeholder="Bambu X1 or P1P" required>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <label for="printerIp" class="col-sm-3 col-form-label">Printer IP</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="printerIp" name="printerIp" placeholder="e.g., 192.168.1.100" required>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <label for="serialNumber" class="col-sm-3 col-form-label">Serial Number</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="serialNumber" name="serialNumber" placeholder="e.g., X1SN123456" required>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <label for="accessCode" class="col-sm-3 col-form-label">Printer Access Code</label>
                        <div class="col-sm-9">
                            <input type="password" class="form-control" id="accessCode" name="accessCode" placeholder="Enter Printer Access Code" required>
                        </div>
                    </div>

                    <div class="row">
                        <label class="col-sm-3 col-form-label"></label>
                        <div class="col-sm-9">
                            <div class="d-md-flex d-grid align-items-center gap-3">
                                <button type="submit" class="btn btn-primary px-4">Add Printer</button>
                                <button type="reset" class="btn btn-light px-4">Reset</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- jQuery & AJAX Script -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
    $('#printerForm').on('submit', function(event) {
        event.preventDefault();  // Prevent traditional form submission

        // Collect form data
        let formData = $(this).serialize();

        // AJAX request to submit form
        $.ajax({
            type: 'POST',
            url: '../src/printers/addPrinter.php',
            data: formData,
            dataType: 'json',
            success: function(response) {
                let banner = $('#alertBanner');
                if (response.status === 'success') {
                    banner.removeClass('d-none alert-danger')
                          .addClass('alert-success')
                          .text(response.message);
                } else {
                    banner.removeClass('d-none alert-success')
                          .addClass('alert-danger')
                          .text(response.message);
                }
            },
            error: function() {
                $('#alertBanner').removeClass('d-none alert-success')
                                 .addClass('alert-danger')
                                 .text('An error occurred while adding the printer.');
            }
        });
    });
});
</script>


			

		<!--end page content -->
			</div>
		</div>
		<!--end page wrapper -->

		<!--start overlay-->
		 <div class="overlay mobile-toggle-icon"></div>
		<!--end overlay-->
		<!--Start Back To Top Button-->
		  <a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
		<!--End Back To Top Button-->
		<footer class="page-footer">
			<p class="mb-0">Copyright © 2024. All right reserved.</p>
		</footer>
	</div>
	<!--end wrapper-->


	<!-- search modal -->
    <div class="modal" id="SearchModal" tabindex="-1">
		<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-fullscreen-md-down">
		  <div class="modal-content">
			<div class="modal-header gap-2">
			  <div class="position-relative popup-search w-100">
				<input class="form-control form-control-lg ps-5 border border-3 border-primary" type="search" placeholder="Search">
				<span class="position-absolute top-50 search-show ms-3 translate-middle-y start-0 top-50 fs-4"><i class='bx bx-search'></i></span>
			  </div>
			  <button type="button" class="btn-close d-md-none" data-bs-dismiss="modal" aria-label="Close"></button>
			</div>
		  </div>
		</div>
	  </div>
    <!-- end search modal -->

	<!-- Bootstrap JS -->
	<script src="../assets/js/bootstrap.bundle.min.js"></script>
	<!--plugins-->
	<script src="../assets/js/jquery.min.js"></script>
	<script src="../assets/plugins/simplebar/js/simplebar.min.js"></script>
	<script src="../assets/plugins/metismenu/js/metisMenu.min.js"></script>
	<script src="../assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
	<script src="../assets/plugins/apexcharts-bundle/js/apexcharts.min.js"></script>
	<!--app JS-->
	<script src="../assets/js/app.js"></script>

	<script src="../assets/js/index.js"></script>
	<script src="../assets/plugins/peity/jquery.peity.min.js"></script>
    <script>
       $(".data-attributes span").peity("donut")
    </script>
</body>

</html>