<?php 
$submit_url = "index?page=view_product";
$show_all_page = "page=view_product&quic=1";
$quick_search =$_REQUEST['quic'];
?>
<!-- search form -->
<form class="form-horizontal" action="<?php echo $submit_url;?>" method="post" name="search_form" id="search_form">
	<div class="card-body">
		<div class="row">
				<div class="col-lg-12 col-12">
				<label for="Office" class="control-label" style="color:red;">Quick Search</label> 
				<input type="radio" name="quick_search" class="flat-red" id="checkbox1" <? echo ($quick_search ==1) ? 'checked':''; ?>>
				<label for="" class="control-label" style="margin-left:5%;color:red;">Advance Search</label> 
				  <input type="radio" id="checkbox2" class="flat-red " name="advance_search" <? echo ($quick_search ==1) ? '':''; ?>>
				</div>
				<div class="col-lg-12 col-12 quick_search_div" style="margin-top:1%;display:<?=$quick_search_div;?>">
				<div class="row">
					 <div class="col-lg-3 col-12">
						<label for="product_template_id" class="control-label">Item Template Name</label>
						<div class="">
							<?php echo $gsi->getProductTempateList("product_template_id", $product_template_id, "100%", false, "form-control select2", ""); ?>
						</div>
					</div>
					<div class="col-lg-3 col-12">
						<label for="Name" class="control-label">Part Number</label>
						<?php echo $gsi->getProductGroupList("search_part_number_q", $search_part_number_q, "100%", false, "form-control select2"); ?>
					</div>
					<div class="col-lg-3 col-12">
						<label for="Name" class="control-label">Item Name</label>
						<input type="text" class="form-control" id="search_product_q" name="search_product_q" value="<?php echo $search_product_q;?>" placeholder="Item Name">
					</div>
					<div class="col-lg-3 col-12">
						<label for="Postcode" class="control-label">&nbsp;</label><br>
						<button type="submit" id='submit' class="submit btn btn-success">Search
							<i class="fas fa-sync-alt fa-spin page_load_div" style="display:none;" id="page_load_div"></i>
						</button>
						<button type="button" value="Show All" onclick="javascript:window.location='?<?php echo $show_all_page ?>'" class="btn btn-info">Show All</button>
				</div>
				</div>
				</div>
				
				<div class="col-lg-12 col-12 advance_search_div" id="myDiv" style="margin-top:1%;display:<?=$advance_search_div;?>">
				<div class="row">
					<div class="col-lg-3 col-12">
						<label for="Name" class="control-label">Part Number</label>
						<?php echo $gsi->getProductGroupList("search_part_number", $search_part_number, "100%", false, "form-control select2"); ?>
					</div>
					<div class="col-lg-3 col-12">
						<label for="Name" class="control-label">Category</label>
						<?php echo $gsi->getCategoryList("search_category", $search_category, "100%", false, "form-control select2"); ?>
					</div>
					<div class="col-lg-3 col-12">
						<label class="control-label">Is Taxable</label>
						<? echo Keycode::getKeycodeListValue("is_taxable", $is_taxable, $width = "100%", "Please Select", "id", "code", "tax_code","","form-control",false,""); ?>
					</div>
					<div class="col-lg-3 col-12">
						<label for="Name" class="control-label">Item Name</label>
						<input type="text" class="form-control" id="search_product_name" name="search_product_name" value="<?php echo $search_product_name;?>" placeholder="Item Name">
					</div>
					<div class="col-lg-3 col-12">
						<label for="Name" class="control-label">Barcode</label>
						<input type="text" class="form-control" id="search_barcode" name="search_barcode" value="<?php echo $search_barcode;?>" placeholder="Barcode">
					</div>
					<div class="col-lg-3 col-12">
						<label for="Name" class="control-label">Sales Item Code</label>
						<input type="text" class="form-control" id="search_sales_item_code" name="search_sales_item_code" value="<?php echo $search_sales_item_code;?>" placeholder="Sales Item Code">
					</div>
					<div class="col-lg-3 col-12">
						<label for="Name" class="control-label">Description</label>
						<input type="text" class="form-control" id="search_description" name="search_description" value="<?php echo $search_description;?>" placeholder="Description">
					</div>
					<div class="col-lg-3 col-12">
					<label for="Postcode" class="control-label">&nbsp;</label><br>
					<button type="submit" id='submit' class=" submit btn btn-success">Search
						<i class="fas fa-sync-alt fa-spin page_load_div" style="display:none;" id="page_load_div"></i>
					</button>
					<button type="button" value="Show All" onclick="javascript:window.location='?<?php echo $show_all_page ?>'" class="btn btn-info">Show All</button>
				</div>
				</div>
				</div>
				
		</div>
	</div>
</form>
<!-- /.search form -->

<script>
 $(document).ready(function() {
	$('#product_template_id, #search_part_number_q , #search_category , #is_taxable').on('change', function() {
    $(".submit").click();
});

$(function () {
    $('#search_form').submit(function (e) {
        // Check if at least one radio button is checked
        if (!$("input[name='quick_search']:checked").val() && !$("input[name='advance_search']:checked").val()) {
            e.preventDefault(); // Prevent form submission
            alert('Please select Quick Search or Advance Search');
        } else {
            $(".submit").attr("disabled", true);
            $('.page_load_div').show();
        }
    });
});
            var checkbox1 = $('#checkbox1');
            var checkbox2 = $('#checkbox2');

            // Check if there's a saved value in local storage and update checkboxes
            var checkbox1State = localStorage.getItem('checkbox1State');
            var checkbox2State = localStorage.getItem('checkbox2State');
            if (checkbox1State === 'checked') {
                checkbox1.prop('checked', true);
            }
            if (checkbox2State === 'checked') {
                checkbox2.prop('checked', true);
				 $('.quick_search_div').hide();
                 $('.advance_search_div').show();
            }

            // Listen for checkbox click events
            checkbox1.on('click', function() {
                if (this.checked) {
                   
					$('#checkbox2').prop('checked', false);
					  $('.quick_search_div').show();
                       $('.advance_search_div').hide();
					    localStorage.setItem('checkbox1State', 'checked');
						 localStorage.removeItem('checkbox2State');
                } else {
                    localStorage.removeItem('checkbox1State');
                }
            });

            checkbox2.on('click', function() {
                if (this.checked) {
                    
					$('#checkbox1').prop('checked', false);
					 $('.quick_search_div').hide();
                      $('.advance_search_div').show();
					  localStorage.setItem('checkbox2State', 'checked');
					  localStorage.removeItem('checkbox1State');
                } else {
                    localStorage.removeItem('checkbox2State');
                }
            });
			
			<?if($quick_search == '1'){?>
				 localStorage.removeItem('checkbox2State');
				 checkbox2.prop('checked', false);
				 $('.advance_search_div').hide();
				 $('.quick_search_div').show();
			<?}?>
});
 

</script>