<div class="wrapper boxed-layout" <?php 
use XcVm\Core\Config\SettingsManager;

if (empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
									} else { ?> style="display: none;" <?php } ?>>
	<div class="container-fluid">
		<div class="row">
			<div class="col-12">
				<div class="page-title-box">
					<div class="page-title-right">
						<?php include 'topbar.php'; ?>
					</div>
					<h4 class="page-title">
						<?php if (isset($rCategoryArr)) {
							echo 'Edit';
						} else {
							echo 'Add';
						} ?>
						Category</h4>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-xl-12">
				<div class="card">
					<div class="card-body">
						<form action="#" method="POST" data-parsley-validate="">
							<?php if (!isset($rCategoryArr)) {
							} else { ?>
								<input type="hidden" name="edit" value="<?= intval($rCategoryArr['id']); ?>" />
								<input type="hidden" name="cat_order" value="<?= intval($rCategoryArr['cat_order']); ?>" />
							<?php } ?>
							<div id="basicwizard">
								<ul class="nav nav-pills bg-light nav-justified form-wizard-header mb-4">
									<li class="nav-item">
										<a href="#category-details" data-toggle="tab"
											class="nav-link rounded-0 pt-2 pb-2">
											<i class="mdi mdi-account-card-details-outline mr-1"></i>
											<span class="d-none d-sm-inline"><?= $language::get('details') ?></span>
										</a>
									</li>
									<?php if (!isset($rCategoryArr)) {
									} else { ?>
										<li class="nav-item">
											<a href="#view-channels" data-toggle="tab" class="nav-link rounded-0 pt-2 pb-2">
												<i class="mdi mdi-play mr-1"></i>
												<span class="d-none d-sm-inline"><?= $language::get('permission_streams') ?></span>
											</a>
										</li>
									<?php } ?>
								</ul>
								<div class="tab-content b-0 mb-0 pt-0">
									<div class="tab-pane" id="category-details">
										<div class="row">
											<div class="col-12">
												<?php if (!isset($rCategoryArr)) { ?>
													<div class="form-group row mb-4">
														<label class="col-md-4 col-form-label" for="category_type">Category
															Type</label>
														<div class="col-md-8">
															<select name="category_type" id="category_type"
																class="form-control select2" data-toggle="select2">
																<?php foreach (array('live' => 'Live TV', 'movie' => 'Movie', 'series' => 'TV Series', 'radio' => 'Radio Station') as $rGroupID => $rGroup) { ?>
																	<option <?php if (!isset($rCategoryArr)) {
																			} else {
																				if ($rCategoryArr['category_type'] == $rGroupID) {
																					echo 'selected ';
																				}
																			} ?> value="<?= $rGroupID; ?>"><?= $rGroup; ?></option>
																<?php } ?>
															</select>
														</div>
													</div>
												<?php } else { ?>
													<input type="hidden" name="category_type"
														value="<?= htmlspecialchars($rCategoryArr['category_type']); ?>" />
												<?php } ?>
												<div class="form-group row mb-4">
													<label class="col-md-4 col-form-label" for="category_name">Category
														Name</label>
													<div class="col-md-8">
														<input type="text" class="form-control" id="category_name"
															name="category_name"
															value="<?= isset($rCategoryArr) ? htmlspecialchars($rCategoryArr['category_name']) : ''; ?>"
															required data-parsley-trigger="change">
													</div>
												</div>
												<div class="form-group row mb-4">
													<label class="col-md-4 col-form-label" for="is_adult">Adult
														Content</label>
													<div class="col-md-2">
														<input name="is_adult" id="is_adult" type="checkbox" <?php if (!isset($rCategoryArr)) {
																												} else {
																													if ($rCategoryArr['is_adult'] == 1) {
																														echo 'checked ';
																													}
																												} ?>data-plugin="switchery" class="js-switch"
															data-color="#039cfd" />
													</div>
												</div>
											</div>
										</div>
										<ul class="list-inline wizard mb-0">
											<li class="list-inline-item float-right">
												<input name="submit_category" type="submit" class="btn btn-primary"
													value="<?php if (isset($rCategoryArr)) {
																echo 'Edit';
															} else {
																echo 'Add';
															} ?>" />
											</li>
										</ul>
									</div>
									<div class="tab-pane" id="view-channels">
										<div class="row">
											<div class="col-12" style="overflow-x:auto;">
												<table id="datatable"
													class="table table-striped table-borderless dt-responsive nowrap">
													<thead>
														<tr>
															<th class="text-center"><?= $language::get('stream_id') ?></th>
															<th><?= $language::get('stream_name') ?></th>
															<th class="text-center"><?= $language::get('actions') ?></th>
														</tr>
													</thead>
													<tbody></tbody>
												</table>
											</div>
										</div>
									</div>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<?php
require_once __DIR__ . '/../layouts/footer.php';
renderUnifiedLayoutFooter('admin');
?>
<script id="scripts">
	var resizeObserver = new ResizeObserver(entries => $(window).scroll());
	$(document).ready(function() {
		resizeObserver.observe(document.body)
		$("form").attr('autocomplete', 'off');
		$(document).keypress(function(event) {
			if (event.which == 13 && event.target.nodeName != "TEXTAREA") return false;
		});
		$.fn.dataTable.ext.errMode = 'none';
		var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
		elems.forEach(function(html) {
			var switchery = new Switchery(html, {
				'color': '#414d5f'
			});
			window.rSwitches[$(html).attr("id")] = switchery;
		});
		setTimeout(pingSession, 30000);
		<?php if (!$rMobile && $rSettings['header_stats']): ?>
			headerStats();
		<?php endif; ?>
		bindHref();
		refreshTooltips();
		$(window).scroll(function() {
			if ($(this).scrollTop() > 200) {
				if ($(document).height() > $(window).height()) {
					$('#scrollToBottom').fadeOut();
				}
				$('#scrollToTop').fadeIn();
			} else {
				$('#scrollToTop').fadeOut();
				if ($(document).height() > $(window).height()) {
					$('#scrollToBottom').fadeIn();
				} else {
					$('#scrollToBottom').hide();
				}
			}
		});
		$("#scrollToTop").unbind("click");
		$('#scrollToTop').click(function() {
			$('html, body').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
		$("#scrollToBottom").unbind("click");
		$('#scrollToBottom').click(function() {
			$('html, body').animate({
				scrollTop: $(document).height()
			}, 800);
			return false;
		});
		$(window).scroll();
		$(".nextb").unbind("click");
		$(".nextb").click(function() {
			var rPos = 0;
			var rActive = null;
			$(".nav .nav-item").each(function() {
				if ($(this).find(".nav-link").hasClass("active")) {
					rActive = rPos;
				}
				if (rActive !== null && rPos > rActive && !$(this).find("a").hasClass("disabled") && $(this).is(":visible")) {
					$(this).find(".nav-link").trigger("click");
					return false;
				}
				rPos += 1;
			});
		});
		$(".prevb").unbind("click");
		$(".prevb").click(function() {
			var rPos = 0;
			var rActive = null;
			$($(".nav .nav-item").get().reverse()).each(function() {
				if ($(this).find(".nav-link").hasClass("active")) {
					rActive = rPos;
				}
				if (rActive !== null && rPos > rActive && !$(this).find("a").hasClass("disabled") && $(this).is(":visible")) {
					$(this).find(".nav-link").trigger("click");
					return false;
				}
				rPos += 1;
			});
		});
		(function($) {
			$.fn.inputFilter = function(inputFilter) {
				return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function() {
					if (inputFilter(this.value)) {
						this.oldValue = this.value;
						this.oldSelectionStart = this.selectionStart;
						this.oldSelectionEnd = this.selectionEnd;
					} else if (this.hasOwnProperty("oldValue")) {
						this.value = this.oldValue;
						this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
					}
				});
			};
		}(jQuery));
		<?php if ($rSettings['js_navigate']): ?>
			$(".navigation-menu li").mouseenter(function() {
				$(this).find(".submenu").show();
			});
			delParam("status");
			$(window).on("popstate", function() {
				if (window.rRealURL) {
					if (window.rRealURL.split("/").reverse()[0].split("?")[0].split(".")[0] != window.location.href.split("/").reverse()[0].split("?")[0].split(".")[0]) {
						navigate(window.location.href.split("/").reverse()[0]);
					}
				}
			});
		<?php endif; ?>
		$(document).keydown(function(e) {
			if (e.keyCode == 16) {
				window.rShiftHeld = true;
			}
		});
		$(document).keyup(function(e) {
			if (e.keyCode == 16) {
				window.rShiftHeld = false;
			}
		});
		document.onselectstart = function() {
			if (window.rShiftHeld) {
				return false;
			}
		}
	});

	<?php
	echo '        ' . "\r\n\t\t" . '$(document).ready(function() {' . "\r\n\t\t\t" . "\$('select').select2({width: '100%'})" . "\r\n\t\t\t";

	if (!isset($rCategoryArr)) {
	} else {
		echo "\t\t\t" . '$("#datatable").DataTable({' . "\r\n\t\t\t\t" . 'language: {' . "\r\n\t\t\t\t\t" . 'paginate: {' . "\r\n\t\t\t\t\t\t" . "previous: \"<i class='mdi mdi-chevron-left'>\"," . "\r\n\t\t\t\t\t\t" . "next: \"<i class='mdi mdi-chevron-right'>\"" . "\r\n\t\t\t\t\t" . '}' . "\r\n\t\t\t\t" . '},' . "\r\n\t\t\t\t" . 'drawCallback: function() {' . "\r\n\t\t\t\t\t" . 'bindHref(); refreshTooltips();' . "\r\n\t\t\t\t" . '},' . "\r\n\t\t\t\t" . 'responsive: false,' . "\r\n\t\t\t\t" . 'bAutoWidth: false,' . "\r\n\t\t\t\t" . 'bInfo: false,' . "\r\n\t\t\t\t" . 'processing: true,' . "\r\n\t\t\t\t" . 'serverSide: true,' . "\r\n\t\t\t\t" . 'ajax: {' . "\r\n\t\t\t\t\t" . 'url: "./table",' . "\r\n\t\t\t\t\t" . '"data": function(d) {' . "\r\n\t\t\t\t\t\t";

		if ($rCategoryArr['category_type'] == 'live') {
			echo "\t\t\t\t\t\t" . 'd.id = "streams_short";' . "\r\n\t\t\t\t\t\t";
		} else {
			if ($rCategoryArr['category_type'] == 'movie') {
				echo "\t\t\t\t\t\t" . 'd.id = "movies_short";' . "\r\n\t\t\t\t\t\t";
			} else {
				if ($rCategoryArr['category_type'] == 'radio') {
					echo "\t\t\t\t\t\t" . 'd.id = "radios_short";' . "\r\n\t\t\t\t\t\t";
				} else {
					echo "\t\t\t\t\t\t" . 'd.id = "series_short";' . "\r\n\t\t\t\t\t\t";
				}
			}
		}

		echo "\t\t\t\t\t\t" . 'd.category_id = ';
		echo $rCategoryArr['id'];
		echo ';' . "\r\n\t\t\t\t\t" . '}' . "\r\n\t\t\t\t" . '},' . "\r\n\t\t\t\t" . 'columnDefs: [' . "\r\n\t\t\t\t\t" . '{"className": "dt-center", "targets": [0,2]}' . "\r\n\t\t\t\t" . '],' . "\r\n\t\t\t" . '});' . "\r\n\t\t\t";
	}

	echo '            $("form").submit(function(e){' . "\r\n" . '                e.preventDefault();' . "\r\n" . "                \$(':input[type=\"submit\"]').prop('disabled', true);" . "\r\n" . '                submitForm(window.rCurrentPage, new FormData($("form")[0]));' . "\r\n" . '            });' . "\r\n\t\t" . '});' . "\r\n" . '        ' . "\r\n\t\t";
	?>
	<?php if (SettingsManager::getAll()['enable_search']): ?>
		$(document).ready(function() {
			initSearch();
		});
	<?php endif; ?>
</script>
<script src="assets/js/listings.js"></script>
</body>

</html>
