<h2 class="h4">Issue Order Form</h2>
<hr>
<div class="card bigbox-hvr-slow">
<div class="card-body">
	   
{{ Form::open(array('url' => 'purchase_full_issue/'.$issue->issue_id)) }}
    @csrf
 <div class="row">
 	<div class="col-md-6"> 		

	<h5>Journal Details:</h5>
	<hr>
	<div class="form-group row m-0">
		<label class="control-label col-md-4 p-2 border-bottom"><strong>Journal:</strong></label>
		<label class="control-label col-md-8 p-2 border-bottom">{{$journal->title}}</label><br>
		<label class="control-label col-md-4 p-2 border-bottom"><strong>Volume:</strong></label>
		<label class="control-label col-md-8 p-2 border-bottom">{{$volume->volume_name}}</label><br>
		<label class="control-label col-md-4 p-2 border-bottom"><strong>Issue:</strong></label>
		<label class="control-label col-md-8 p-2 border-bottom">{{$issue->title}}</label><br>
		<label class="control-label col-md-4 p-2 border-bottom"><strong>Year:</strong></label>
		<label class="control-label col-md-8 p-2 border-bottom">{{$volume->year}}</label><br>
		<label class="control-label col-md-4 p-2 border-bottom"><strong>Price:</strong></label>
		<label class="control-label col-md-8 p-2 border-bottom">${{$issue->price}}</label><br>
		<div class="form-group" id="validate_promocode">
		<label for="edit-promo-code"><strong>Promo Code:</strong></label>
		<input class="form-control" type="text" maxlength="128" id="promo_code" name="promo_code" size="60" value="{{ old('promo_code', isset($promo_code) ? $promo_code : '') }}" class="form-text">
		<span id="promo_code_message"></span>
		</div>
	</div>				

 	</div>
 	<div class="col-md-6">
 		
	 <h5>Contact Details</h5>
		 <hr>
		
		
		@php 
			$first_name_value = '' ;
			$last_name_value = '';
			$email_name_value = '';
		@endphp
   
		<div class="form-row">
			<div class="form-group m-0">
				<label class="control-label">First Name: *</label>
				
				@if(request('first_name'))
					@php $first_name_value = request('first_name'); @endphp
				@elseif($detail['first_name'])
					@php $first_name_value = $detail['first_name']; @endphp
				@endif
				
			<input type="text" maxlength="50" name="first_name" size="60" value="{{$first_name_value}}" class="form-control">
			<div class="text-danger">{{ $errors->first('first_name') }}</div>
			</div>
			<div class="form-group m-0">
				<label for="edit-last_name">Last Name: *</label>
				@if(request('last_name'))
					@php $last_name_value = request('last_name'); @endphp
				@elseif($detail['last_name'])
					@php $last_name_value = $detail['last_name']; @endphp
				@endif
				<input type="text" maxlength="100" name="last_name" id="" size="60" value="{{$last_name_value}}" class="form-control" >
				<div class="text-danger">{{ $errors->first('last_name') }}</div>
			</div>

			<div class="form-group m-0">
				<label for="edit-email">Email: *</label>
				@if(request('email'))
					@php ($email_name_value = request('email')) @endphp
				@elseif($detail['email'])
					@php ($email_name_value = $detail['email']) @endphp
				@endif
				<input type="text" maxlength="50" name="email" id="" size="60" value="{{$email_name_value}}" class="form-control">
				<div class="text-danger">{{ $errors->first('email') }}</div>
			</div>
			
			<div class="form-group mt-2 text-center">              <div class="form-group row mt-3 w-100"> 

                      <div class="col-auto mx-auto w-100 d-flex ">
                          <div class="col-md-6 text-right">
                              <div class="captcha">                                       
                                  <span>{!! captcha_img() !!}</span>             
                              </div>
                          </div>
                          <div class="col-md-6">                                        
                              <button type="button" class="btn btn-danger" class="refresh-captcha" id="refresh-captcha">
                                  &#x21bb;
                              </button> 
                          </div>
                      </div>
                      <div class="form-group ml-3 mt-2">
                          <input id="captcha" type="text" class="form-control" placeholder="Enter Captcha" name="captcha">
                          @if ($errors->has('captcha'))

                            <span class="invalid-feedback" style="display: block;">

                                <strong>{{ $errors->first('captcha') }}</strong>

				  </span>
			  @endif
			</div>              </div>			
          	</div>
			<div class="form-group text-center w-100">
			<hr>
				<a class="btn btn-outline-dark" href="/issue/{{$issue->issue_id}}">Back</a>
				<input class="btn btn-dark" name="issue_purchase_form" type="submit" value="Preview">	
			</div>
			
		</div>
		
		
		
		</div>
 	
	  
	</div>
   
		{{ Form::close() }}	
				
        </div>
    
      </div>
	  <script>
	$("#promo_code").keyup(function(e) {
		setTimeout(function() {
			response = validate_promo_code();
		}, 2000);

	});

	function validate_promo_code() {
		var promo_code = $("#promo_code").val();
		var response = 0;

		$.ajax({
			type: "POST",
			data: {
				"_token": "{{ csrf_token() }}",
				"promo_code": promo_code,
				ajax: true
			},
			success: function(data) {
				console.log(data);
				$("#promo_code_message").html(data[1]);
				if (data[0]) {
					$("#validate_promocode").removeClass('alert alert-danger');
					$("#validate_promocode").removeClass('alert alert-warning');
					$("#validate_promocode").addClass('alert alert-success');
				} else {
					$("#validate_promocode").removeClass('alert alert-success');
					$("#validate_promocode").removeClass('alert alert-warning');
					$("#validate_promocode").addClass('alert alert-danger');
				}
			},
			error: function() {
				$("#validate_promocode").removeClass('alert alert-success');
				$("#validate_promocode").removeClass('alert alert-warning');
				$("#validate_promocode").addClass('alert alert-danger');
			},
			beforeSend: function() {
				$("#validate_promocode").removeClass('alert alert-success');
				$("#validate_promocode").removeClass('alert alert-danger');
				$("#validate_promocode").addClass('alert alert-warning');
			}
		});

	}
</script>
   