<section class="wpcargo-container">
	<div class="wpcargo-row">
		<div class="wpcargo-col-md-12">
			<div id="parcel-rate" class="wpcsr-card">
				<div class="wpcsr-card-header">
					<?php if( $rate_logo ): ?>
						<div class="header-logo">
							<img class="wpcsr_logo" src="<?php echo $rate_logo; ?>" >
						</div>	
					<?php endif; ?>	
					<div class="header-content<?php echo ( !$rate_logo ) ? '-full' : '' ; ?>">
						<span class="label"><strong><?php echo wpcsr_shipment_rate_label(); ?></strong></span>
						<span class="rate"><?php echo $rateInfo->brand; ?></span><br>
						<span id="total_rate" class="rate">
							<strong><?php echo wpcsr_total_label(); ?></strong>
							<?php echo wpcsr_currency().' <span class="t_rate">'.format_wpcsr_currency( $total_cost, false ).'</span>'; ?>
						</span>
					</div>                
				</div>
				<div class="wpcsr-card-body wpcsr-rate-list">
					<div class="wpcargo-row">
						<div class="wpcargo-col-md-4 wpcsr-details">
							<h4><?php echo wpcsr_shipment_rate_details_label(); ?></h4>
							<table>
								<tr>
									<th class="label"><strong><?php echo wpcsr_service_variation_label(); ?>:</strong></th>
									<td class="service"><?php echo $rateInfo->service; ?></td>
								</tr>
								<tr>
									<th class="label"><strong><?php echo wpcsr_type_label(); ?>:</strong></th>
									<td class="type"><?php echo $delivery_info->title; ?></td>
								</tr>
								<tr>
									<th class="label"><strong><?php echo wpcsr_description_label(); ?>:</strong></th>
									<td class="desc"><?php echo $delivery_info->description; ?></td>
								</tr>
								<tr>
									<th class="label"><strong><?php echo wpcsr_zone_variation_label(); ?>:</strong></th>
									<td class="zone"><?php echo $rateInfo->zone; ?></td>
								</tr>
								<tr>
									<th class="label"><strong><?php echo wpcsr_origin_label(); ?></strong></th>
									<td class="origin"><?php echo $origin; ?> - <?php echo $origin_postcode; ?></td>
								</tr>
								<tr>
									<th class="label"><strong><?php echo wpcsr_destination_label(); ?></strong></th>
									<td class="destination"><?php echo $destination; ?> - <?php echo $destination_postcode; ?></td>
								</tr>
							</table>
						</div>
						<div class="wpcargo-col-md-4 wpcsr-payment-details">
							<h4><?php echo wpcsr_payment_details_label(); ?></h4>
							<table>
								<tr>
									<th class="label"><strong><?php echo wpcsr_weight_label(); ?>:</strong></th>
									<td class="weight float_right"><?php echo format_wpcsr_currency($package_weight).' '.wpcsr_weight_unit(); ?></td>
								</tr>
								<tr>
									<th class="label"><strong><?php echo wpcsr_rate_label(); ?>:</strong></th>
									<td class="shipping_rate float_right" ><?php echo format_wpcsr_currency( $rate_price, true ); ?></td>
								</tr>
								<tr class="in-protection <?php echo ($is_protected) ? '' : 'hide-element' ; ?>">
									<th class="label"><strong><?php echo wpcsr_protection_variation_label(); ?></strong></th>
									<td class="shipping_protection float_right"><?php echo format_wpcsr_currency( $rateInfo->rate_protection, true ); ?></td>
								</tr>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>
<form id="wpcsr-create-order" method="post" action="" enctype="multipart/form-data" >
	<?php wp_nonce_field( 'wpcsr_create_order_action', 'wpcsr_create_order_nonce' ); ?>
	<?php do_action('wpcsr_create_order_before_form_wrapper'); ?>
	<input type="hidden" name="wpcsr_rate" value="<?php echo $rate_id; ?>">
	<input type="hidden" name="wpcsr_origin" value="<?php echo $origin; ?>">
	<input type="hidden" name="wpcsr_origin_postcode" value="<?php echo $origin_postcode; ?>">
	<input type="hidden" name="wpcsr_destination" value="<?php echo $destination; ?>">
	<input type="hidden" name="wpcsr_destination_postcode" value="<?php echo $destination_postcode; ?>">
	<input type="hidden" name="weight" value="<?php echo $package_weight; ?>">
	<div class="wpcargo-container">
		<div id="parcel-container" class="wpcargo-row">
			<div id="shipper-info" class="section wpcargo-col-md-6">
				<h4><?php echo wpcsr_shipper_information_label(); ?></h4>
				<?php           
					do_action('wpcsr_shipper_after_title', $rate_id);
					do_action('wpc_shipper_before_content');
					$WPCCF_Fields->convert_to_form_fields( $shipper_fields );                
					do_action('wpcsr_shipper_after_content', $rate_id); 
				?>
				<?php if( !is_user_logged_in() ): ?>
					<?php $wpcfe_admin = get_option( 'wpcfe_admin' ) ? : "#"; ?>
					<p style="margin-top: 10px;">
						<a href="<?php echo get_the_permalink( $wpcfe_admin ); ?>"> <?php echo wpcsr_signin_here_label(); ?></a>
					</p>
				<?php endif; ?>
			</div>
			<?php do_action('wpcsr_after_shipper_info', $rate_id); ?>
			<div id="receiver-info" class="section wpcargo-col-md-6" >
				<h4><?php echo wpcsr_receiver_information_label(); ?></h4>
				<?php              
					do_action('wpcsr_receiver_after_title', $rate_id);
					do_action('wpc_receiver_before_content');
					$WPCCF_Fields->convert_to_form_fields( $receiver_fields );
					do_action('wpcsr_receiver_after_content', $rate_id); 
				?>
			</div>
			<?php do_action('wpcsr_after_receiver_info', $rate_id); ?>
			<div id="shipment_info" class="section wpcargo-col-md-12" style="display:block; clear:both;" >
				<h4><?php echo wpcsr_shipment_information_label(); ?></h4>
				<div class="row">
					<?php 
						do_action('wpcsr_before_shipment_info', $rate_id);
						$WPCCF_Fields->convert_to_form_fields( $shipment_fields, '', 'col-md-6' );
						do_action('wpcsr_shipment_after_content', $rate_id);
					?>
				</div>
			</div>
			<?php do_action('wpcsr_after_shipment_info', $rate_id); ?>
			<div id="parcel-info" class="section wpcargo-col-md-12">
				<h4><?php echo wpcsr_parcel_details_label(); ?></h4>
				<?php do_action('wpcsr_before_parcel', $rate_id); ?>
				<div id="wpcsr-parcels" class="table-responsive">
					<table class="table wpcargo-table-wrapper wpcsr-parcel-wrapper wpcargo-container" data-repeater-list="wpc-multiple-package">
						<thead>
							<tr>
								<?php foreach( wpcargo_package_fields() as $package_key => $package_value ): ?>
									<th><?php esc_html_e($package_value['label'], 'wpcargo-shipment-rate'); ?></th>
								<?php endforeach; ?>
							</tr>
						</thead>
						<tbody>
							<?php if( !empty( $wpcsr_parcels ) ): ?>
								<?php foreach ( $wpcsr_parcels as $parcel ) : ?>
									<tr data-repeater-item>
										<?php foreach ( wpcargo_package_fields() as $key => $field_value): ?>
											<?php
												$value = array_key_exists( $key, $parcel ) ? $parcel[$key] : '' ;
												if( $key == 'wpc-pm-piece-type' ){
													$value = $package_type;
												}
												$class = $field_value['field'] == 'select' ? 'form-control browser-default custom-select' : 'form-control';
												$extra = $key == 'wpc-pm-value' ? 'parcel-value-input' : '';
												$disabled = !empty( $value ) ? 'disable-input' : '';
											?>
											<td><?php echo wpcargo_field_generator( $field_value, $key, $value, $class.' '.$extra.' '.$disabled ); ?></td>
										<?php endforeach; ?>
									</tr>
								<?php endforeach; ?>
							<?php else: ?>
								<i></i>
							<?php endif; ?>   
						</tbody>
					</table>
					<p class="alert alert-danger"><?php echo wpcsr_parcel_subcharges_notice( $rateInfo ); ?></p>
				</div>
				<?php do_action('wpcsr_after_parcel_content', $rate_id); ?>
			</div>
			<?php do_action('wpcsr_after_parcel_info', $rate_id); ?>
			<?php if( $rateInfo->rate_protection  ): ?>
				<div id="wpcsr-protection-section" class="wpcargo-col-md-12">
					<div id="protection-header" class="hide-element">
						<h4 class="wpcsr-dynamic-parcel"><?php echo  wpcsr_protection_header( $rateInfo ); ?></h4>
						<p class="protection-subheading"><?php echo wpcsr_protection_subheader( $rateInfo ); ?></p>
					</div>
					<div id="protection-content" class="hide-element">
						<div id="protection-body">
							<div class="wpcsr-check-protection-wrap check-yes-protection">
								<div class="wpcsr-check-icon wpcsr-check-content">
									<input id="protection-yes" class="protection-option form-check-input" type="radio" name="protection" value="1" <?php checked( $is_protected, 1); ?>>
									<label for="protection-yes" class="form-check-label"><?php echo  wpcsr_yes_protection_option( $rateInfo ); ?></label>
								</div>
							</div>
							<div class="wpcsr-check-protection-wrap check-no-protection">
								<div class="wpcsr-check-icon wpcsr-check-content">
									<input id="protection-no" class="protection-option form-check-input" type="radio" name="protection" value="0" <?php checked( $is_protected, 0); ?>>
									<label for="protection-no" class="form-check-label"><?php echo wpcsr_no_protection_option( $rateInfo ); ?></label>
								</div>
							</div>
						</div>
						<div class="zoom-in alert-popup alert alert-danger">
							<p><?php echo wpcsr_recommend_protection( $rateInfo ); ?></p>
						</div>
					</div>
					<div id="protection-footer">
						<p class="find-desc wpcsr_col_float">
							<span><?php echo wpcsr_protection_covered_header( $rateInfo ); ?></span>
							<a class="find-more-button wpcsr-float-right wpcargo-btn wpcargo-btn-sm wpcargo-btn-primary"><?php echo wpcsr_read_more_label(); ?></a>
						</p>                
					</div>
				</div> 
			<?php endif; ?>
			<?php do_action('wpcsr_create_order_after_form_wrapper', $rate_id ); ?>
			<div id="disagree-alert" class="alert-popup wpcargo-col-md-12 mb-4" style="display: none;">
				<p class="alert alert-danger"><?php echo wpcsr_agreement_information_message(); ?></p>
			</div>
			<div class="submit-wrapper form-check wpcargo-col-md-12">    
				<?php if( $prohibited_restricted ): ?>
					<input id="form-agreement" type="checkbox" name="agree" value="yes" class="form-check-input" /> <label for="form-agreement" ><?php echo wpcsr_agreement_checkbox_message(); ?></label>
				<?php endif; ?>
				<input id="submit-order" class="wpcargo-btn wpcargo-btn-sm wpcargo-btn-primary wpcsr-float-right" type="submit" name="submit" value="<?php echo wpcsr_submit_order_label(); ?>" />
			</div>
		</div>
	</div> <!-- wpcargo-container -->
</form>
<!-- Protection More Info -->
<div id="wpcsr-protection-info" class="wpcsr-modal hide-element">
    <div class="wpcsr-modal-content">
        <span class="exit-modal">&times;</span>
        <div class="header"></div>
        <div class="body">
            <?php do_action( 'wpcsr_protection_covered_information', $rateInfo ) ?>
        </div>                          
    </div>                  
</div>
<?php
    // postcode autocomplete based on the quote rate form
    if( !empty( $origin_postcode ) && !empty( wpcsr_billing_postcode_meta() ) ){
        ?>
        <script>
        jQuery('input#<?php echo wpcsr_billing_postcode_meta(); ?>').val(<?php echo $origin_postcode; ?>);    
        </script>
        <?php
    }
    if( !empty( $destination_postcode ) && !empty( wpcsr_shipping_postcode_meta() ) ){
        ?>
        <script>
        jQuery('input#<?php echo wpcsr_shipping_postcode_meta(); ?>').val(<?php echo $destination_postcode; ?>);    
        </script>
        <?php
    }
?>
<?php if( !is_user_logged_in() ): ?>
    <div id="wpcsr-login-form-popup" class="hide-element">
        <div id="wpcsr-popup-content">
            <div id="user-data" style="display: none !important;">
                <?php $wpcsr_parcels = !empty( $wpcsr_parcels ) ? htmlentities(serialize($wpcsr_parcels)) : htmlentities(serialize(array())) ; ?> 
                <data id="shipping_rate"><?php echo $rate_id; ?></data>
                <data id="shipping_protection"><?php echo $is_protected; ?></data>
                <data id="shipping_package"><?php echo $wpcsr_parcels; ?></data>
                <data id="shipping_origin"><?php echo $origin_postcode; ?></data>
                <data id="shipping_destination"><?php echo $destination_postcode; ?></data>
                <data id="shipping_nonce"><?php echo $_POST['wpcsr_create_order_field']; ?></data>
            </div>
            <?php include_once( WPCSR_PATH.'templates/login.php'); ?>
        </div>
    </div>
    <div id="wpcsr-registration-form-popup" class="hide-element">
        <div id="wpcsr-popup-content">
            <?php include_once( WPCSR_PATH.'templates/registration-form.tpl.php'); ?>
        </div>
    </div>
<?php endif; ?>
<!-- Rate More Info -->
<div id="wpcsr-prohibited-docs" class="wpcsr-modal hide-element">
    <div class="wpcsr-modal-content">
        <span class="exit-modal">&times;</span>
        <div class="header"></div>
        <div class="body">
            <?php do_action( 'wpcsr_prohibited_items_docs', $rateInfo ) ?>
        </div>                          
    </div>                  
</div>
