<?php echo message_box('success'); ?>
<?php echo message_box('error');
$created = can_action('142', 'created');
$edited = can_action('142', 'edited');
$deleted = can_action('142', 'deleted');
?>
<div class="space-y-4">
	<div class="rounded-2xl border border-border bg-card shadow-sm">
		<div class="p-5">
			<table class="table table-striped DataTables" id="DataTables" cellspacing="0" width="100%">
				<thead>
					<tr>
						<th><?= lang('categories') ?></th>
						<th><?= lang('description') ?></th>
						<th class="col-sm-1"><?= lang('active') ?></th>
						<th class="col-sm-1"><?= lang('order') ?></th>
						<th><?= lang('action') ?></th>
					</tr>
				</thead>
				<tbody>
					<script type="text/javascript">
						list = base_url + "admin/knowledgebase/categoriesList";
					</script>
				</tbody>
			</table>
		</div>
	</div>
</div>
<script>
	$(document).on("click", '.change_kb_category input[type="checkbox"]', function() {
		var kb_category_id = $(this).data().id;
		var status = $(this).is(":checked");
		if (status == true) {
			status = 1;
		} else {
			status = 2;
		}
		$.ajax({
			type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
			url: '<?= base_url() ?>admin/knowledgebase/change_status/' + status + '/' +
				kb_category_id, // the url where we want to POST
			dataType: 'json', // what type of data do we expect back from the server
			encode: true,
			success: function(res) {
				if (res) {
					toastr[res.status](res.message);
				} else {
					alert(<?= json_encode(lang('ajax_problem')) ?>);
				}
			}
		})
	});
</script>
