<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php $useDataTables = !empty($dataTables) || !empty($datatable); ?>
<?php
$asset_url = function ($path) {
	$fullPath = FCPATH . $path;
	$version = is_file($fullPath) ? filemtime($fullPath) : time();
	return base_url($path) . '?v=' . $version;
};
?>
<script>
	// Base URL helper for inline scripts
	window.base_url = "<?php echo base_url(); ?>";
	window.erpCsrf = {
		tokenName: "<?php echo $this->security->get_csrf_token_name(); ?>",
		cookieName: "<?php echo config_item('csrf_cookie_name'); ?>",
		cookiePrefix: "<?php echo config_item('cookie_prefix'); ?>"
	};
	window.erpLazyAssets = Object.assign(window.erpLazyAssets || {}, {
		selectpicker: '<?php echo $asset_url('assets/plugins/selectpicker/selectpicker.js'); ?>',
		datetimepicker: '<?php echo $asset_url('assets/plugins/datetimepicker/datetimepicker.js'); ?>',
		tags: '<?php echo $asset_url('assets/plugins/tags/tags.js'); ?>',
		uploader: '<?php echo $asset_url('assets/plugins/uploader/uploader.js'); ?>',
		colorpicker: '<?php echo $asset_url('assets/plugins/colorpicker/colorpicker.js'); ?>',
		editor: '<?php echo $asset_url('assets/plugins/editor/editor.js'); ?>',
		validation: '<?php echo $asset_url('assets/plugins/validation/validation.js'); ?>',
		kanban: '<?php echo $asset_url('assets/plugins/kanban/kanban.js'); ?>'
	});
	window.tables_pagination_limit = <?php echo config_item('tables_pagination_limit') ? (int)config_item('tables_pagination_limit') : 10; ?>;
	window.export_lang = '<?php echo lang('export'); ?>';
	window.copy = '<?php echo lang('copy'); ?>';
	window.csv = '<?php echo lang('csv'); ?>';
	window.excel = '<?php echo lang('excel'); ?>';
	window.pdf = '<?php echo lang('pdf'); ?>';
	window.print_lang = '<?php echo lang('print'); ?>';
	window.erpNativePrint = typeof window.print === 'function' ? window.print.bind(window) : window.erpNativePrint;
	window.confirm_action = '<?php echo lang('confirm'); ?>';
	window.confirm_cancel = '<?php echo lang('cancel'); ?>';
	window.confirm_delete = '<?php echo lang('delete'); ?>';
	window.bulk_delete = '<?php echo lang('bulk_delete'); ?>';
window.search_all_column = '<?php echo lang('search_all_column'); ?>';
window.nothing_found_sorry = '<?php echo lang('nothing_found_sorry'); ?>';
window.no_record_available = '<?php echo lang('no_record_available'); ?>';
window.filtered_from = '<?php echo lang('filtered_from'); ?>';
	window.total = '<?php echo lang('total'); ?>';
window.records = '<?php echo lang('records'); ?>';
window.showing = '<?php echo lang('showing'); ?>';
window.to = '<?php echo lang('to'); ?>';
window.of = '<?php echo lang('of'); ?>';
window.entries = '<?php echo lang('entries'); ?>';
window.erpDatatableCacheBust = <?php echo !empty($this->session->flashdata('datatable_cache_bust')) ? 'true' : 'false'; ?>;
window.erpDataTableCoreAssets = {
	jqueryDataTables: '<?php echo $asset_url('assets/plugins/dataTables/js/jquery.dataTables.min.js'); ?>',
	responsive: '<?php echo $asset_url('assets/plugins/dataTables/js/dataTables.responsive.min.js'); ?>',
	buttons: '<?php echo $asset_url('assets/plugins/dataTables/js/dataTables.buttons.min.js'); ?>',
		print: '<?php echo $asset_url('assets/plugins/dataTables/js/buttons.print.min.js'); ?>',
		colVis: '<?php echo $asset_url('assets/plugins/dataTables/js/buttons.colVis.min.js'); ?>',
		erpDataTables: '<?php echo $asset_url('assets/plugins/dataTables/js/dataTables.js'); ?>'
	};
	window.erpDataTableAssets = {
		buttonsHtml5: '<?php echo $asset_url('assets/plugins/dataTables/js/buttons.html5.min.js'); ?>',
		jszip: '<?php echo $asset_url('assets/plugins/dataTables/js/jszip.min.js'); ?>',
		pdfmake: '<?php echo $asset_url('assets/plugins/dataTables/js/pdfmake.min.js'); ?>',
		vfsFonts: '<?php echo $asset_url('assets/plugins/dataTables/js/vfs_fonts.js'); ?>'
	};
</script>
<?php if ($useDataTables): ?>
	<script src="<?php echo $asset_url('assets/plugins/dataTables/js/jquery.dataTables.min.js'); ?>"></script>
	<script src="<?php echo $asset_url('assets/plugins/dataTables/js/dataTables.responsive.min.js'); ?>"></script>
	<script src="<?php echo $asset_url('assets/plugins/dataTables/js/dataTables.buttons.min.js'); ?>"></script>
	<script src="<?php echo $asset_url('assets/plugins/dataTables/js/buttons.print.min.js'); ?>"></script>
	<script src="<?php echo $asset_url('assets/plugins/dataTables/js/buttons.colVis.min.js'); ?>"></script>
	<script>
		var tables_pagination_limit = window.tables_pagination_limit;
		var export_lang = window.export_lang;
		var copy = window.copy;
		var csv = window.csv;
		var excel = window.excel;
		var pdf = window.pdf;
		var datatable_print = window.print_lang;
		var bulk_delete = window.bulk_delete;
		var search_all_column = window.search_all_column;
		var nothing_found_sorry = window.nothing_found_sorry;
		var no_record_available = window.no_record_available;
		var filtered_from = window.filtered_from;
		var total = window.total;
		var records = window.records;
		var showing = window.showing;
		var to = window.to;
		var of = window.of;
		var entries = window.entries;
	</script>

	<script src="<?php echo $asset_url('assets/plugins/dataTables/js/dataTables.js'); ?>"></script>
<?php endif; ?>
<script src="<?php echo $asset_url('assets/vendor/lucide/lucide.min.js'); ?>" defer></script>
<?php
$scripts = isset($scripts) ? $scripts : array(
	'assets/plugins/ui/ui.js',
	'assets/plugins/modal/modal.js',
	'assets/js/app.js',
);
foreach ($scripts as $scriptPath): ?>
	<script src="<?php echo $asset_url($scriptPath); ?>" defer></script>
<?php endforeach; ?>
