<?php
if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Single Template for single vehicle page
 * Loaded by plugin via single_template hook
 */

get_header(); ?>

<main id="primary" class="site-main vehicle-single"><div id="main-content"><div class="container">

	<?php
	while ( have_posts() ) :
		the_post();

		$post_id = get_the_ID();
		$mobile_api_metas = get_post_meta( $post_id );
		$mobile_api_meta_exclude = mobile_api_get_meta_exclude();
		$mobile_api_terms = get_the_terms( $post_id, 'mobile_api_vehicle_category' );
		$mobile_api_images = maybe_unserialize( get_post_meta( $post_id, 'mobile_api_images', true ) );

		$mobile_api_seller = maybe_unserialize( get_post_meta( $post_id, 'mobile_api_seller', true ) );
		$mobile_api_vin = get_post_meta( $post_id, 'mobile_api_vin', true );
		$mobile_api_tel = '+'.$mobile_api_seller->phones[0]->internationalPrefix.$mobile_api_seller->phones[0]->nationalPrefix.$mobile_api_seller->phones[0]->number;
		$mobile_api_tel_formatted = '+'.$mobile_api_seller->phones[0]->internationalPrefix.' '.$mobile_api_seller->phones[0]->nationalPrefix.' '.$mobile_api_seller->phones[0]->number;

		$mobile_api_price = maybe_unserialize( get_post_meta( $post_id, 'mobile_api_price', true ) );
		$mobile_api_condition = get_post_meta( $post_id, 'mobile_api_condition', true );
		$mobile_api_mileage = get_post_meta( $post_id, 'mobile_api_mileage', true );
		$mobile_api_power = get_post_meta( $post_id, 'mobile_api_power', true );
		$mobile_api_fuel = get_post_meta( $post_id, 'mobile_api_fuel', true );
		$mobile_api_gearbox = mobile_api_translate_data_value( get_post_meta( $post_id, 'mobile_api_gearbox', true ) );
		$mobile_api_firstRegistration = get_post_meta( $post_id, 'mobile_api_firstRegistration', true );
		$mobile_api_owner = get_post_meta( $post_id, 'mobile_api_numberOfPreviousOwners', true );
		$mobile_api_mobile_url = get_post_meta( $post_id, 'mobile_api_detailPageUrl', true );

		$mobile_api_is_licensed = mobile_api_is_licensed();
		?>

		<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
			<div class="entry-content">
				<div class="vehicle-grid">
					<div class="vehicle-images">
						<button type="button" aria-label="<?php esc_html_e( 'Close image lightbox', 'ad-integration-for-mobile-de-api' ); ?>" class="close-button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false"><path d="m13.06 12 6.47-6.47-1.06-1.06L12 10.94 5.53 4.47 4.47 5.53 10.94 12l-6.47 6.47 1.06 1.06L12 13.06l6.47 6.47 1.06-1.06L13.06 12Z"></path></svg></button>

						<?php
						if ( !empty( $mobile_api_images ) ) :
							?>
							<div class="single-vehicle-slider">
								<figure class="slide">
									<img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title(); ?>">
									<button class="lightbox-trigger" type="button" aria-haspopup="dialog" aria-label="<?php esc_html_e( 'Enlarge image in lightbox', 'ad-integration-for-mobile-de-api' ); ?>"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12"><path fill="#000" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z"></path></svg></button>
								</figure>
								<?php
								foreach ( $mobile_api_images AS $mobile_api_index => $mobile_api_imageObject ) :
									if ( $mobile_api_index == 0 )
										continue;

									$mobile_api_image_array = (array) $mobile_api_imageObject;
									$mobile_api_image = end( $mobile_api_image_array );
									?>
									<figure class="slide">
										<img src="<?php echo esc_url( $mobile_api_image ) ?>" alt="<?php the_title(); ?>">
										<button class="lightbox-trigger" type="button" aria-haspopup="dialog" aria-label="<?php esc_html_e( 'Enlarge image in lightbox', 'ad-integration-for-mobile-de-api' ); ?>"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12"><path fill="#000" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z"></path></svg></button>
									</figure>
									<?php if ( !$mobile_api_is_licensed ) break; ?>
								<?php endforeach; ?>
							</div>

							<?php if ( $mobile_api_is_licensed && count( $mobile_api_images ) > 1 ) : ?>
								<div class="single-vehicle-slider-thumbnails">
									<figure class="slide">
										<img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title(); ?>">
									</figure>
									<?php
									foreach ( $mobile_api_images AS $mobile_api_index => $mobile_api_image ) :
										if ( $mobile_api_index == 0 )
											continue;
										?>
										<figure class="slide">
											<img src="<?php echo esc_html( $mobile_api_image->icon ) ?>" alt="<?php the_title(); ?>">
										</figure>
									<?php endforeach; ?>
								</div>
							<?php endif; ?>
						<?php endif; ?>
					</div>
					<div class="vehicle-summary"><div class="vehicle-content-container">
						<p class="breadcrumbs"><?php echo esc_html( implode( ' › ', wp_list_pluck( $mobile_api_terms, 'name' ) ) ) ?></p>
						<h1 class="entry-title"><?php the_title(); ?></h1>

						<p class="price">
							<span class="woocommerce-Price-amount amount"><bdi><?php echo esc_html( number_format_i18n( $mobile_api_price->consumerPriceGross, 0 ) ) ?> <span class="woocommerce-Price-currencySymbol">€</span></bdi></span>
							<?php
							if ( property_exists( $mobile_api_price, 'consumerPriceNet' ) && property_exists( $mobile_api_price, 'vatRate' ) ) {
								// translators: %s is the formatted price and the vat rate
								echo '<span class="tax-info">'.sprintf( esc_html__( '%s (net)', 'ad-integration-for-mobile-de-api' ), esc_html( number_format_i18n( $mobile_api_price->consumerPriceNet, 2 ) ) ).', '.sprintf( esc_html__( '%s VAT', 'ad-integration-for-mobile-de-api' ), esc_html( round( $mobile_api_price->vatRate ).'%' ) ).'</span>';
							} else
								echo '<span class="tax-info">'.esc_html__( 'VAT not included', 'ad-integration-for-mobile-de-api' ).'</span>';
							?>
						</p>

						<ul class="icon-list">
							<?php if ( $mobile_api_condition == 'USED' ) : ?>
								<li class="mileage dashicons-before dashicons-chart-bar"><small><?php esc_html_e( 'Mileage', 'ad-integration-for-mobile-de-api' ) ?></small> <strong><?php echo esc_html( number_format_i18n( $mobile_api_mileage, 0 ) ) ?> km</strong></li>
							<?php endif; ?>
							<?php if ( !empty( $mobile_api_power ) ) : ?>
								<li class="power dashicons-before dashicons-dashboard"><small><?php esc_html_e( 'Power', 'ad-integration-for-mobile-de-api' ) ?></small> <strong><?php echo esc_html( number_format_i18n( $mobile_api_power, 0 ) ) ?> kW (<?php echo esc_html( number_format_i18n( $mobile_api_power * 1.35962, 0 ) ) ?> PS)</strong></li>
							<?php endif; ?>
							<li class="fuel dashicons-before dashicons-car"><small><?php esc_html_e( 'Fuel', 'ad-integration-for-mobile-de-api' ) ?></small> <strong><?php echo esc_html( mobile_api_translate_data_value( $mobile_api_fuel ) ) ?></strong></li>
							<li class="gearbox dashicons-before dashicons-admin-generic"><small><?php esc_html_e( 'Gear', 'ad-integration-for-mobile-de-api' ) ?></small> <strong><?php echo esc_html( $mobile_api_gearbox ) ?></strong></li>
							<?php if ( $mobile_api_condition == 'USED' ) : ?>
								<li class="calendar dashicons-before dashicons-calendar-alt"><small><?php esc_html_e( 'First Registration', 'ad-integration-for-mobile-de-api' ) ?></small> <strong><?php echo esc_html( substr( $mobile_api_firstRegistration, 4, 6 ) ) ?>/<?php echo esc_html( substr( $mobile_api_firstRegistration, 0, -2 ) ) ?></strong></li>
								<li class="user dashicons-before dashicons-admin-users"><small><?php esc_html_e( 'Previous Owners', 'ad-integration-for-mobile-de-api' ) ?></small> <strong><?php echo esc_html( $mobile_api_owner ) ?></strong></li>
							<?php endif; ?>
						</ul>
						<p><a href="<?php echo esc_url( 'mailto:'.$mobile_api_seller->email.'?subject='.__( 'Vehicle request:', 'ad-integration-for-mobile-de-api' ).' '.get_the_title().' | VIN: '.$mobile_api_vin ) ?>" class="<?php echo esc_attr( mobile_api_get_button_classes() ) ?>"><?php esc_html_e( 'Direct inquiry by email', 'ad-integration-for-mobile-de-api' ); ?></a></p>
						<?php // translators: %s is the formatted phone number ?>
						<p><a href="<?php echo esc_url( 'tel:'.$mobile_api_tel ) ?>"><?php echo sprintf( esc_html__( 'Or call %s', 'ad-integration-for-mobile-de-api' ), esc_html( $mobile_api_tel_formatted ) ) ?></a></p>
					</div></div>
				</div>

				<div class="vehicle-grid">
					<div class="features vehicle-content-container">
						<h2><?php esc_html_e( 'Equipment', 'ad-integration-for-mobile-de-api' ) ?></h2>
						<ul>
							<?php
							$mobile_api_features = array();
							$mobile_api_vehicle = get_post_meta( $post_id, 'mobile_api_vehicleClass', true );
							$mobile_api_url = 'https://services.mobile.de/refdata/classes/'.$mobile_api_vehicle.'/features';
							$mobile_api_json = mobile_api_request( $mobile_api_url );
							if ( !empty( $mobile_api_json ) && property_exists( $mobile_api_json, 'values' ) ) :
								foreach ( $mobile_api_json->values AS $mobile_api_feature )
									$mobile_api_features[strtolower( str_replace( '_', '', $mobile_api_feature->name ) )] = $mobile_api_feature->description;

								foreach ( $mobile_api_metas as $mobile_api_key => $mobile_api_value ) :
									if ( !str_starts_with( $mobile_api_key, 'mobile_api' ) )
										continue;

									$mobile_api_key = substr( $mobile_api_key, 11 ); // Remove post meta prefix 'mobile_api_'

									if ( in_array( $mobile_api_key, $mobile_api_meta_exclude )
										|| empty( reset( $mobile_api_value ) )
										|| reset( $mobile_api_value ) != 1
										|| $mobile_api_key == 'numberOfPreviousOwners'
										|| !array_key_exists( strtolower( $mobile_api_key ), $mobile_api_features )
									)
										continue;
									?>
									<li class="dashicons-before dashicons-yes <?php echo esc_attr( $mobile_api_key ) ?>"><?php echo esc_html( $mobile_api_features[strtolower( $mobile_api_key )] ) ?></li>
								<?php
								endforeach;
							else :
								esc_html_e( 'It was not able to load the equipment. Please try again later.', 'ad-integration-for-mobile-de-api' );
							endif;
							?>
						</ul>
					</div>

					<div class="specifications vehicle-content-container">
						<h2><?php esc_html_e( 'Technical data', 'ad-integration-for-mobile-de-api' ) ?></h2>
						<dl class="vehicle-grid-columns">
							<?php
							foreach ( $mobile_api_metas as $mobile_api_key => $mobile_api_value ) :
								if ( !str_starts_with( $mobile_api_key, 'mobile_api' ) )
									continue;

								$mobile_api_key = substr( $mobile_api_key, 11 ); // Remove post meta prefix 'mobile_api_'

								if ( in_array( $mobile_api_key, $mobile_api_meta_exclude )
									|| empty( reset( $mobile_api_value ) )
									|| ( reset( $mobile_api_value ) == 1 && $mobile_api_key != 'numberOfPreviousOwners' )
									|| ( $mobile_api_key == 'costModel' && !property_exists( unserialize( maybe_unserialize( reset( $mobile_api_value ) ) ), 'consumptionCosts' ) )
								)
									continue;
								?>
								<dt class="<?php echo esc_attr( $mobile_api_key ) ?>-key">
									<?php echo esc_html( mobile_api_translate_data( $mobile_api_key ) ) ?>
									<?php echo mobile_api_get_data_hints( $mobile_api_key ) ? '<div class="tooltip"><span class="dashicons dashicons-info-outline"></span><div class="tooltiptext">'.wp_kses_post( mobile_api_get_data_hints( $mobile_api_key ) ).'</div></div>' : ''; ?>
								</dt>
								<dd class="<?php echo esc_attr( $mobile_api_key ) ?>-value">
									<?php
									$mobile_api_value = maybe_unserialize( reset( $mobile_api_value ) );
									/* if ( $mobile_api_key == 'wltpValues' ) :
										$mobile_api_object = unserialize( $mobile_api_value );
										if ( $mobile_api_object->consumptionPowerCombined )
											echo number_format_i18n( $mobile_api_object->consumptionPowerCombined, 1 ).' '.esc_html( mobile_api_translate_consumption_unit( 'power' ) );

										if ( $mobile_api_object->consumptionFuelCombined )
											echo number_format_i18n( $mobile_api_object->consumptionFuelCombined, 1 ).' '.esc_html( mobile_api_translate_consumption_unit( 'fuel' ) );
									else */ if ( $mobile_api_key == 'costModel' ) :
										$mobile_api_object = unserialize( $mobile_api_value );

										echo '<p>'.esc_html__( 'Energy costs for 15,000 km annual mileage:', 'ad-integration-for-mobile-de-api' ).' '.esc_html( number_format_i18n( $mobile_api_object->consumptionCosts, 2 ) ).' € / '.esc_html__( 'year', 'ad-integration-for-mobile-de-api' ).'</p>';

										if ( property_exists( $mobile_api_object, 'powerPrice' ) )
											echo '<p>'.esc_html__( 'Electricity price:', 'ad-integration-for-mobile-de-api' ).' '.esc_html( number_format_i18n( $omobile_api_bject->powerPrice, 2 ) ).' €/kWh (⌀ '.intval( $mobile_api_object->consumptionPriceYear ).')</p>';

										if ( property_exists( $mobile_api_object, 'fuelPrice' ) )
											echo '<p>'.esc_html__( 'Fuel price:', 'ad-integration-for-mobile-de-api' ).' '.esc_html( number_format_i18n( $mobile_api_object->fuelPrice, 2 ) ).' €/l (⌀ '.intval( $mobile_api_object->consumptionPriceYear ).')</p>';

										echo '<p>'.esc_html__( 'Motor vehicle tax:', 'ad-integration-for-mobile-de-api' ).' '.esc_html( number_format_i18n( $mobile_api_object->tax, 0 ) ).' €/'.esc_html__( 'year', 'ad-integration-for-mobile-de-api' ).'</p>';
										?>
								</dd>
								<dt class="co2Costs-key">
									<?php esc_html_e( 'Possible CO₂ costs over the next 10 years (15,000 km/year)', 'ad-integration-for-mobile-de-api' ) ?>
									<div class="tooltip"><span class="dashicons dashicons-info-outline"></span><div class="tooltiptext">'<?php echo wp_kses_post( mobile_api_get_data_hints( 'co2Costs' ) ) ?></div></div>
								</dt>
								<dd class="co2Costs-value">
										<?php
										// translators: %s is the level of the average CO₂ price
										echo '<p><strong>'.esc_html( number_format_i18n( $mobile_api_object->co2Costs->middle->accumulated, 0 ) ).' €'.' '.sprintf( esc_html__( '(assuming an %1$s average CO₂ price of %2$d €/t)', 'ad-integration-for-mobile-de-api' ), esc_html__( 'medium', 'ad-integration-for-mobile-de-api' ), esc_html( number_format_i18n( $mobile_api_object->co2Costs->middle->basePrice, 0 ) ) ).'</strong></p>';
										// translators: %s is the level of the average CO₂ price
										echo '<p>'.esc_html( number_format_i18n( $mobile_api_object->co2Costs->low->accumulated, 0 ) ).' €'.' '.sprintf( esc_html__( '(assuming an %1$s average CO₂ price of %2$d €/t)', 'ad-integration-for-mobile-de-api' ), esc_html__( 'low', 'ad-integration-for-mobile-de-api' ), esc_html( number_format_i18n( $mobile_api_object->co2Costs->low->basePrice, 0 ) ) ).'</p>';
										// translators: %s is the level of the average CO₂ price
										echo '<p>'.esc_html( number_format_i18n( $mobile_api_object->co2Costs->high->accumulated, 0 ) ).' €'.' '.sprintf( esc_html__( '(assuming an %1$s average CO₂ price of %2$d €/t)', 'ad-integration-for-mobile-de-api' ), esc_html__( 'high', 'ad-integration-for-mobile-de-api' ), esc_html( number_format_i18n( $mobile_api_object->co2Costs->high->basePrice, 0 ) ) ).'</p>';
									elseif ( is_serialized( $mobile_api_value ) ) :
										$mobile_api_array = unserialize( $mobile_api_value );
										foreach ( $mobile_api_array as $mobile_api_array_key => $mobile_api_array_value ) {
											if ( is_object( $mobile_api_array_value ) || $mobile_api_key == 'consumptions' ) {
												if ( $mobile_api_key == 'emissions' ) {
													$mobile_api_classes = array();
													foreach ( $mobile_api_array as $mobile_api_emission ) {
														if ( property_exists( $mobile_api_emission, 'co2Class' ) )
															$mobile_api_classes[] = $mobile_api_emission->co2Class;
													}

													if ( count( $mobile_api_classes ) > 1 )
														$mobile_api_classes[] = reset( explode( '_', get_locale() ) );

													if ( property_exists( $mobile_api_array_value, 'co2' ) ) :
														echo esc_html__( 'CO₂ emissions (combined):', 'ad-integration-for-mobile-de-api' ).' '.intval( $mobile_api_array_value->co2 ).' g/km';
														echo '<img src="'.esc_url( mobile_api_get_emission_class_image( $mobile_api_classes ) ).'" alt="'.esc_attr( implode( '-', $mobile_api_classes ) ).'">';
													endif;
												} elseif ( $mobile_api_key == 'wltpValues' ) {
													echo esc_html__( 'CO₂ emissions (combined):', 'ad-integration-for-mobile-de-api' ).' '.intval( $mobile_api_array_value ).' g/km';
												} elseif ( $mobile_api_key == 'consumptions' ) {
													if ( $mobile_api_array_key == 'weightedCombinedFuel' )
														echo '<p>'.esc_html__( 'Consumptions (weighted combined):', 'ad-integration-for-mobile-de-api' ).' '.esc_html( number_format_i18n( $mobile_api_array_value, 1 ) ).' '.esc_html( mobile_api_translate_consumption_unit( $mobile_api_array_key ) );

													if ( $mobile_api_array_key == 'weightedCombinedPower' )
														echo ' + '.esc_html( number_format_i18n( $mobile_api_array_value, 1 ) ).' '.esc_html( mobile_api_translate_consumption_unit( $mobile_api_array_key ) ).'</p>';

													if ( is_object( $mobile_api_array_value ) && count( (array)$mobile_api_array_value ) ) {
														echo '<p>';

														if ( count( get_object_vars( $mobile_api_array ) ) > 1 )
															echo esc_html( mobile_api_translate_consumption_title( $mobile_api_array_key ) ).'<br>';

														if ( !empty( $mobile_api_array_value->combined ) )
															echo '<strong>'.esc_html( number_format_i18n( $mobile_api_array_value->combined, 1 ).' '.mobile_api_translate_consumption_unit( $mobile_api_array_key ).' '.__( 'combined', 'ad-integration-for-mobile-de-api' ) ).'</strong><br>';

														if ( !empty( $mobile_api_array_value->city ) )
															echo esc_html( number_format_i18n( $mobile_api_array_value->city, 1 ).' '.mobile_api_translate_consumption_unit( $mobile_api_array_key ).' '.__( 'City', 'ad-integration-for-mobile-de-api' ) ).'<br>';

														if ( !empty( $mobile_api_array_value->suburban ) )
															echo esc_html( number_format_i18n( $mobile_api_array_value->suburban, 1 ).' '.mobile_api_translate_consumption_unit( $mobile_api_array_key ).' '.__( 'Suburban', 'ad-integration-for-mobile-de-api' ) ).'<br>';

														if ( !empty( $mobile_api_array_value->rural ) )
															echo esc_html( number_format_i18n( $mobile_api_array_value->rural, 1 ).' '.mobile_api_translate_consumption_unit( $mobile_api_array_key ).' '.__( 'Rural', 'ad-integration-for-mobile-de-api' ) ).'<br>';

														if ( !empty( $mobile_api_array_value->highway ) )
															echo esc_html( number_format_i18n( $mobile_api_array_value->highway, 1 ).' '.mobile_api_translate_consumption_unit( $mobile_api_array_key ).' '.__( 'Highway', 'ad-integration-for-mobile-de-api' ) ).'</p>';
													}
												}
											} elseif ( $mobile_api_key == 'dimension' ) {
												if ( $mobile_api_array_key == 'length' )
													echo esc_html__( 'Length:', 'ad-integration-for-mobile-de-api' ).' '.esc_html( number_format_i18n( $mobile_api_array_value, 0 ) ).' mm'.'<br>';

												if ( $mobile_api_array_key == 'width' )
													echo esc_html__( 'Width:', 'ad-integration-for-mobile-de-api' ).' '.esc_html( number_format_i18n( $mobile_api_array_value, 0 ) ).' mm'.'<br>';

												if ( $mobile_api_array_key == 'height' )
													echo esc_html__( 'Height:', 'ad-integration-for-mobile-de-api' ).' '.esc_html( number_format_i18n( $mobile_api_array_value, 0 ) ).' mm'.'<br>';
											} else
												echo esc_html( mobile_api_translate_data_value( $mobile_api_array_value ) ).'<br>';
										}
									else :
										if ( $mobile_api_key == 'mileage' || $mobile_api_key == 'range' || $mobile_api_key == 'equivalentAllElectricRange' )
											echo esc_html( number_format_i18n( $mobile_api_value, 0 ) ).' km';
										elseif ( $mobile_api_key == 'power' )
											echo esc_html( $mobile_api_value ).' kW ('.intval( round( $mobile_api_value * 1.35962 ) ).' PS)';
										elseif ( $mobile_api_key == 'firstRegistration' )
											echo esc_html( substr( $mobile_api_value, 4, 6 ) ).'/'.esc_html( substr( $mobile_api_value, 0, -2 ) );
										elseif ( $mobile_api_key == 'cubicCapacity' )
											echo esc_html( number_format_i18n( mobile_api_translate_data_value( $mobile_api_value, 0 ) ) ).' cm³';
										elseif ( $mobile_api_key == 'fuelTankVolume' )
											echo esc_html( number_format_i18n( mobile_api_translate_data_value( $mobile_api_value, 0 ) ) ).' l';
										elseif ( $mobile_api_key == 'batteryCapacity' )
											echo esc_html( number_format_i18n( mobile_api_translate_data_value( $mobile_api_value, 0 ) ) ).' kWh';
										elseif ( $mobile_api_key == 'weight' || $mobile_api_key == 'trailerLoadBraked' || $mobile_api_key == 'trailerLoadUnbraked' || $mobile_api_key == 'licensedWeight' || $mobile_api_key == 'maxNoseWeight' )
											echo esc_html( number_format_i18n( mobile_api_translate_data_value( $mobile_api_value, 0 ) ) ).' kg';
										elseif ( $mobile_api_key == 'deliveryPeriod' ) {
											// translators: %d is the availability in months from order
											echo sprintf( esc_html__( 'Available in %d months from order', 'ad-integration-for-mobile-de-api' ), intval( $mobile_api_value / 30 ) );
										} elseif ( $mobile_api_key == 'lastMaintenanceDate' )
											echo esc_html( explode( '-', $mobile_api_value )[1].'/'.explode( '-', $mobile_api_value )[0] );
										elseif ( $mobile_api_key == 'generalInspection' )
											echo esc_html( $mobile_api_value[4].$mobile_api_value[5].'/'.$mobile_api_value[0].$mobile_api_value[1].$mobile_api_value[2].$mobile_api_value[3] );
										elseif ( is_string( $mobile_api_value ) )
											echo esc_html( mobile_api_translate_data_value( $mobile_api_value ) );
									endif;
									?>
								</dd>
							<?php endforeach; ?>
						</dl>
					</div>
				</div>

				<div class="description vehicle-content-container">
					<h2><?php esc_html_e( 'Further vehicle data', 'ad-integration-for-mobile-de-api' ) ?></h2>
					<?php the_content(); ?>
					<?php // translators: %s is the url to the vehicle on mobile ?>
					<p><small><?php echo sprintf( wp_kses_post( __( 'The data for this vehicle was obtained via the mobile.de interface. <a href="%s" target="_blank">View vehicle on mobile.de</a>.', 'ad-integration-for-mobile-de-api' ) ), esc_url( $mobile_api_mobile_url ) ) ?></small></p>

					<h3><?php esc_html_e( 'Contact details', 'ad-integration-for-mobile-de-api' ) ?></h3>
					<dl class="vehicle-grid-columns">
						<dt><?php esc_html_e( 'Company name', 'ad-integration-for-mobile-de-api' ) ?></dt>
						<dd><?php echo esc_html( $mobile_api_seller->companyName ) ?></dd>

						<dt><?php esc_html_e( 'Email', 'ad-integration-for-mobile-de-api' ) ?></dt>
						<dd><?php echo esc_html( $mobile_api_seller->email ) ?></dd>

						<dt><?php esc_html_e( 'Phone', 'ad-integration-for-mobile-de-api' ) ?></dt>
						<dd><?php echo esc_html( $mobile_api_tel_formatted ) ?></dd>

						<dt><?php esc_html_e( 'Address', 'ad-integration-for-mobile-de-api' ) ?></dt>
						<dd><?php echo esc_html( $mobile_api_seller->address->street ) ?><br><?php echo esc_html( $mobile_api_seller->address->country ) ?>-<?php echo esc_html( $mobile_api_seller->address->zipcode ) ?> <?php echo esc_html( $mobile_api_seller->address->city ) ?></dd>
					</dl>

					<p><a href="<?php echo esc_url( 'mailto:'.$mobile_api_seller->email.'?subject='.__( 'Vehicle request:', 'ad-integration-for-mobile-de-api' ).' '.get_the_title().' | VIN: '.$mobile_api_vin ) ?>" class="<?php echo esc_attr( mobile_api_get_button_classes() ) ?>"><?php esc_html_e( 'Direct inquiry by email', 'ad-integration-for-mobile-de-api' ); ?></a></p>
					<?php // translators: %s is the formatted phone number ?>
					<p><a href="<?php echo esc_url( 'tel:'.$mobile_api_tel ) ?>"><?php echo sprintf( esc_html__( 'Or call %s', 'ad-integration-for-mobile-de-api' ), esc_html( $mobile_api_tel_formatted ) ) ?></a></p>
				</div>

			</div>

			<footer class="entry-footer">
				<?php // post nav ?>
			</footer>

		</article>

	<?php endwhile; ?>

	<?php get_sidebar(); ?>

</div></div></main>

<?php get_footer(); ?>