<?php echo view('admin/includes/head');?>
<body>
	<div id="global-loader">
		<div class="whirly-loader"> </div>
	</div>
	<!-- Main Wrapper -->
	<div class="main-wrapper">

		<!-- Header -->
<?php echo view('admin/includes/header');?>
		<!-- /Header -->

		<!-- Sidebar -->
<?php echo view('admin/includes/sidebarmenulogo');?>
		<!-- /Sidebar -->


			<!-- /Two Col Sidebar -->

			<div class="page-wrapper">
				<div class="content">
					<div class="page-header">
						<div class="add-item d-flex">
							<div class="page-title">
								<h4 class="fw-bold">Units</h4>
								<h6>Manage your Units</h6>
							</div>
						</div>
						<ul class="table-top-head">
						
							<li>
								<a data-bs-toggle="tooltip" data-bs-placement="top" title="Refresh"><i class="ti ti-refresh"></i></a>
							</li>
							<li>
								<a data-bs-toggle="tooltip" data-bs-placement="top" title="Collapse" id="collapse-header"><i class="ti ti-chevron-up"></i></a>
							</li>
						</ul>
						<div class="page-btn">
							<a href="#" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#add-category"><i class="ti ti-circle-plus me-1"></i>Add Unit</a>
						</div>
					</div>
					<!-- /product list -->
					<?php 
					if(session()->getFlashdata('success')): ?>
				   <div class="alert alert-success d-flex align-items-center" role="alert">
                                        <i class="feather-check-circle flex-shrink-0 me-2"></i>
                                        <div>
	<?= session()->getFlashdata('success') ?>
					
					
				 </div>
                                    </div>
<?php endif; ?>

 
                                          
					<div class="card">
						<div class="card-header d-flex align-items-center justify-content-between flex-wrap row-gap-3">
							<div class="search-set">
								<div class="search-input">
									<span class="btn-searchset"><i class="ti ti-search fs-14 feather-search"></i></span>
								</div>
							</div>
							<div class="d-flex table-dropdown my-xl-auto right-content align-items-center flex-wrap row-gap-3">
								<div class="dropdown">
								<a href="javascript:void(0);"
   class="btn btn-white btn-md d-inline-flex align-items-center"
   data-bs-toggle="dropdown">
    Status
    <i data-feather="chevron-down" class="ms-2"></i>
</a>
									<ul class="dropdown-menu  dropdown-menu-end p-3">
										<li>
											<a href="javascript:void(0);" class="dropdown-item rounded-1">Active</a>
										</li>
										<li>
											<a href="javascript:void(0);" class="dropdown-item rounded-1">Inactive</a>
										</li>
									</ul>
								</div>
							</div>
						</div>
						
						<div class="card-body p-0">
							<div class="table-responsive">
								<table class="table datatable">
									<thead class="thead-light">
										<tr>
												<th>Unit Name</th>
												<th>Short Name</th>
												<th>Product Count</th>
												<th>Created On</th>
												<th>Status</th>
												<th></th>
										</tr>
									</thead>
									<tbody>
									
									     <?php if(!empty($units)): ?>
                <?php foreach($units as $uni): ?>
										<tr>
										
											<td><span class="text-gray-9"><?= esc($uni['unit_name']) ?></span></td>
											<td><?= esc($uni['unit_short_name']) ?></td>
											<td>2</td>
											<td><?= esc($uni['unit_created_at']) ?></td>
												<td>
											   
											     <?php if($uni['unit_status']=='Active'){ ?>
											    <span class="badge bg-success fw-medium fs-10">Active</span>
											     <?php }
											     else{
											     ?>
											     <span class="badge bg-danger fw-medium fs-10">Inactive</span>
											     <?php } ?>
											    </td>
											    	  
											<td>
												<div class="edit-delete-action">
													<a class="me-2 p-2" href="#" data-bs-toggle="modal" data-bs-target="#edit-category<?= $uni['unit_id']?>">
														<i data-feather="edit" class="feather-edit"></i>
													</a>
												</div>
												
											</td>
										
										</tr>
										<!-- Edit Category -->
		<div class="modal fade" id="edit-category<?= $uni['unit_id']?>">
			<div class="modal-dialog modal-dialog-centered">
				<div class="modal-content">
					<div class="modal-header">
						<div class="page-title">
							<h4>Edit Category <?= $uni['unit_name']?></h4>
						</div>
						<button type="button" class="close bg-danger text-white fs-16" data-bs-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
					</div>
				<form action="<?=base_url('updatunit')?>" method="post" class="add-product-form">
						<div class="modal-body">
						    	<div class="mb-3">
								<label class="form-label">Unit id<span class="text-danger ms-1">*</span></label>
								<input type="hidden" class="form-control" name="unit_id" value="<?= $uni['unit_id']?>">
							</div>
							<div class="mb-3">
								<label class="form-label">Unit Name<span class="text-danger ms-1">*</span></label>
								<input type="text" class="form-control" name="unit_name" value="<?= $uni['unit_name']?>" required>
							</div>
							<div class="mb-3">
								<label class="form-label">Unit Short Name<span class="text-danger ms-1">*</span></label>
								<input type="text" class="form-control" name="unit_short_name" value="<?= $uni['unit_short_name']?>" required>
							</div>
						  <div class="mb-3">
                        <label class="form-label">Status</label>
                        <select name="unit_status" class="form-control">
                            <option value="Active" <?= ($uni['unit_status'] ?? '') === 'Active' ? 'selected' : '' ?>>Active</option>
                            <option value="Inactive" <?= ($uni['unit_status'] ?? '') === 'Inactive' ? 'selected' : '' ?>>Inactive</option>
                        </select>
                    </div>
							
						</div>
						<div class="modal-footer">
							<button type="button" class="btn me-2 btn-secondary" data-bs-dismiss="modal">Cancel</button>
							<button type="submit" class="btn btn-primary">Save Changes</button>
						</div>
					</form>
				</div>
			</div>
		</div>
									<?php endforeach; ?>
            <?php else: ?>
                <tr>
                    <td colspan="4" class="text-center">
                       <div class="alert alert-success d-flex align-items-center" role="alert">
                                        <i class="feather-check-circle flex-shrink-0 me-2"></i>
                                        <div>
No Units Found
					
				 </div>
                                    </div>
                    
                    </td>
                </tr>
            <?php endif; ?>
																
									</tbody>
								</table>
							</div>
						</div>
					</div>
					<!-- /product list -->
				</div>
				<?php echo view('admin/includes/coppy');?>
			</div>
        </div>
		<!-- /Main Wrapper -->

		<!-- Add Category -->
		<div class="modal fade" id="add-category">
			<div class="modal-dialog modal-dialog-centered">
				<div class="modal-content">
					<div class="modal-header">
						<div class="page-title">
							<h4>Add Unit</h4>
						</div>
						<button type="button" class="close bg-danger text-white fs-16" data-bs-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
					</div>
				<form action="<?= base_url('addunit')?>" method="post" class="add-product-form">
						<div class="modal-body">
						
							<div class="mb-3">
								<label class="form-label">Unit Name<span class="text-danger ms-1">*</span></label>
								<input type="text" class="form-control" name="unit_name" required>
							</div>
							<div class="mb-3">
								<label class="form-label">Unit Short Name<span class="text-danger ms-1">*</span></label>
								<input type="text" class="form-control" name="unit_short_name" required>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn me-2 btn-secondary" data-bs-dismiss="modal">Cancel</button>
							<button type="submit" class="btn btn-primary">Add Unit</button>
						</div>
					</form>
				</div>
			</div>
		</div>
		
		
		<!-- /Add Category -->

	

		<!-- delete modal 
		<div class="modal fade" id="delete-modal">
			<div class="modal-dialog modal-dialog-centered">
				<div class="modal-content">
					<div class="page-wrapper-new p-0">
						<div class="content p-5 px-3 text-center">
								<span class="rounded-circle d-inline-flex p-2 bg-danger-transparent mb-2"><i class="ti ti-trash fs-24 text-danger"></i></span>
								<h4 class="fs-20 fw-bold mb-2 mt-1">Delete Category</h4>
								<p class="mb-0 fs-16">Are you sure you want to delete category?</p>
								<div class="modal-footer-btn mt-3 d-flex justify-content-center">
									<button type="button" class="btn me-2 btn-secondary fs-13 fw-medium p-2 px-3 shadow-none" data-bs-dismiss="modal">Cancel</button>
									<button type="submit" class="btn btn-primary fs-13 fw-medium p-2 px-3">Yes Delete</button>
								</div>						
						</div>
					</div>
				</div>
			</div>
		</div>-->

		<!-- /Edit Category -->
		  

		<!-- jQuery -->
        <script src="<?= base_url('assets/js/jquery-3.7.1.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>

        <!-- Feather Icon JS -->
		<script src="<?= base_url('assets/js/feather.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>

		<!-- Slimscroll JS -->
		<script src="<?= base_url('assets/js/jquery.slimscroll.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>

		<!-- Datatable JS -->
		<script src="<?= base_url('assets/js/jquery.dataTables.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>
		<script src="<?= base_url('assets/js/dataTables.bootstrap5.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>
		
		<!-- Bootstrap Core JS -->
        <script src="<?= base_url('assets/js/bootstrap.bundle.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>

		<!-- Select2 JS -->
		<script src="<?= base_url('assets/plugins/select2/js/select2.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>

		<!-- Datetimepicker JS -->
		<script src="<?= base_url('assets/js/moment.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>
		<script src="<?= base_url('assets/js/bootstrap-datetimepicker.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>

		<!-- Color Picker JS -->
		<script src="<?= base_url('assets/plugins/%40simonwep/pickr/pickr.es5.min.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>

		<!-- Custom JS -->
		<script src="<?= base_url('assets/js/theme-colorpicker.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>
		<script src="<?= base_url('assets/js/script.js');?>" type="57dc3058e26463e0702091f1-text/javascript"></script>
		
    <script src="<?= base_url('assets/scripts/7d0fa10a/cloudflare-static/rocket-loader.min.js');?>" data-cf-settings="57dc3058e26463e0702091f1-|49" defer></script><script defer src="https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon='{"version":"2024.11.0","token":"3ca157e612a14eccbb30cf6db6691c29","server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}' crossorigin="anonymous"></script>
</body>

</html>