@extends('layouts.app')
@section('title')
Book - {{$ebook->title}}
@parent
@stop
@section('content')
<!----Banner Section Starts----> 
@include('layouts.ebook_volume_form_header_section')    	
<!----Banner Section Starts----> 

<!----Main Section Starts (where all content bodies exist)----> 
<main>
  
  <section>
    <div class="container">
      <div class="row">
        <div class="col-md-12 listing" id="printtopscroll">
		
          <h2 class="h4">Library / Institutional-User Purchase Form</h2>
		  	<hr>
          	 <div class="card bigbox-hvr-slow">
				  <div class="card-body px-5 mt-3">
				  
				  
				   @if ($errors->any())
					
						<div class="form-row">
						<div class="form-group col-md-12 p-0 m-0">				
				   
							<div class="alert alert-danger m-0">	
							  <strong>Whoops!</strong> There were some problems with your input.
							  <ul>
									@foreach ($errors->all() as $error)
										<li>{{ $error }}</li>
									@endforeach
								</ul>
							</div>
							
						</div>
						</div>	
					
					@endif
				  
	  

  
   
   @if (Session::has('thankyou'))
      <div class="alert alert-success alert-dismissible fade show" data-auto-dismiss="5000" role="alert">
      <b>SuccessFull</b>{{ Session::get('thankyou') }}         
         <button type="button" class="close" data-dismiss="alert" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      @endif
			
   
   @if (isset($preview))
	
	{{ Form::open(array('url' => 'submit_order_ebook/'.$ebook_volume_details[0]->ebook_volume_id)) }}
<div class="table-responsive">   
<table class="table table-striped border">

<tbody>
	<tr><td width="300" class="oddrowcolor border-none"><b>Name:</b></td><td class="oddrowcolor border-none">{{$preview['name']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Email:</b></td><td class="oddrowcolor border-none">{{$preview['email']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Contact Number:</b></td><td class="oddrowcolor border-none">{{$preview['phone']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Country:</b></td><td class="oddrowcolor border-none">{{$preview['country']}}</td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>City:</b></td><td class="oddrowcolor border-none">{{$preview['city']}}</td></tr>
@if(!empty($preview['zip']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Zip/Postal Code:</b></td><td class="oddrowcolor border-none">{{$preview['zip']}}</td></tr>
@endif
	<tr><td width="300" class="oddrowcolor border-none"><b>Organization Name:</b></td><td class="oddrowcolor border-none">{{$preview['organization_name']}}</td></tr>
@if(!empty($preview['organization_ips']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Organization IPs:</b></td><td class="oddrowcolor border-none">{{$preview['organization_ips']}}</td></tr>
@endif
	<tr><td width="300" class="oddrowcolor border-none"><b>Location/Address:</b></td><td class="oddrowcolor border-none">{{$preview['address']}}</td></tr>
@if(!empty($preview['comments']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Commnets:</b></td><td class="oddrowcolor border-none">{{$preview['comments']}}</td></tr>
@endif

	@if(!empty($preview['promo_code']))
					
		@if (!empty($preview['discounted_amount']))
			<tr><td width="170"><b>Promo Code:</b></td><td>{{$preview['promo_code']}}</td></tr>
		@else
			<tr><td width="170"><b>Promo Code:</b></td><td><font color="red"><i>Invalid Promo Code</i></font></td></tr>
		@endif
	
	@endif
	
	<tr><td width="300" class="oddrowcolor border-none"><b>Total Amount:</b></td><td class="oddrowcolor border-none">{{$preview['total_amount']}}<strong> $</strong></td></tr>
	@if (!empty($preview['discounted_amount']) && !empty($preview['promo_code']))
	<tr><td width="300" class="oddrowcolor border-none"><b>Discount Amount:</b></td><td class="oddrowcolor border-none">{{$preview['discounted_amount']}}<strong> $</strong></td></tr>
	<tr><td width="300" class="oddrowcolor border-none"><b>Discount Percentage:</b></td><td class="oddrowcolor border-none">{{$preview['discount_percentage']}}<strong> %</strong></td></tr>
	@endif
	
</tbody>

</table>	
</div>		


<input type="hidden" name="name" value="{{$preview['name']}}" />
<input type="hidden" name="email" value="{{$preview['email']}}" />
<input type="hidden" name="phone" value="{{$preview['phone']}}" />
<input type="hidden" name="country" value="{{$preview['country']}}" />
<input type="hidden" name="city" value="{{$preview['city']}}" />
<input type="hidden" name="zip" value="{{$preview['zip']}}" />
<input type="hidden" name="organization_name" value="{{$preview['organization_name']}}" />
<input type="hidden" name="organization_ips" value="{{$preview['organization_ips']}}" />
<input type="hidden" name="address" value="{{$preview['address']}}" />
<input type="hidden" name="comments" value="{{$preview['comments']}}" />
<input type="hidden" name="discounted_amount" value="{{$preview['discounted_amount']}}" />
<input type="hidden" name="total_amount" value="{{$preview['total_amount']}}" />
<input type="hidden" name="promo_code" value="{{$preview['promo_code']}}" />


{{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}

		{{ Form::close() }}		
   @else
	   

		{{ Form::open(array('url' => 'preview_order_ebook/'.$ebook_volume_details[0]->ebook_volume_id)) }}
		
		
		
        <div class="form-row">
			<div class="form-group col-md-6">
            <label class="control-label">Name: *</label>
            <input type="text" maxlength="50" name="name" id="control-label" size="60" value="{{old('name')}}" class="form-control" required = 'required'>
			@if ($errors->has('name'))															
				<label class="control-label text-danger">{{ $errors->first('name') }} </label>
			@endif	
         </div>
         <div class="form-group col-md-6" >
            <label for="edit-email">Email: *</label>
            <input type="text" maxlength="100" name="email" id="edit-email" size="60" value="{{old('email')}}" class="form-control" required = 'required'>
			@if ($errors->has('email'))															
				<label class="control-label text-danger">{{ $errors->first('email') }} </label>
			@endif	
         </div>
		 </div>
         <div class="form-row">
			<div class="form-group col-md-6">
            <label for="edit-phone">Phone: *</label>
            <input type="text" maxlength="50" name="phone" id="edit-phone" size="60" value="{{old('phone')}}" class="form-control" required = 'required'>
			@if ($errors->has('phone'))															
				<label class="control-label text-danger">{{ $errors->first('phone') }} </label>
			@endif	
         </div>
         <div class="form-group col-md-6" id="edit-cmbCountryCode-wrapper">
            <label class="control-label">Country: *</label>
             <select class="form-control" id="country" name="country[]"  required = 'required'>
                <option value="">Country</option>
             @foreach ($country as $countries)
                <option value="{{$countries->printable_name}}"  @if(old('country') == $countries->printable_name) {{ 'selected' }}
                @elseif(isset($selected_authors->country) and ($selected_authors->country == $countries->printable_name))) {{ 'selected' }} @endif> {{$countries->printable_name}}</option>
            @endforeach
            </select>
         </div>
		  </div>
         <div class="form-row">
			<div class="form-group col-md-6" id="edit-city-wrapper">         
            <label for="edit-city">City: *</label>
            <input type="text" maxlength="50" name="city" id="edit-city" size="60" value="{{old('city')}}" class="form-control" required = 'required'>
			@if ($errors->has('city'))															
				<label class="control-label text-danger">{{ $errors->first('city') }} </label>
			@endif	
         </div>
         <div class="form-group col-md-6" id="edit-zip-wrapper">
            <label for="edit-zip">Zip/Postal Code: </label>
            <input type="text" maxlength="50" name="zip" id="edit-zip" size="60" value="{{old('zip')}}" class="form-control">
			@if ($errors->has('zip'))															
				<label class="control-label text-danger">{{ $errors->first('zip') }} </label>
			@endif	
         </div>
		  </div>
         <div class="form-row">
			<div class="form-group col-md-6" id="org_name-wrapper">         
            <label for="org_name">Name of Institution/Organization: *</label>
            <input type="text" maxlength="200" name="org_name" id="org_name" size="60" value="{{old('org_name')}}" class="form-control" required = 'required'>
			@if ($errors->has('org_name'))															
				<label class="control-label text-danger">{{ $errors->first('org_name') }} </label>
			@endif	
         </div>
        <div class="form-group col-md-6" id="org_location-wrapper">
         
            <label for="org_location">Location/Address:</label>
            <input type="text" maxlength="200" name="address" id="org_location" size="60" value="{{old('address')}}" class="form-control">
			@if ($errors->has('address'))															
				<label class="control-label text-danger">{{ $errors->first('address') }} </label>
			@endif	
         </div>
		  </div>
         <div class="form-row">			
		 <div class="form-group col-md-6" id="edit-org-ip-wrapper">
            <label for="edit-org-ip">IPs:</label>
            <div class="resizable-textarea">
               <span>
                  <textarea cols="60" rows="5" name="org_ip" id="edit-org-ip" class="form-control">{{old('org_ip')}}</textarea>
                  <div  style="margin-right: 351px;"></div>
               </span>
            </div>
         </div>
         <div class="form-group col-md-6" id="edit-comments-wrapper">
            <label for="edit-comments">Comment: </label>
            <div class="resizable-textarea">
               <span>
                  <textarea cols="60" rows="5" name="comments" id="edit-comments" class="form-control"  >{{old('comments')}}</textarea>
                  <div  style="margin-right: 351px;"></div>
				  
               </span>
			   @if ($errors->has('comments'))															
				<label class="control-label text-danger">{{ $errors->first('comments') }} </label>
				@endif	
            </div>
         </div>
		  </div>
		
		
        <div class="form-row">
			<div class="form-group col-md-6">
				<div class="form-group" id="validate_promocode">
					<label for="edit-promo-code">Promo Code:</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="form-group col-md-12">
	              <!--label for="password" class="col-md-4  col-form-label text-md-right">Captcha</label-->
	              
	                  <div class="g-recaptcha" data-sitekey="{{ env('SETTINGS_GOOGLE_RECAPTCHA_SITE_KEY') }}"></div>
	                  @if ($errors->has('g-recaptcha-response'))
	                      <span class="invalid-feedback text-center" style="display: block;">
	                          <strong>{{ $errors->first('g-recaptcha-response') }}</strong>
	                      </span>
	                  @endif
	              
	        </div>
		
	
		<div class="form-group text-center mt-3 w-100"> 
			<hr>
			<input class="btn btn-primary" id="preview" type="submit" value="Preview">
		</div>
		
   
		{{ Form::close() }}		
	
   
   @endif
   


	 
	  
	</div>
				
        </div>
    
      </div>
    </div>
  </section>
  
<script>
 	
$(document).ready(function()
{ 
	@if(!empty($promo_code))
		validate_promo_code();
	@endif

$("html, body").animate({scrollTop: $("#printtopscroll").offset().top}, 200);
});

$( "#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 () 
		{
			//console.log(data);
			$( "#validate_promocode" ).removeClass('alert alert-success');
			$( "#validate_promocode" ).removeClass('alert alert-danger');
			$( "#validate_promocode" ).addClass('alert alert-warning');
			
		}
       
    });    
   
}
	
</script>

  
</main>
@endsection
