
<div class="euro-row es-vehgrid">
              <?php
              foreach ($vehicles as $vehicle) {

                $key_l = array_search('L', array_column($vehicle['images'], 'size'));
                $key_xl = array_search('XL', array_column($vehicle['images'], 'size'));

                $image_l_url = ($key_l !== false) ? $vehicle['images'][$key_l]['url'] :
                  (($key_xl !== false) ? $vehicle['images'][$key_xl]['url'] : '');
                $image_xl_url = ($key_xl !== false) ? $vehicle['images'][$key_xl]['url'] : $image_l_url;
              ?>
                <div class="estocks eurocol-12 eurocol-sm-6 eurocol-lg-4 eurostocks-grid-item">
                  <a class="estocks-link" data-id="<?php echo esc_html($vehicle['vehicleId']); ?>"
                    href="<?php if($diflang && ($default_lang != $current_lang)){ echo "/" . esc_html($current_lang); } ?>/auto/<?php echo esc_html($vehicle['vehicleId']); ?>/">
                    <div class="estocks-image-wrapper es-img-box">
                        <picture>
                            <source media="(max-width: 768px)" srcset="<?php echo esc_url($image_xl_url); ?>">
                            <img alt="<?php echo esc_html($vehicle['modelDescription']); ?>"
                                src="<?php echo esc_url($image_l_url); ?>" loading="lazy" />
                        </picture>
                    </div>
                    <div class="es-content">
                      <h3 class="eurosearch-car-title">
                        <?php echo esc_html($vehicle['make'] . ' ' . $vehicle['modelDescription']); ?>
                      </h3>
                      <div class="eurosearch-car-details es-grid es-grid-columns-2">
                        <div class="es-icon es-registration">
                          <?php echo esc_html($vehicle['firstRegistrationDate']); ?>
                        </div>
                        <div class="es-icon es-pk">
                          <?php echo esc_html(intval($vehicle['power'] * 1.362)); ?>
                          <?php esc_html_e('HP', 'eurostocks'); ?>
                        </div>
                        <div class="es-icon es-gearbox">
                          <?php if ($vehicle['gearBox'] == "Automatische transmissie") {
                            echo "Automaat";
                          } else {
                            echo esc_html($vehicle['gearBox']);
                          } ?>
                        </div>
                        <div class="es-icon es-mileage">
                          <?php echo esc_html(number_format(floatval($vehicle['mileage']), 0, ',', '.')); ?>KM
                        </div>
                        <div class="es-icon es-fueltype">
                          <?php
                          if ($vehicle['fuelType'] == "Hybride (benzine/elektrisch)") {
                            echo "Hybride benzine";
                          } elseif ($vehicle['fuelType'] == "Hybride (diesel/elektrisch)") {
                            echo "Hybride diesel";
                          } else {
                            echo esc_html($vehicle['fuelType']);
                          }
                          ?>
                        </div>
                      </div>

                      <?php if (isset($vehicle['priceInfo'])) {

                        if ((isset($vehicle['priceInfo']['PriceMobiledeBruto'])) && (is_numeric($vehicle['priceInfo']['PriceMobiledeBruto'])) && $vehicle['priceInfo']['PriceMobiledeBruto'] != 0) {
                          if (isset($vehicle['priceInfo']['TransportCosts']) && $vehicle['priceInfo']['TransportCosts'] != '') {
                            $transportCosts = $vehicle['priceInfo']['TransportCosts'];
                          } else {
                            $transportCosts = 0;
                          }
                          if ($options['country'] != 'nl' && $options['country'] != 'nl21') {
                            if (isset($vehicle['priceInfo']['ImportMargin']) && $vehicle['priceInfo']['ImportMargin'] != '') {
                              $importMargin = $vehicle['priceInfo']['ImportMargin'];
                            } else {
                              $importMargin = 0;
                            }
                            if (isset($vehicle['priceInfo']['ImportCosts']) && $vehicle['priceInfo']['ImportCosts'] != '') {
                              $importCosts = $vehicle['priceInfo']['ImportCosts'];
                            } else {
                              $importCosts = 0;
                            }
                            $price = $vehicle['priceInfo']['PriceMobiledeBruto'] + $importMargin + $importCosts + $transportCosts;
                          } elseif ($options['country'] == 'nl21') {
                              if (isset($vehicle['priceInfo']['PriceNlWithVatNl']) && $vehicle['priceInfo']['PriceNlWithVatNl'] != '') {
                                  $price = $vehicle['priceInfo']['PriceNlWithVatNl'];
                              } else {
                                  if(isset($vehicle['priceInfo']['FallbackPriceNlWithVatNl']) && $vehicle['priceInfo']['FallbackPriceNlWithVatNl'] != '' && isset($options['co2_fallback_display']) && $options['co2_fallback_display'] == 1) {
                                      $price = $vehicle['priceInfo']['FallbackPriceNlWithVatNl'];
                                  }else{
                                      $price = false;
                                  }
                              }
                          } else {
                              if($options['country'] == 'nl') {
                                  if (isset($vehicle['priceInfo']['PriceNlWithVatMobilede']) && $vehicle['priceInfo']['PriceNlWithVatMobilede'] != '') {
                                      $price = $vehicle['priceInfo']['PriceNlWithVatMobilede'];
                                  }
                                  elseif(isset($vehicle['priceInfo']['FallbackPriceNlWithVatMobilede']) && $vehicle['priceInfo']['FallbackPriceNlWithVatMobilede'] != '' && isset($options['co2_fallback_display']) && $options['co2_fallback_display'] == 1) {
                                      $price = $vehicle['priceInfo']['FallbackPriceNlWithVatMobilede'];
                                  } else {
                                      $price = false;
                                  }
                              }else {
                                 
        $price = false;
                                  
                              }
                          }
                        }

                      ?>

                        <div class="es-flex price-n-btn">
                          <div class="euro-price-wrapper">
                            <?php if ($eurostocks_only_fl != 1) { ?>
                              <div class="euro-price">
                                <?php
                                if ($price) {
                                  echo esc_html("&euro; " . number_format(floatval($price), 0, ',', '.')) . ",-";
                                } else {
                                  if($diflang && isset($options[esc_html($current_lang)]) && isset($options[esc_html($current_lang)]['txt_priceonrequest']) && $options[esc_html($current_lang)]['txt_priceonrequest'] != ""  ){ 
                                    echo esc_html($options[esc_html($current_lang)]['txt_priceonrequest']); 
                                  }else{ 
                                     if (isset($options['txt_priceonrequest']) && $options['txt_priceonrequest'] != "") {
                                      echo esc_html($options['txt_priceonrequest']);
                                    } else {
                                      esc_html_e("Price on request", 'eurostocks');
                                    } 
                                  }
                                } ?>
                              </div>

                              <?php
                              if ($vehicle['priceInfo']['IsVatable'] == "Ja") {
                              ?>
                                <div class="euro-help-text">
                                  <?php if (isset($options['txt_price_help'])) {
                                    echo esc_html($options['txt_price_help']);
                                  } ?>
                                </div>
                              <?php
                              } else {
                              ?>
                                <div class="euro-help-text">
                                  <?php if (isset($options['txt_price_helpp'])) {
                                    echo esc_html($options['txt_price_helpp']);
                                  } ?>
                                </div>
                              <?php
                              } ?>

                            <?php } ?>


                            <?php if (($eurostocks_fl == 1 || $eurostocks_only_fl == 1)) {
                              if ($price) { ?>
                                <span class="euro-price-wrapper euro-fl <?php if ($eurostocks_only_fl == 1) {
                                                                          echo 'only-fl';
                                                                        } ?>">
                                  <span class="euro-helper-text"><?php esc_html_e('Lease from', 'eurostocks'); ?></span> <span
                                    class="euro-price">€
                                    <?php echo esc_html($this->eurostocks_financial_lease($eurostocks_fl_interest, $eurostocks_fl_duration, $eurostocks_fl_rest, $price)); ?>,-
                                  </span>
                                </span>
                              <?php } elseif (!$price && $eurostocks_only_fl == 1) { ?>
                                <span class="euro-price-wrapper euro-fl only-fl">
                                  <span class="euro-helper-text"><?php esc_html_e('Lease from', 'eurostocks'); ?></span> <span class="euro-price"><?php esc_html_e('Request price', 'eurostocks'); ?></span>
                                </span>
                            <?php
                              }
                            } ?>
                          </div>
                        </div>

                    </div>
                  </a>
                </div>
                <?php
                      }
                      // grid display
                      if (count($vehicles) > 0 || (isset($_GET['make']) && isset($_GET['model']))) {
                        if (isset($options['replacement_img']) && $options['replacement_img'] != '') {
                          $replacement_img = wp_get_attachment_image_url($options['replacement_img'], 'full'); ?>
                  <a href="<?php if (isset($options['cta_url']) && $options['cta_url'] != '') {
                              echo esc_url($options['cta_url']);
                            } else {
                              echo '#';
                            } ?>" <?php if (isset($options['cta_url']) && $options['cta_url'] != '') {
                            echo 'target="_blank" data-cta="a" ';
                          } else {
                            echo 'data-cta="b" data-modal="es-contact" ';
                          } ?>class="estocks eurocol-12 eurocol-sm-6 eurocol-lg-4 es-cta-action"
                    style="background-image: url('<?php echo esc_url($replacement_img); ?>');">
                  </a>
            <?php
                        }
                      }
                    }



            ?>

            </div>