<?php 
	
	$sessid = session_id();
	$tema = info();
	$themeColor = isset($tema['tema']) ? trim((string) $tema['tema']) : '#000000';
	if (preg_match('/^#[0-9a-f]{3}$/i', $themeColor)) {
		$themeColor = '#'.$themeColor[1].$themeColor[1].$themeColor[2].$themeColor[2].$themeColor[3].$themeColor[3];
	}
	if (!preg_match('/^#[0-9a-f]{6}$/i', $themeColor)) {
		$themeColor = '#000000';
	}
	$themeColor = strtoupper($themeColor);
	$relativeLuminance = function($hex) {
		$rgb = array(
			hexdec(substr($hex, 1, 2)) / 255,
			hexdec(substr($hex, 3, 2)) / 255,
			hexdec(substr($hex, 5, 2)) / 255
		);
		foreach ($rgb as &$channel) {
			$channel = $channel <= 0.03928 ? $channel / 12.92 : pow(($channel + 0.055) / 1.055, 2.4);
		}
		unset($channel);
		return (0.2126 * $rgb[0]) + (0.7152 * $rgb[1]) + (0.0722 * $rgb[2]);
	};
	$themeLuminance = $relativeLuminance($themeColor);
	$darkThemeText = '#17233C';
	$lightThemeText = '#FFFFFF';
	$darkTextContrast = ($themeLuminance + 0.05) / ($relativeLuminance($darkThemeText) + 0.05);
	$lightTextContrast = ($relativeLuminance($lightThemeText) + 0.05) / ($themeLuminance + 0.05);
	$themeTextColor = $darkTextContrast >= $lightTextContrast ? $darkThemeText : $lightThemeText;
	$themeIconFilter = $themeTextColor === $darkThemeText ? 'brightness(0) saturate(100%)' : 'none';
	$themeFabBorderColor = $themeTextColor === $darkThemeText ? '#CBD5E1' : 'transparent';
	$themeTextRgb = implode(',', array(
		hexdec(substr($themeTextColor, 1, 2)),
		hexdec(substr($themeTextColor, 3, 2)),
		hexdec(substr($themeTextColor, 5, 2))
	));
	$favicon = !empty($tema['favicon']) ? $tema['favicon'] : 'favicon.ico';
	$sidebarBrandTitle = !empty($tema['title']) ? trim((string) $tema['title']) : 'POS Kasir Percetakan';
	$demoMode = isset($tema['demo']) && $tema['demo'] == 'Y';
	$chatEnabled = !isset($tema['chat_aktif']) || (int)$tema['chat_aktif'] === 1;
	$chatSound = isset($tema['chat_suara']) && in_array($tema['chat_suara'], array('classic','soft','double','silent'), true) ? $tema['chat_suara'] : 'classic';
	$versi = asset_version();
	$segment = $this->uri->segment(1);
	$segment2 = $this->uri->segment(2);
	$current_uri = trim($this->uri->uri_string(), '/');
	$root_segment = trim((string) $segment, '/');
	$needsChartJs = in_array($segment, array('home', 'grafik', 'konsumen'), TRUE) || ($segment === 'penjualan' && $segment2 === 'grafik');
	$needsPenjualanChart = ($segment === 'home');
	$needsQrScanner = ($segment === 'penjualan');
	$needsJsBarcode = ($segment === 'produk');
	$cek_info = cek_info();
	$cekUser = cekUser($this->session->idu);
	$userProfilePath = !empty($cekUser['img']) ? ltrim(str_replace('\\', '/', $cekUser['img']), '/') : '';
	if ($userProfilePath === '' || !is_file(FCPATH.$userProfilePath)) {
		$userProfilePath = 'assets/img/boy.png';
	}
	$userProfileUrl = base_url($userProfilePath);
	$sidebarMenu = sidebar_menu_data($cekUser);
	$sidebarRoots = $sidebarMenu['roots'];
	$sidebarChildren = $sidebarMenu['children'];
	$isMenuActive = function($link) use ($current_uri, $root_segment) {
		$link = trim((string) $link, '/');
		if ($link === '') {
			return FALSE;
		}
		return $link === $current_uri || $link === $root_segment || strpos($current_uri, $link.'/') === 0;
	};
	$hasActiveChild = function($parentId) use ($sidebarChildren, $isMenuActive) {
		$parentId = (int) $parentId;
		if (empty($sidebarChildren[$parentId])) {
			return FALSE;
		}
		foreach ($sidebarChildren[$parentId] as $child) {
			if ($isMenuActive($child['link'])) {
				return TRUE;
			}
		}
		return FALSE;
	};
	$mobileNavDefinitions = array(
		array('route' => 'home', 'label' => 'Beranda', 'icon' => 'fa-home', 'matches' => array('home', 'dashboard')),
		array('route' => 'penjualan/order', 'label' => 'Transaksi', 'icon' => 'fa-shopping-cart', 'matches' => array('penjualan/order', 'penjualan/trx')),
		array('route' => 'transaksi', 'label' => 'Laporan', 'icon' => 'fa-bar-chart', 'matches' => array('transaksi')),
		array('route' => 'laporan/operator', 'label' => 'Pekerjaan', 'icon' => 'fa-tasks', 'matches' => array('laporan/operator', 'operator')),
	);
	$mobileNavItems = array();
	foreach ($mobileNavDefinitions as $mobileNavItem) {
		if ($mobileNavItem['route'] !== 'home' && !isset($sidebarMenu['links'][$mobileNavItem['route']])) {
			continue;
		}
		$mobileNavItem['active'] = FALSE;
		foreach ($mobileNavItem['matches'] as $mobileNavMatch) {
			if ($isMenuActive($mobileNavMatch)) {
				$mobileNavItem['active'] = TRUE;
				break;
			}
		}
		$mobileNavItems[] = $mobileNavItem;
	}
	$mini = "";
	// Nonaktifkan sementara notifikasi bell update aplikasi di dashboard.
	$disable_update_bell = true;
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
        <link href="<?= base_url('uploads/'); ?><?=$favicon;?>" rel="icon">
        <title><?= $title; ?></title>
		
		<link rel="preconnect" href="https://fonts.googleapis.com">
		<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
		<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
		
		<!--css vendor-->
		<?=link_tag('assets/vendor/fontawesome/css/font-awesome.css'); ?>
		<?=link_tag('assets/vendor/bootstrap/css/bootstrap.min.css'); ?>
		<?=link_tag('assets/vendor/datatables/dataTables.bootstrap4.css'); ?>
		<?=link_tag('assets/vendor/selectize/css/selectize.css'); ?>
		<?=link_tag('assets/vendor/colorpick/colorPick.css'); ?>
		<?=link_tag('assets/vendor/sweetalert2/sweetalert2.min.css'); ?>
		<?=link_tag('assets/vendor/bootstrap-datepicker/bootstrap-datepicker.css'); ?>
		<?=link_tag('assets/vendor/icon-picker/simple-iconpicker.css'); ?>
		<?=link_tag('assets/vendor/jquery-ui-1.12.1/jquery-ui.css'); ?>
		<?=link_tag('assets/vendor/select2/dists/css/select2.min.css'); ?>
		<?=link_tag('assets/vendor/jquery-toast-plugin/dist/jquery.toast.min.css'); ?>
		<?=link_tag('assets/vendor/copy/primer.css'); ?>
		<?=link_tag('assets/vendor/clockpicker/clockpicker.css'); ?>
		<?=link_tag('assets/vendor/mklb/mklb.css?v='.$versi); ?>
		<?=link_tag('assets/vendor/trumbowyg/dist/ui/trumbowyg.min.css'); ?>
		<?=link_tag('assets/node_modules/noty/lib/noty.css'); ?>
		<?=link_tag('assets/node_modules/noty/lib/themes/nest.css'); ?>
		
		<!--css file-->
		<?=link_tag('assets/css/ruang-admin.css?v='.$versi); ?>
		<?=link_tag('assets/css/style-adm.css?v='.$versi); ?>
		<?=link_tag('assets/css/ns-default.css?v='.$versi); ?>
		<?=link_tag('assets/css/ns-style-other.css'); ?>
		<?=link_tag('assets/css/select2-bootstrap4.css'); ?>
		<?=link_tag('assets/css/custom-style.css?r='.$versi); ?>
		<?=link_tag('assets/css/daterangepicker.css'); ?>
		<?=link_tag('assets/css/purecookie.css'); ?>
		<?=link_tag('assets/css/glightbox.min.css'); ?>
		<?=link_tag('assets/css/jquery.terminal.min.css'); ?>
		<?=link_tag('assets/css/component-chosen.css'); ?>
		<?=link_tag('assets/css/produk.css'); ?>
		<?=link_tag('assets/css/bootstrap-select.min.css'); ?>
		<?=link_tag('assets/css/jquery.bootstrap-touchspin.css'); ?>
		<?=link_tag('assets/build/css/intlTelInput.css'); ?>
		<?=link_tag('assets/css/mobile-bottom-nav.css?v='.asset_version('assets/css/mobile-bottom-nav.css')); ?>
		
		<?=link_tag('assets/css/jquery.mCustomScrollbar.min.css'); ?>
		<?=link_tag('assets/css/mobile-responsive.css?v='.asset_version('assets/css/mobile-responsive.css')); ?>
		<?=link_tag('assets/css/sidebar-modern.css?v='.asset_version('assets/css/sidebar-modern.css')); ?>
		<?php if ($chatEnabled): ?>
		<?=link_tag('assets/css/chat.css?v='.asset_version('assets/css/chat.css')); ?>
		<?=link_tag('assets/css/chat-attachments.css?v='.asset_version('assets/css/chat-attachments.css')); ?>
		<?=link_tag('assets/css/chat-modern.css?v='.asset_version('assets/css/chat-modern.css')); ?>
		<?php endif; ?>
		
		<?php if ($demoMode){ ?>
			<!--script async data-id="200642" src="https://widget.my.id/assets/js/script.widget.js"></script-->
		<?php }?>
		<!--js file-->
        <script src="<?= base_url('assets/'); ?>vendor/jquery/jquery.min.js?v=<?=$versi;?>" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>vendor/chosen-js/chosen.jquery.min.js"></script>
        <script src="<?= base_url('assets/'); ?>vendor/jquery-ui-1.12.1/jquery-ui.js" type="text/javascript"></script>
        <script src="<?= base_url('assets/'); ?>vendor/bootstrap/js/bootstrap.bundle.js?v=<?=$versi;?>" type="text/javascript"></script>
		<script type="text/javascript" src="<?= base_url('assets/'); ?>js/moment.min.js"></script>
        <script src="<?= base_url('assets/'); ?>vendor/jquery-easing/jquery.easing.min.js?v=<?=$versi;?>" type="text/javascript"></script>
        <script src="<?= base_url('assets/'); ?>vendor/bootstrap-notify/bootstrap-notify.js" type="text/javascript"></script>
        <script src="<?= base_url('assets/'); ?>js/notif.js?v=<?=asset_version('assets/js/notif.js');?>" type="text/javascript"></script>
        <script src="<?= base_url('assets/'); ?>vendor/jquery-scrollbar/jquery.scrollbar.min.js" type="text/javascript"></script>
        <script src="<?= base_url('assets/'); ?>vendor/jQuery-slimScroll/jquery.slimscroll.min.js" type="text/javascript"></script>
        <script src="<?= base_url('assets/'); ?>js/shortcut.js" type="text/javascript"></script>
        
		<script src="<?= base_url('assets/'); ?>vendor/bootstrap-datepicker/bootstrap-datepicker.min.js?v=<?=$versi;?>" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>vendor/bootstrap-datepicker/bootstrap-datepicker.id.js" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>build/js/intlTelInput.js"></script>
		<!-- Import Trumbowyg -->
		<script src="<?= base_url('assets/'); ?>vendor/trumbowyg/dist/trumbowyg.min.js?v=<?=asset_version('assets/vendor/trumbowyg/dist/trumbowyg.min.js');?>" type="text/javascript"></script>
		<!-- Import Trumbowyg plugins... -->
		<script src="<?= base_url('assets/'); ?>vendor/trumbowyg/dist/plugins/upload/trumbowyg.upload.js" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>vendor/icon-picker/simple-iconpicker.js" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>js/js.cookie.min.js" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>js/antri_ajax.<?=$mini;?>js" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>vendor/clipboard.js/dist/clipboard.min.js?v=<?=asset_version('assets/vendor/clipboard.js/dist/clipboard.min.js');?>"></script>
		<script src="<?= base_url('assets/'); ?>node_modules/noty/lib/noty.min.js?v=<?=asset_version('assets/node_modules/noty/lib/noty.min.js');?>"></script>
		<!-- Include Date Range Picker -->
		<script type="text/javascript" src="<?= base_url('assets/'); ?>js/daterangepicker.js"></script>
		<script src="<?= base_url('assets/'); ?>js/glightbox.min.js"></script>
		<script src="<?= base_url('assets/'); ?>vendor/jquery.loading/jquery.loading.js"></script>
		<script src="<?= base_url('assets/'); ?>vendor/clockpicker/clockpicker.js"></script>
		<script src="<?= base_url('assets/'); ?>js/loadingoverlay.js" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>js/loader.<?=$mini;?>js" type="text/javascript"></script>
		<?php if ($needsJsBarcode){ ?>
		<script src="<?= base_url('assets/'); ?>js/JsBarcode.all.min.js?v=<?=asset_version('assets/js/JsBarcode.all.min.js');?>" type="text/javascript"></script>
		<?php } ?>
		<script src="<?= base_url('assets/'); ?>js/paginathing.min.js" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>js/component.js" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>js/bootstrap-select.min.js" type="text/javascript"></script>
		<script src="<?= base_url('assets/'); ?>js/jquery.bootstrap-touchspin.js" type="text/javascript"></script>
		<?php if ($needsQrScanner){ ?>
		<script src="<?= base_url('assets/'); ?>node_modules/html5-qrcode/html5-qrcode.min.js" type="text/javascript"></script>
		<?php } ?>
		<script src="<?= base_url('assets/'); ?>js/jquery.mCustomScrollbar.concat.min.js" type="text/javascript"></script>
		
        <style>
			.ui-autocomplete {
			max-height: 400px;
			overflow-y: auto;   /* prevent horizontal scrollbar */
			overflow-x: hidden; /* add padding to account for vertical scrollbar */
			z-index: 9999 !important;
			}
			.trx-scroller {
			overflow-x: auto; }
			.trx-scroller .modal-body {
			flex-wrap: nowrap;
			white-space: nowrap; }
			:root {
			--app-theme-color:<?=$themeColor;?>;
			--app-theme-text-color:<?=$themeTextColor;?>;
			--app-theme-text-rgb:<?=$themeTextRgb;?>;
			}
			.bg-navbar {
			background-color:<?=$themeColor;?>;
			color:<?=$themeTextColor;?>;
			}
			.bg-navbar #sidebarToggleTop,
			.bg-navbar #sidebarToggleLeft,
			.bg-navbar .navbar-nav .nav-item .nav-link,
			.bg-navbar .navbar-nav .nav-item .nav-link:hover,
			.bg-navbar .navbar-nav .nav-item .nav-link:focus,
			.bg-navbar .navbar-nav .nav-item .nav-link:active,
			.bg-navbar .text-white {
			color:<?=$themeTextColor;?> !important;
			}
			.bg-navbar .topbar-divider {
			border-right-color:<?=$themeTextColor;?>;
			opacity:.28;
			}
			.bg-navbar .img-profile {
			border-color:<?=$themeTextColor;?> !important;
			}
			@media (max-width: 768px) {
			.navbar.topbar.bg-navbar {
			background-color:var(--app-theme-color, <?=$themeColor;?>) !important;
			color:var(--app-theme-text-color, <?=$themeTextColor;?>) !important;
			}
			.navbar.topbar.bg-navbar #sidebarToggleTop,
			.navbar.topbar.bg-navbar #sidebarToggleLeft,
			.navbar.topbar.bg-navbar .navbar-nav .nav-item .nav-link,
			.navbar.topbar.bg-navbar .navbar-nav .nav-item .nav-link:hover,
			.navbar.topbar.bg-navbar .navbar-nav .nav-item .nav-link:focus,
			.navbar.topbar.bg-navbar .navbar-nav .nav-item .nav-link:active,
			.navbar.topbar.bg-navbar #clock,
			.navbar.topbar.bg-navbar .text-white {
			color:var(--app-theme-text-color, <?=$themeTextColor;?>) !important;
			}
			.navbar.topbar.bg-navbar .topbar-divider {
			border-right-color:var(--app-theme-text-color, <?=$themeTextColor;?>);
			border-left-color:var(--app-theme-text-color, <?=$themeTextColor;?>);
			opacity:.28;
			}
			.navbar.topbar.bg-navbar .img-profile {
			border-color:var(--app-theme-text-color, <?=$themeTextColor;?>) !important;
			}
			}
			.bg-cart{background-color:<?=$themeColor;?>;color:<?=$themeTextColor;?>;}
			.sidebar-light .sidebar-brand {
			color:<?=$themeTextColor;?> !important;
			background-color:<?=$themeColor;?>;
			}
			.ba-we-love-subscribers .img {
			background-image: url("<?= base_url('assets/img/cart.png'); ?>");
			}
			.ba-we-love-subscribers-fab {
			width: 45px;
			height: 45px;
			box-sizing: border-box;
			background-color: <?=$themeColor;?>;
			border-radius: 30px;
			float: right;
			box-shadow: 0px 12px 45px rgba(0, 0, 0, .3);
			z-index: 5;
			position: relative;
			}
			
			.ba-we-love-subscribers-fab .img-fab {
			height: 25px;
			width: 25px;
			margin: 10px auto;
			background-image: url("<?=base_url('assets/img/cart.png'); ?>");
			filter:<?=$themeIconFilter;?>;
			
			}
			.ba-we-love-subscribers-wrap {
			position: fixed;
			right: 8px;
			bottom: 15px;
			z-index: 1000;
			}
			
			.input-group-append{
			z-index:1;
			}

			.input-group-prepend > .input-group-text:not(.bg-warning):not(.bg-success):not(.bg-danger):not(.bg-info):not(.bg-primary):not(.bg-secondary):not(.bg-dark):not(.bg-light),
			.input-group-append > .input-group-text:not(.bg-warning):not(.bg-success):not(.bg-danger):not(.bg-info):not(.bg-primary):not(.bg-secondary):not(.bg-dark):not(.bg-light) {
			background-color: var(--app-theme-color) !important;
			border-color: var(--app-theme-color) !important;
			color: var(--app-theme-text-color) !important;
			}
			<?php if($this->session->level =='kasir'){ ?>
				/* ---------------------------------------------------
				SIDEBAR STYLE
				----------------------------------------------------- */
				a,
				a:hover,
				a:focus {
				color: inherit;
				text-decoration: none;
				transition: all 0.3s;
				}
				
				#sidebar {
				width: 250px;
				position: fixed;
				top: 0;
				left: -250px;
				height: 100vh;
				z-index: 999;
				background: <?=$themeColor;?>;
				color:<?=$themeTextColor;?>;
				transition: all 0.3s;
				overflow-y: scroll;
				box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.2);
				}
				
				#sidebar.active {
				left: 0;
				}
				
				#dismiss {
				width: 35px;
				height: 35px;
				line-height: 35px;
				text-align: center;
				background:<?=$themeColor;?>;
				color:<?=$themeTextColor;?>;
				position: absolute;
				top: 10px;
				right: 10px;
				cursor: pointer;
				-webkit-transition: all 0.3s;
				-o-transition: all 0.3s;
				transition: all 0.3s;
				}
				
				#dismiss:hover {
				background: #fff;
				color: #7386D5;
				}
				
				.overlay {
				display: none;
				position: fixed;
				width: 100vw;
				height: 100vh;
				background: rgba(0, 0, 0, 0.7);
				z-index: 998;
				opacity: 0;
				transition: all 0.5s ease-in-out;
				}
				.overlay.active {
				display: block;
				opacity: 1;
				}
				
				#sidebar .sidebar-header {
				padding: 20px 20px 10px 20px;
				background: <?=$themeColor;?>;
				}
				
				#sidebar ul.components {
				padding: 20px 0;
				border-bottom: 1px solid #47748b;
				}
				
				#sidebar ul p {
				color:<?=$themeTextColor;?>;
				padding: 10px;
				}
				
				#sidebar ul li a {
				padding: 10px;
				font-size: 1.1em;
				display: block;
				}
				
				#sidebar ul li a:hover {
				color: #7386D5;
				background: #fff;
				}
				
				#sidebar ul li.active>a,
				a[aria-expanded="true"] {
				color:<?=$themeTextColor;?>;
				background:<?=$themeColor;?>;
				filter: brightness(50%);
				}
				a[data-toggle="collapse"] {
				position: relative;
				}
				
				.dropdown-toggle::after {
				display: block;
				position: absolute;
				top: 50%;
				right: 20px;
				transform: translateY(-50%);
				}
			<?php } ?>

			<?php if (empty($disable_update_bell)): ?>
				/* ===== Update Bell Badge (topbar) ===== */
				#updateBellWrap { position: relative; }
				#updateBellWrap .badge-counter{
				  position: absolute;
				  top: 6px;
				  right: 6px;
				  font-size: 10px;
				  padding: 2px 6px;
				  border-radius: 12px;
				  line-height: 1;
				}

				.badge-counter {
			    position: absolute;
			    transform: scale(.8);
			    transform-origin: top right;
			    right: 2px;
			    top: 4px;
				}
			<?php endif; ?>


		</style>
        <script>
		    var servername = location.host;
			
			if(servername =='demo.ins.my.id')
			{
				var base_url = '<?=url_https(); ?>';
				}else{
				var base_url = '<?=base_url(); ?>';
			}
			
			let level = '<?= $this->session->level; ?>',
			dtime = '<?= $sessid; ?>',
			segment = '<?= $segment; ?>',
			online = "<?=ip_in_range(); ?>",
			my_ip = "<?=$_SERVER['SERVER_NAME']; ?>",
			computer_name = "<?=pengaturan('computer_name'); ?>",
			folder_af = "<?=pengaturan('folder_af'); ?>",
			folder_gm = "<?=pengaturan('folder_gm'); ?>",
			folder_ns = "<?=pengaturan('folder_ns'); ?>",
			folder_tz = "<?=pengaturan('folder_tz'); ?>",
			kasir = 1;
			rklik = <?=$tema['dev_tools'];?>;
			shortcut.add("Home",function() {
				window.location.href = base_url;
			});
			let confirm = new ConfirmClass();
			var tgl_awal = '<?=tgl_dari_slash();?>';
		</script>
		<?php
			cek_printer();
		?>
		<script src="<?= base_url('assets/'); ?>js/custom.<?=$mini;?>js?v=<?=$versi;?>" type="text/javascript"></script>
		
	</head>
	
	<body id="page-top" class="sidebar-toggled ">
		<div id="wrapper">
			<?php if($this->session->level =='kasir' && !empty($sidebarRoots)){ ?>
				<!-- Sidebar  -->
				<nav id="sidebar">
					<div id="dismiss">
						<i class="fa fa-arrow-left"></i>
					</div>
					<div class="sidebar-header">
						<div class="sidebar-brand d-flex align-items-center ">
							<div class="sidebar-brand-icon">
								<img src="<?= base_url('uploads/'); ?><?=$favicon;?>" alt="Logo aplikasi">
							</div>
							<div class="sidebar-brand-copy">
								<span class="sidebar-brand-name"><?=html_escape($sidebarBrandTitle);?></span>
								<span class="sidebar-brand-tagline">Support by : Jabar IT</span>
							</div>
						</div>
					</div>
					<hr class="sidebar-divider my-0">
							<ul class="list-unstyled components">
								<?php foreach ($sidebarRoots as $m){ ?>
									<?php if($m['treeview']=='header'){ ?>
									<?php }elseif($m['treeview']=='treeview'){
										$sub = isset($sidebarChildren[(int) $m['idmenu']]) ? $sidebarChildren[(int) $m['idmenu']] : array();
										$active = $hasActiveChild($m['idmenu']) || $isMenuActive($m['link']) ? 'active' : '';
									?>
										<li class="<?=$active;?>">
											<a href="#ex<?=$m['idmenu'];?>" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle"><?=$m['nama_menu'];?></a>
											
											<ul class="collapse list-unstyled" id="ex<?=$m['idmenu'];?>">
												
												<?php foreach ($sub as $w){ ?>
													<li>
														<a href="<?=base_url().$w['link'];?>"><?=$w['nama_menu'];?></a>
													</li>
												<?php } ?>
											</ul>
										</li>
									<?php }else{
										$active = $isMenuActive($m['link']) ? 'active' : '';
									?>
										<li class="<?=$active;?>">
											<a href="<?=base_url().$m['link'];?>"><?=$m['nama_menu'];?></a>
										</li>
									<?php } ?>
								<?php } ?>
							</ul>
							<div class="version text-center pb-3" id="version-pospercetakan"></div>
				</nav>
			<?php }
				if($this->session->level !='kasir' && !empty($sidebarRoots)){
			?>
						<!-- Sidebar -->
						
						<ul class="navbar-nav sidebar sidebar-light accordion no-print" id="accordionSidebar">
							<div class="sidebar-brand d-flex align-items-center justify-content-center">
								<div class="sidebar-brand-icon">
									<img src="<?= base_url('uploads/'); ?><?=$favicon;?>" alt="Logo aplikasi">
								</div>
								<div class="sidebar-brand-copy">
									<span class="sidebar-brand-name"><?=html_escape($sidebarBrandTitle);?></span>
									<span class="sidebar-brand-tagline">Support by : Jabar IT</span>
								</div>
							</div>
							<hr class="sidebar-divider my-0">
							<div class="sidebars">
								<?php foreach ($sidebarRoots as $m){
										if($m['treeview']=='header'){ ?>
										<hr class="sidebar-divider">
										<div class="sidebar-heading"><?=$m['nama_menu'];?></div>
										<?php }
										elseif($m['treeview']=='modal'){ ?>
										<li class="nav-item">
											<a class="nav-link openPopup" href="javascript:void(0);" data-href="<?=base_url().$m['link'];?>">
												<i class="fa fa-fw <?=$m['icon'];?> fa-lg"></i>
												<span><?=$m['nama_menu'];?></span>
											</a>
										</li>
										<?php }
										elseif($m['treeview']=='treeview'){
											$sub = isset($sidebarChildren[(int) $m['idmenu']]) ? $sidebarChildren[(int) $m['idmenu']] : array();
											$hasChildActive = $hasActiveChild($m['idmenu']);
											$jml = count($sub);
											$collapsed = $hasChildActive || $isMenuActive($m['link']) ? '' : 'collapsed';
										?>
										<li class="nav-item">
											<a class="nav-link <?=$collapsed;?>" href="#ex<?=$m['idmenu'];?>" data-toggle="collapse" data-target="#ex<?=$m['idmenu'];?>" aria-expanded="false" aria-controls="ex<?=$m['idmenu'];?>">
												<i class="fa fa-fw <?=$m['icon'];?> fa-lg"></i>
												<span><?=$m['nama_menu'];?></span>
											</a>
											<?php if ($hasChildActive || $isMenuActive($m['link'])){ ?>
												<div id="ex<?=$m['idmenu'];?>" class="collapse show" aria-labelledby="headingBootstrap" data-parent="#accordionSidebar">
											<?php }else{ ?>
												<div id="ex<?=$m['idmenu'];?>" class="collapse" aria-labelledby="headingBootstrap" data-parent="#accordionSidebar">
											<?php }
													if ($jml > 0){ ?>
														<div class="bg-white py-2 collapse-inner rounded">
															<h6 class="collapse-header"><?=$m['nama_menu'];?></h6>
															<?php foreach ($sub as $w){ ?>
																	<a class="collapse-item<?=$isMenuActive($w['link']) ? ' active' : '';?>" href="<?=base_url().$w['link'];?>" target="<?=$w['target'];?>"><?=$w['nama_menu'];?></a>
															<?php } ?>
														</div>
													<?php } ?>
												</div>
											</li>
											<?php }else{ ?>
											<li class="nav-item">
												<a class="nav-link" href="<?=base_url().$m['link'];?>" target="<?=$m['target'];?>">
													<i class="fa fa-fw <?=$m['icon'];?> fa-lg"></i>
													<span><?=$m['nama_menu'];?></span>
												</a>
											</li>
											<?php }
										}
									?>
									</div>
									<hr class="sidebar-divider">
									<div class="version text-center pb-3" id="version-pospercetakan"></div>
								</ul>
			<?php } ?>
					<!-- Topbar -->
					<div id="content-wrapper" class="d-flex flex-column">
						<div id="content">
							<nav class="navbar navbar-expand navbar-light bg-navbar topbar mb-4 static-top">
								<?php if($this->session->level =='kasir'){ ?>
									<button id="sidebarToggleLeft" class="btn btn-link rounded-circle mr-3">
										<i class="fa fa-bars"></i>
									</button>
									<?php }else{ ?>
									<button id="sidebarToggleTop" class="btn btn-link rounded-circle mr-3">
										<i class="fa fa-bars"></i>
									</button>
								<?php } ?>
								<ul class="navbar-nav ml-auto">
									<li class="nav-item no-arrow">
										<a class="nav-link" href="#">
											<i class="fa fa-clock-o fa-fw"></i> <div id="clock" data-timezone="<?=html_escape(date_default_timezone_get());?>"></div>
										</a>
									</li>
									<li class="nav-item dropdown no-arrow <?php echo ($segment === 'penjualan' && $segment2 === 'order') ? 'mobile-order-search-item' : ''; ?>">
										<a class="nav-link" href="#" data-toggle="modal" data-target="#myModalTab">
											<i class="fa fa-search fa-fw"></i>
										</a>
									</li>

									<?php if (empty($disable_update_bell)): ?>
										<li class="nav-item dropdown no-arrow mx-1" id="updateBellWrap">
										    <a class="nav-link dropdown-toggle" href="#" id="updateBellDropdown" role="button"
										       data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Notifikasi Update">
										        <i class="fa fa-bell fa-fw"></i>
										        <span class="badge badge-danger badge-counter" id="updateBellBadge">0</span>
										    </a>

										    <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in"
										         aria-labelledby="updateBellDropdown" style="min-width: 320px;">
										        <h6 class="dropdown-header">Notifikasi Update</h6>

										        <div id="updateBellContent" class="px-3 pb-2" style="font-size: 13px;">
										            <div class="text-muted">Memeriksa update...</div>
										        </div>

										        <div class="dropdown-divider"></div>
										        <a class="dropdown-item text-center small text-gray-500" href="<?= base_url('updateversi'); ?>">
										            Buka halaman update
										        </a>
										    </div>
										</li>
									<?php endif; ?>

									
																			
									</li>
									
									<li class="nav-item dropdown no-arrow mx-1 stok-notif">
										
									</li>
									<?php if ($chatEnabled): ?>
									<li class="nav-item no-arrow mx-1">
										<a class="nav-link chat-nav-link" href="#" id="chatNavButton" title="Chat pengguna" aria-label="Buka chat">
											<i class="fa fa-comments fa-fw"></i><span class="chat-nav-badge" id="chatNavBadge">0</span>
										</a>
									</li>
									<?php endif; ?>
									<div class="topbar-divider d-none d-sm-block"></div>
									<li class="nav-item dropdown no-arrow">
										<a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button"
										data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
											<img class="img-profile rounded-circle" src="<?=html_escape($userProfileUrl);?>" alt="Foto profil <?=html_escape($cekUser['nama']);?>"
											style="max-width: 60px">
											<span
											class="ml-2 d-none d-lg-inline text-white small"><?=$cekUser['nama'];?></span>
											<?php if($segment === 'penjualan' && $segment2 === 'order'){ ?>
												<span class="mobile-order-user-name text-white small"><?=$cekUser['nama'];?></span>
												<i class="fa fa-angle-down mobile-order-user-caret text-white"></i>
											<?php } ?>
										</a>
										<div class="dropdown-menu dropdown-menu-right shadow animated--grow-in"
										aria-labelledby="userDropdown">
											<?php if ($demoMode OR $this->session->level=='admin'){ ?>
												<a class="dropdown-item" href="<?=base_url();?>user/profil/<?=encrypt_url($this->session->idu);?>">
													<i class="fa fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
													Profile
												</a>
												<a class="dropdown-item" href="<?=base_url();?>main/info">
													<i class="fa fa-cogs fa-sm fa-fw mr-2 text-gray-400"></i>
													Settings
												</a>
												<div class="dropdown-divider"></div>
												<!--a class="dropdown-item" href="https://wa.me/62895326083254" target="_blank">
													<i class="fa fa-info fa-sm fa-fw mr-2 text-gray-400"></i>
													Hubungi Pengembang
												</a-->
												<?php }else{ ?>
												<a class="dropdown-item" href="<?=base_url();?>user/profil/<?=encrypt_url($this->session->idu);?>">
													<i class="fa fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
													Profile
												</a>
											<?php } ?>
											
											
											<a class="dropdown-item" href="<?= base_url('main/'); ?>logout">
												<i class="fa fa-sign-out fa-sm fa-fw mr-2 text-gray-400"></i>
												Logout
											</a>
										</div>
									</li>
								</ul>
							</nav>
							
							<!-- Topbar -->
							<?php
								echo $contents;
								$this->load->view('produk/modal_popup');
								if ($chatEnabled) $this->load->view('chat/widget', array('chatSound'=>$chatSound));
								
							?>
							<div id="load-modal"></div>
						</div>
						<nav class="mobile-bottom-nav no-print" aria-label="Navigasi utama mobile" style="--mobile-nav-count:<?=count($mobileNavItems) + 1;?>">
							<?php foreach ($mobileNavItems as $mobileNavItem){ ?>
								<a class="mobile-bottom-nav__item<?=$mobileNavItem['active'] ? ' is-active' : '';?>" href="<?=base_url($mobileNavItem['route']);?>"<?=$mobileNavItem['active'] ? ' aria-current="page"' : '';?>>
									<i class="fa <?=$mobileNavItem['icon'];?>" aria-hidden="true"></i>
									<span><?=$mobileNavItem['label'];?></span>
								</a>
							<?php } ?>
							<button class="mobile-bottom-nav__item" type="button" data-mobile-menu-toggle aria-label="Buka menu utama">
								<i class="fa fa-bars" aria-hidden="true"></i>
								<span>Menu</span>
							</button>
						</nav>
						<?php if($segment!='penjualan'){ ?>
							<div class="ba-we-love-subscribers-wrap no-print">
								
								<div class="ba-we-love-subscribers-fab">
									<div class="wrap">
										<a href="#" class="button_transaksi" data-id="0" data-modedit="baru" id="cart"><div class="img-fab img"></div></a>
									</div>
								</div>
							</div>
						<?php } ?>
						<!-- Footer -->
						<footer class="sticky-footer bg-white no-print">
							<div class="container my-auto">
								<div class="copyright text-center my-auto">
									<span><?= copyYear(2024) .' '.SITE_NAME .' | JABAR IT SOLUTION | '.$cek_info['browser'].' | '.$cek_info['os'].' | IP: '.$cek_info['ip']; ?> <a href="https://indrijunanda.github.io/RuangAdmin/" target="_blank"></a></span>
								</div>
							</div>
						</footer>
						<!-- Footer -->
					</div>
				</div>
				
				<!--div class="c3d6fa211a7c7a"></div-->
				<?php
					$pesan = $this->session->flashdata('dataNull');
					if(!empty($pesan)):
				?>
				<script>
					$(window).on('load',function(){
						let pesan = "<?= $pesan ?>";
						Swal.fire('Oops!',pesan,'error');
					});
				</script>
				<?php endif; ?>  


				<!-- ===== Scroll Controls: Top & Bottom (drop-in replacement) ===== -->
				<style>
				  :root{
				    --scroll-btn-size: 45px;
				    --scroll-gap: 12px;
				    --floating-action-right: 8px;
				    --floating-action-bottom: 15px;
				  }
				  .no-print{ }
				  @media print {
				    .no-print{ display: none !important; }
				  }

				  .scroll-fab{
				    position: fixed;
				    right: var(--floating-action-right);
				    z-index: 1040; /* di atas konten */
				    width: var(--scroll-btn-size);
				    height: var(--scroll-btn-size);
				    box-sizing: border-box;
				    border-radius: 50%;
				    display: grid;
				    place-items: center;
				    box-shadow: 0 8px 20px rgba(0,0,0,.24);
				    background-color: <?=$themeColor;?>;
				    background-image: none;
				    color: <?=$themeTextColor;?> !important;
				    border: 1px solid <?=$themeFabBorderColor;?>;
				    font-size: 18px;
				    line-height: 1;
				    text-decoration: none;
				    opacity: 0;
				    pointer-events: none;
				    transform: translateY(8px);
				    transition: opacity .2s ease, transform .2s ease, box-shadow .2s ease;
				  }
				  .scroll-fab:hover,
				  .scroll-fab:focus{
				    box-shadow: 0 10px 24px rgba(0,0,0,.30);
				    outline: none;
				  }
				  .scroll-fab i{
				    display:block;
				    line-height:1;
				  }
				  .scroll-fab.show{
				    opacity: 1;
				    pointer-events: auto;
				    transform: translateY(0);
				  }
				  /* posisi: bottom & top disusun vertikal */
				  .scroll-to-bottom{
				    bottom: calc(var(--floating-action-bottom) + var(--scroll-btn-size) + var(--scroll-gap));
				  }
				  .scroll-to-top{
				    bottom: calc(var(--floating-action-bottom) + var(--scroll-btn-size) + var(--scroll-gap) + var(--scroll-btn-size) + var(--scroll-gap));
				  }

				  /* dukung preferensi user untuk smooth scroll (fallback ditangani JS) */
				  html{ scroll-behavior: smooth; }
				</style>

				<!-- Tombol Scroll -->
				<a class="scroll-fab scroll-to-top no-print" href="#page-top" aria-label="Scroll to top" title="Ke atas">
				  <i class="fa fa-angle-up" aria-hidden="true"></i>
				</a>
				<a class="scroll-fab scroll-to-bottom no-print" href="#page-bottom" aria-label="Scroll to bottom" title="Ke bawah">
				  <i class="fa fa-angle-down" aria-hidden="true"></i>
				</a>

				<script>
				  (function(){
				    // Pastikan anchor top & bottom tersedia
				    if(!document.getElementById('page-top')){
				      const topAnchor = document.createElement('div');
				      topAnchor.id = 'page-top';
				      topAnchor.style.position = 'absolute';
				      topAnchor.style.top = '0';
				      topAnchor.style.left = '0';
				      document.body.prepend(topAnchor);
				    }
				    if(!document.getElementById('page-bottom')){
				      const bottomAnchor = document.createElement('div');
				      bottomAnchor.id = 'page-bottom';
				      bottomAnchor.style.position = 'absolute';
				      bottomAnchor.style.bottom = '0';
				      bottomAnchor.style.left = '0';
				      document.body.appendChild(bottomAnchor);
				    }

				    const btnTop = document.querySelector('.scroll-to-top');
				    const btnBottom = document.querySelector('.scroll-to-bottom');

				    // Tampilkan/hilangkan berdasarkan posisi scroll
				    function updateButtons(){
				      const scrollY = window.scrollY || window.pageYOffset;
				      const docH = Math.max(
				        document.body.scrollHeight, document.documentElement.scrollHeight,
				        document.body.offsetHeight, document.documentElement.offsetHeight,
				        document.body.clientHeight, document.documentElement.clientHeight
				      );
				      const winH = window.innerHeight || document.documentElement.clientHeight;

				      // Munculkan "Top" jika sudah turun > 200px
				      if(scrollY > 200){
				        btnTop.classList.add('show');
				      }else{
				        btnTop.classList.remove('show');
				      }

				      // Munculkan "Bottom" jika belum dekat bagian paling bawah (buffer 200px)
				      if(scrollY + winH < docH - 200){
				        btnBottom.classList.add('show');
				      }else{
				        btnBottom.classList.remove('show');
				      }
				    }

				    // Smooth scroll via JS (fallback jika browser tak dukung CSS smooth)
				    function smoothTo(y){
				      try{
				        window.scrollTo({ top: y, behavior: 'smooth' });
				      }catch(_){
				        // fallback lama
				        window.scrollTo(0, y);
				      }
				    }

				    btnTop.addEventListener('click', function(e){
				      // Jika href target ada, biarkan default; tapi kita override untuk robust
				      e.preventDefault();
				      smoothTo(0);
				    });

				    btnBottom.addEventListener('click', function(e){
				      e.preventDefault();
				      const docH = Math.max(
				        document.body.scrollHeight, document.documentElement.scrollHeight,
				        document.body.offsetHeight, document.documentElement.offsetHeight,
				        document.body.clientHeight, document.documentElement.clientHeight
				      );
				      smoothTo(docH);
				    });

				    // Keyboard accessibility (Enter/Space memicu)
				    [btnTop, btnBottom].forEach(btn=>{
				      btn.setAttribute('role','button');
				      btn.setAttribute('tabindex','0');
				      btn.addEventListener('keydown', function(ev){
				        if(ev.key === 'Enter' || ev.key === ' '){
				          ev.preventDefault();
				          btn.click();
				        }
				      });
				    });

				    // Init + listeners
				    updateButtons();
				    window.addEventListener('scroll', updateButtons, { passive: true });
				    window.addEventListener('resize', updateButtons);
				    document.addEventListener('DOMContentLoaded', updateButtons);
				  })();
				</script>
				<!-- ===== End Scroll Controls ===== -->



				<script src="<?=base_url('assets/');?>vendor/jquery-toast-plugin/dist/jquery.toast.min.js" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>vendor/datatables/jquery.dataTables.js" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>vendor/datatables/dataTables.bootstrap4.js?v=<?=$versi;?>" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>vendor/datatables/dataTables.buttons.min.js" type="text/javascript"></script>
				
				<!-- Sertakan JSZip untuk eksport ke Excel -->
				<script src="<?=base_url('assets/');?>vendor/datatables/jszip.min.js"></script>
				
				<!-- Sertakan PDFMake untuk eksport ke PDF -->
				<script src="<?=base_url('assets/');?>vendor/datatables/buttons.html5.min.js"></script>
				<script src="<?=base_url('assets/');?>vendor/datatables/pdfmake.min.js"></script>
				<script src="<?=base_url('assets/');?>vendor/datatables/vfs_fonts.js"></script>
				
				<script src="<?=base_url('assets/');?>vendor/datatables/buttons.bootstrap4.min.js?v=<?=asset_version('assets/vendor/datatables/buttons.bootstrap4.min.js');?>" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>js/ruang-admin.min.js" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>js/sidebar-modern.js?v=<?=asset_version('assets/js/sidebar-modern.js');?>" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>js/mobile-bottom-nav.js?v=<?=asset_version('assets/js/mobile-bottom-nav.js');?>" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>js/validation.min.js" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>vendor/selectize/js/standalone/selectize.js" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>vendor/select2/dists/js/select2.min.js?v=<?=$versi;?>" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>js/jquery.fileDownload.js" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>js/jquery.fcs.js?v=<?=$versi;?>" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>vendor/sweetalert2/sweetalert2.min.js" type="text/javascript"></script>
				<?php if ($needsChartJs){ ?>
				<script src="<?=base_url('assets/');?>vendor/chart.js/Chart.min.js?v=<?=asset_version('assets/vendor/chart.js/Chart.min.js');?>" type="text/javascript"></script>
				<?php } ?>
				<?php if ($needsPenjualanChart){ ?>
				<script src="<?=base_url('assets/');?>js/chart/chart-penjualan.js?v=<?=$versi;?>" type="text/javascript"></script>
				<?php } ?>
				<script src="<?=base_url('assets/');?>js/domath.<?=$mini;?>js?v=<?=asset_version('assets/js/domath.'.$mini.'js');?>" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>js/popup.<?=$mini;?>js?v=<?=asset_version('assets/js/popup.'.$mini.'js');?>" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>js/app.<?=$mini;?>js?v=<?=asset_version('assets/js/app.'.$mini.'js');?>" type="text/javascript"></script>
				<script src="<?=base_url('assets/');?>js/tab.<?=$mini;?>js?v=<?=$versi;?>" type="text/javascript"></script>
				
				<script src="<?= base_url('assets/'); ?>js/pencarian.<?=$mini;?>js?v=<?=$versi;?>" type="text/javascript"></script>
				<script src="<?= base_url('assets/'); ?>js/url_doc.js?v=<?=$versi;?>" type="text/javascript"></script>
				<script src="<?= base_url('assets/'); ?>js/clock.min.js?v=<?=asset_version('assets/js/clock.min.js');?>" type="text/javascript"></script>
				<?php if ($chatEnabled): ?><script src="<?= base_url('assets/'); ?>js/chat.js?v=<?=asset_version('assets/js/chat.js');?>" type="text/javascript"></script><?php endif; ?>
				<script src="<?= base_url('assets/'); ?>vendor/copy/clipboard.js?v=<?=asset_version('assets/vendor/copy/clipboard.js');?>"></script>
				
				<script>
					
					if(rklik==1){
						document.addEventListener('contextmenu', (e) => e.preventDefault());
						
						function ctrlShiftKey(e, keyCode) {
							return e.ctrlKey && e.shiftKey && e.keyCode === keyCode.charCodeAt(0);
						}
						
						document.onkeydown = (e) => {
							if (
							event.keyCode === 123 ||
							ctrlShiftKey(e, 'I') ||
							ctrlShiftKey(e, 'J') ||
							ctrlShiftKey(e, 'C') ||
							(e.ctrlKey && e.keyCode === 'U'.charCodeAt(0))
							)
							return false;
						};
					}
					$('#multiple').select2({
						theme: "bootstrap"
					});
					
					$('#jenis_grup').each(function () {
						$(this).select2({
							theme: 'bootstrap4',
							width: 'style',
							placeholder: $(this).attr('placeholder'),
							allowClear: Boolean($(this).data('allow-clear')),
						});
					});
					$(document).ready(function(){
						$('[data-toggle="tooltip"]').tooltip();
						$('[data-tooltip="tooltip"]').tooltip();
						$('#dari').attr('autocomplete','off');
						$('#sampai').attr('autocomplete','off');
						
					});
					$(document).ready(function () {
						$("#sidebar").mCustomScrollbar({
							theme: "minimal"
						});
						
						$('#dismiss, .overlay').on('click', function () {
							$('#sidebar').removeClass('active');
							$('.overlay').removeClass('active');
						});
						
						$('#sidebarToggleLeft').on('click', function () {
							$('#sidebar').addClass('active');
							$('.overlay').addClass('active');
							$('.collapse.in').toggleClass('in');
							$('a[aria-expanded=true]').attr('aria-expanded', 'false');
						});
					});
					$(".bootstrap-select").selectpicker();
				</script>
				<?php
					if(isset($this->RenderScript))
					foreach($this->RenderScript as $script) {
						$script();
					}
				?>

				<script>
				  // ===== ONLINE PING (update last_activity) =====
				  (function(){
				    function pingOnline(){
				      if (typeof $ === 'undefined' || typeof base_url === 'undefined' || document.hidden) return;
				      $.ajax({
				        type: 'POST',
				        url: base_url + 'history/ping',
				        dataType: 'json',
				        timeout: 8000
				      });
				    }
				    window.setTimeout(pingOnline, 1500);
				    setInterval(pingOnline, 60000); // 60 detik sekali
				  })();
				</script>

				
				<!--script src="<?= base_url('assets/js/anti-right-click.js'); ?>"></script--> 


<?php if (empty($disable_update_bell)): ?>
<script>
(function(){
  if (typeof $ === 'undefined' || typeof base_url === 'undefined') return;

  var CACHE_KEY = 'pos_update_bell_cache_v1';
  var TTL = 30 * 60 * 1000; // 30 menit

  function setBadge(n, isUpdate){
    n = parseInt(n || 0, 10);
    if (isNaN(n)) n = 0;

    $('#updateBellBadge').text(String(n));

    if (isUpdate) {
      $('#updateBellBadge').removeClass('badge-secondary').addClass('badge-danger');
    } else {
      $('#updateBellBadge').removeClass('badge-danger').addClass('badge-secondary');
    }
  }

  function normalize(res){
    // dukung 2 kemungkinan nama field dari backend
    var has = false;
    if (res) {
      if (typeof res.available !== 'undefined') has = !!res.available;
      else if (typeof res.has_update !== 'undefined') has = !!res.has_update;
    }
    return {
      available: has,
      latest: (res && (res.latest || res.latest_version)) ? (res.latest || res.latest_version) : '-',
      current: (res && (res.current || res.current_version)) ? (res.current || res.current_version) : '-'
    };
  }

  function render(raw){
    var res = normalize(raw);

    if (res.available) {
      setBadge(1, true);
      $('#updateBellContent').html(
        '<div style="font-weight:600; margin-bottom:6px;">Update tersedia!</div>' +
        '<div>Versi terbaru: <b>' + res.latest + '</b></div>' +
        '<div>Versi saat ini: <b>' + res.current + '</b></div>' +
        '<div class="mt-2">' +
          '<a href="' + base_url + 'updateversi" class="btn btn-sm btn-warning">Update sekarang</a>' +
        '</div>'
      );
    } else {
      setBadge(0, false);
      $('#updateBellContent').html('<div class="text-muted">Tidak ada update. Aplikasi sudah versi terbaru.</div>');
    }
  }

  function loadCache(){
    try{
      var raw = localStorage.getItem(CACHE_KEY);
      if(!raw) return null;
      var obj = JSON.parse(raw);
      if(!obj || !obj.ts) return null;
      if(Date.now() - obj.ts > TTL) return null;
      return obj.data || null;
    }catch(e){ return null; }
  }

  function saveCache(data){
    try{
      localStorage.setItem(CACHE_KEY, JSON.stringify({ts: Date.now(), data: data}));
    }catch(e){}
  }

  function fetchStatus(){
    var cached = loadCache();
    if (cached) render(cached);

    $.ajax({
      url: base_url + 'updateversi/check_update_notif',
      method: 'GET',
      dataType: 'json',
      timeout: 20000
    }).done(function(res){
      saveCache(res);
      render(res);
    }).fail(function(){
      setBadge(0, false);
      $('#updateBellContent').html('<div class="text-muted">Gagal memeriksa update.</div>');
    });
  }

  $(function(){
    setBadge(0, false);
    $('#updateBellContent').html('<div class="text-muted">Memeriksa update...</div>');
    fetchStatus();

    document.addEventListener('visibilitychange', function(){
      if(!document.hidden) fetchStatus();
    });
  });
})();
</script>
<?php endif; ?>


<script>
(function (w, d) {
  if (w.__escModalCloseBound) return;
  w.__escModalCloseBound = true;

  d.addEventListener('keydown', function (e) {
    var isEsc = e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27;
    if (!isEsc || typeof w.jQuery === 'undefined') return;

    var $ = w.jQuery;
    var $modals = $('.modal.show:visible');
    if ($modals.length) {
      e.preventDefault();
      e.stopPropagation();
      $modals.last().modal('hide');
      return;
    }

    var $overlay = $('.overlay.active:visible, .overlay.show:visible, .popup.show:visible').last();
    if ($overlay.length) {
      e.preventDefault();
      e.stopPropagation();
      $overlay.removeClass('active show').hide();
    }
  }, true);
})(window, document);
</script>



			</body>
		</html>																						
