<?php echo message_box('success'); ?>
<?php echo message_box('error'); ?>
<?php
$created = can_action('82', 'created');
$edited = can_action('82', 'edited');
$deleted = can_action('82', 'deleted');
?>

<div class="space-y-4">
	<div class="rounded-2xl border border-border bg-card shadow-sm">
		<div class="p-4">
			<div class="table-responsive">
				<table class="table table-striped DataTables" id="DataTables" cellspacing="0" width="100%">
					<thead>
						<tr>
							<th class="w-12"><?= lang('sl') ?></th>
							<th><?= lang('item_name') ?></th>
							<th><?= lang('stock_category') ?></th>
							<th><?= lang('assign_quantity') ?></th>
							<th><?= lang('assign_date') ?></th>
							<th><?= lang('assigned_user') ?></th>
							<?php if (!empty($deleted) || !empty($edited)) { ?>
								<th class="w-16 hidden-print"><?= lang('action') ?></th>
							<?php } ?>
						</tr>
					</thead>
					<tbody></tbody>
				</table>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
$(document).ready(function() {
	list = base_url + "admin/stock/assign_stockList";
	$(document).on('click', '.filtered > .stock_toggle', function(e) {
		e.preventDefault();
		var $dropdown = $(this).siblings('.group_');
		if ($dropdown.css('display') == 'block') {
			$dropdown.css('display', 'none');
			$(this).attr('aria-expanded', 'false');
		} else {
			$dropdown.css('display', 'block');
			$(this).attr('aria-expanded', 'true');
		}
	});
	$(document).on('click', function(e) {
		if (!$(e.target).closest('.filtered').length) {
			$('.group_').css('display', 'none');
			$('.stock_toggle').attr('aria-expanded', 'false');
		}
	});
	$(document).on('click', '.all_filter', function() {
		$('.to_account').removeAttr("style");
		$('.from_account').removeAttr("style");
	});
	$(document).on('click', '.by_sub_category li', function() {
		if ($('.by_employee').css('display') == 'block') {
			$('.by_employee').removeAttr("style");
			$('.by_sub_category').css('display', 'block');
		} else {
			$('.by_sub_category').css('display', 'block');
		}
		if ($('.by_item_name').css('display') == 'block') {
			$('.by_item_name').removeAttr("style");
		}
	});

	$(document).on('click', '.by_employee li', function() {
		if ($('.by_item_name').css('display') == 'block') {
			$('.by_item_name').removeAttr("style");
			$('.by_employee').css('display', 'block');
		} else {
			$('.by_employee').css('display', 'block');
		}

	});

	$(document).on('click', '.by_item_name li', function() {
		if ($('.by_sub_category').css('display') == 'block') {
			$('.by_sub_category').removeAttr("style");
			$('.by_item_name').css('display', 'block');
		} else {
			$('.by_item_name').css('display', 'block');
		}
		if ($('.by_employee').css('display') == 'block') {
			$('.by_employee').removeAttr("style");
		}
	});

	$(document).on('click', '.filter_by', function(e) {
		e.preventDefault();
		$('.filter_by').removeClass('active');
		$('.group').css('display', 'block');
		$(this).addClass('active');
		var filter_by = $(this).data('filter-id');
		var search_type = $(this).data('search-type');
		if (filter_by) {
			filter_by = filter_by;
		} else {
			filter_by = '';
		}
		if (search_type) {
			search_type = '/' + search_type;
		} else {
			search_type = '';
		}
		$('.group_').css('display', 'none');
		$('.stock_toggle').attr('aria-expanded', 'false');
		table_url(base_url + "admin/stock/assign_stockList/" + filter_by + search_type);
	});

});
</script>
