
<!-- Modal -->
<div id="access_{{$value->user_access_id}}" class="modal fade" role="dialog">
  <div class="modal-dialog modal-lg">
  <form method="POST" action="{{ action('UserAccessController@update', ['user_access_id' => $value->user_access_id]) }}" enctype="multipart/form-data">	@method('PUT')	@csrf
  
  <input type="hidden" name="section" value="date_range_form"/>
  
	<!-- Modal content-->
	<div class="modal-content">
	  <div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">&times;</button>
		<h4 class="modal-title">Acces Date Range</h4>
	  </div>
	  <div class="modal-body text-left">
	  
		<div class="form-row">	
		
				<div class="form-group col-md-4">	
						<label>Date From : <a href="javascript:void(0);" onclick="reset_access_from_date();">reset</a></label>
						<input id="access_date_from_window" name="access_date_from" class="form-control flatpickr" placeholder="Pick date" data-input data-dateFormat="F-j-Y" required="required" @if($value->access_date_from != "") value="{{strftime('%d-%B-%Y',$value->access_date_from)}}" @else value="" @endif>
				</div>	
				
				<div class="form-group col-md-4">	
						<label>Date To : <a href="javascript:void(0);" onclick="reset_access_to_date();">reset</a></label>
						<input id="access_date_to_window" name="access_date_to" class="form-control flatpickr" placeholder="Pick date" data-input data-dateFormat="F-j-Y" required="required" @if($value->access_date_to != "") value="{{strftime('%d-%B-%Y',$value->access_date_to)}}" @else value="" @endif>
				</div>	
				
				<div class="form-group col-md-4" style="margin-top:35px;">	
						<label><input name="perpetual" id="perpetual_window" type="checkbox" value="1" @if($value->perpetual == 1) checked @endif> Perpetual</label>
				</div>	
		</div>	
		
		<div class="form-row">	
		@if ($value->perpetual == 1)
			<div class="form-group col-md-4"></div>
			<div class="form-group col-md-4"></div>
			<div class="form-group col-md-4">Perpetual</div>
		@else
			<div class="form-group col-md-4">	
			@if( $value->access_date_from != null)
				<label>Date From  : </label>&nbsp;<label>{{strftime("%d-%B-%Y",$value->access_date_from)}}</label>
			@else
				---
			@endif	
			</div>	
			
			<div class="form-group col-md-8">	
			@if( $value->access_date_to != null)
				
				@if( $value->access_date_to < time())
					<label>Date To  : </label>&nbsp;<label class="text-danger">{{strftime("%d-%B-%Y",$value->access_date_to)}}	</label>
				@else
					<label>Date To  : </label>&nbsp;<label>{{strftime("%d-%B-%Y",$value->access_date_to)}}	</label>
				@endif	
			@else
				---
			@endif	
			</div>	
		@endif
					
		</div>	

		<div class="form-row w-100">
			<h4 class="modal-title">User Access</h4>
			@php 
				$access_type_on = explode(',',$value->access_type_on); 
			@endphp
			 <input type="checkbox" name="access_type_on[]" value="v" @if (in_array('v', $access_type_on)) checked="checked" disabled="disabled" @endif /> Volume <br /> 
			
			 <input type="checkbox" name="access_type_on[]" value="e" @if (in_array('e', $access_type_on)) checked disabled="disabled" @endif /> eBook Volume <br /> 
			 
			 <input type="checkbox" name="access_type_on[]" value="i" @if (in_array('i', $access_type_on)) checked disabled="disabled" @endif/> Issue  <br />
			
			 <input type="checkbox" name="access_type_on[]" value="c" @if (in_array('c', $access_type_on)) checked disabled="disabled" @endif/> Chapter <br /> 
			
			 <input type="checkbox" name="access_type_on[]" value="a" @if (in_array('a', $access_type_on)) checked disabled="disabled" @endif/> Article <br /> 
			
		</div>
		
	  </div>
	  <div class="modal-footer">
		<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
		@if(isset($request_id))			<button type="submit" class="btn btn-primary" id="ip_range_submit" name="ip_range_submit" value="submit">Submit</button>
		@endif	
	  </div>
	</div>
	
</form>

  </div>
</div>

<script>
$( window ).on( "load", function() {

		if ($("#perpetual_window").is(":checked")) 
		{
			$("#access_date_from_window").prop("readonly", true);
			$("#access_date_to_window").prop("readonly", true);
			// $('#access_date_from_window').val('');
			// $('#access_date_to_window').val('');
		} 
		else 
		{
			$("#access_date_from_window").prop("readonly", false);
			$("#access_date_to_window").prop("readonly", false);
		}
    });

$(function()
{
	$("#perpetual_window").click(function () 
	{
		if ($(this).is(":checked")) {
			$("#access_date_from_window").prop("readonly", true);
			$("#access_date_to_window").prop("readonly", true);
			$('#access_date_from_window').val('');
			$('#access_date_to_window').val('');
		} else {
			$("#access_date_from_window").prop("readonly", false);
			$("#access_date_to_window").prop("readonly", false);
		}
	});	
});
</script>