<?php
if (!defined('ABSPATH'))
  exit;
global $wp;

$options = get_option($this->plugin_name);
$car_options = get_option($this->plugin_name . "_cars");

$accepted_languages = array('nl', 'de', 'en', 'fr', 'es');
$lang_data      = eurostocks_get_language_details();
$languages      = $lang_data['languages'];
$language_codes = $lang_data['language_codes'];
$default_lang   = $lang_data['default_lang'];
$current_lang   = $lang_data['current_lang'];
$diflang        = $lang_data['diflang'];
$show_lang      = $lang_data['show_lang'];


$makelist = get_option('eurostocks_makes');

if (isset($car_options['select_available_make'])) {
  $makes = $car_options['select_available_make'];
} elseif (isset($options['select_available_make'])) {
  $makes = $options['select_available_make'];
} else {
  $makes = array();
}
if (isset($makes) && is_array($makes)) {
  sort($makes);
}

if (!isset($car_options['live_models']) || (isset($car_options['live_models']) && $car_options['live_models'] == '0')) {

  if (! wp_next_scheduled('eurostocks_update_model_scheduler', [])) {
    if (isset($car_options['select_available_model'])) {
      $models_a = $car_options['select_available_model'];
    } else {
      $models_a = array();
    }
    if (isset($car_options['select_available_model_b'])) {
      $models_b = $car_options['select_available_model_b'];
    } else {
      $models_b = array();
    }
    $models = array_merge($models_a, $models_b);
  } else {
    $models = array();
    foreach ($makes as $make) {
      $carmodels = get_option('eurostocks_models_' . sanitize_text_field($make));
      // check if carmodels is an array
      if (isset($carmodels) && is_array($carmodels)) {
        $models = array_merge($models, $carmodels);
      }
    }
  }

  if (isset($car_options['excluded_models']) && $car_options['excluded_models'] != '') {
    $filtered_models = [];
    $excluded_models = explode(',', $car_options['excluded_models']);
    foreach ($models as $model) {
      list($model_name, $make) = explode('|', $model);
      $exclude = false;
      foreach ($excluded_models as $excluded_model) {
        if (strpos($model_name, $excluded_model) !== false) {
          $exclude = true;
          break;
        }
      }
      if (!$exclude) {
        $filtered_models[] = $model;
      }
    }
    $models = $filtered_models;
  }

  sort($models);
} else {
  $models = array();
}


$allowed_html = array(
  'br' => array(),
  'strong' => array(),
  'p' => array(),
  'span' => array(),
);

if (count($language_codes) > 1) {
  $eurostocks_fuel_types = get_option('eurostocks_fuel_types_' . $current_lang);
  if (!isset($eurostocks_fuel_types) || !is_array($eurostocks_fuel_types)) {
    $eurostocks_fuel_types = get_option('eurostocks_fuel_types');
  }
} else {
  $eurostocks_fuel_types = get_option('eurostocks_fuel_types');
}



if ($diflang && isset($options[esc_html($current_lang)]) && isset($options[esc_html($current_lang)]['txt_select_make']) && $options[esc_html($current_lang)]['txt_select_make'] != "") {
  $select_make = esc_html($options[esc_html($current_lang)]['txt_select_make']);
} else {
  if (isset($options['txt_select_make']) && $options['txt_select_make'] != "") {
    $select_make = esc_html($options['txt_select_make']);
  } else {
    $select_make = __("Select make", 'eurostocks');
  }
}

if ($diflang && isset($options[esc_html($current_lang)]) && isset($options[esc_html($current_lang)]['txt_select_model']) && $options[esc_html($current_lang)]['txt_select_model'] != "") {
  $select_model = esc_html($options[esc_html($current_lang)]['txt_select_model']);
} else {
  if (isset($options['txt_select_model']) && $options['txt_select_model'] != "") {
    $select_model = esc_html($options['txt_select_model']);
  } else {
    $select_model = __("Select model", 'eurostocks');
  }
}

$mileage_to_only = isset($atts['mileage_to_only']) || isset($atts['mileage_to']);
$mileage_from_only = isset($atts['mileage_from_only']) || isset($atts['mileage_from']);
$mileage_show_from = isset($atts['mileage']) || $mileage_from_only;
$mileage_show_to = isset($atts['mileage']) || $mileage_to_only;
$show_transmission_filter = isset($atts['transmission']);
if($show_transmission_filter) {
  $eurostocks_transmissions = get_option('eurostocks_transmissions');
}
if ($mileage_to_only && !$mileage_from_only) {
  $mileage_show_from = false;
}
if ($mileage_from_only && !$mileage_to_only) {
  $mileage_show_to = false;
}
$show_mileage_filter = $mileage_show_from || $mileage_show_to;
$mileage_wrapper_classes = 'eurofilters' . ($mileage_show_from && $mileage_show_to ? ' euro-input-group' : '');

$year_from_only = isset($atts['year_from_only']) || isset($atts['year_from']);
$year_to_only = isset($atts['year_to_only']) || isset($atts['year_to']);
$year_show_from = isset($atts['year']) || $year_from_only;
$year_show_to = isset($atts['year']) || $year_to_only;
if ($year_from_only && !$year_to_only) {
  $year_show_to = false;
}
if ($year_to_only && !$year_from_only) {
  $year_show_from = false;
}
$show_year_filter = $year_show_from || $year_show_to;
$year_wrapper_classes = 'eurofilters' . ($year_show_from && $year_show_to ? ' euro-input-group' : '');

?>
<script>
  var EUROSTOCKS_TRANSLATIONS = {
    "ERROR_GENERIC": "<?php esc_html_e("An error occurred, please try again later.", "eurostocks"); ?>",
    "ERROR_EXPIRED": "<?php esc_html_e("This request expired. Refresh the page and try again.", "eurostocks"); ?>",
    "LIVE_MODELS_LOAD": "<?php esc_html_e("Loading...", "eurostocks"); ?>",
    "MODELS_NO_PREFERENCE": "<?php esc_html_e("No preference", "eurostocks"); ?>",
    "MODELS_SELECT": "<?php echo esc_html($select_model); ?>",
    "MAKES_SELECT": "<?php echo esc_html($select_make); ?>",
    "ALL": "<?php echo esc_html("All", "eurostocks"); ?>",
  };

  <?php
  if (isset($car_options['excluded_models']) && $car_options['excluded_models'] != '') {

    $excluded_models = explode(',', $car_options['excluded_models']);
  ?>
    var EXCLUDED_MODELS = <?php echo json_encode($excluded_models); ?>;
  <?php } else { ?>
    var EXCLUDED_MODELS = [];
  <?php }
  ?>
</script>
<?php if ($diflang && isset($options[esc_html($current_lang)]) && isset($options[esc_html($current_lang)]['filters_page']) && $options[esc_html($current_lang)]['filters_page'] != "") { ?>
  <form class="es-search-box" method="GET" action="<?php echo esc_url(get_page_link($options[esc_html($current_lang)]['filters_page'])); ?>">
  <?php } else { ?>
    <form class="es-search-box" method="GET" action="<?php echo esc_url(get_page_link($options['filters_page'])); ?>">
    <?php } ?>
    <div class="filter es-flex">
      <h2 class="es-flex-r-grow es-search-title">
        <?php if ($diflang && isset($options[esc_html($current_lang)]) && isset($options[esc_html($current_lang)]['txt_srch']) && $options[esc_html($current_lang)]['txt_srch'] != "") { ?>
          <?php echo wp_kses($options[esc_html($current_lang)]['txt_srch'], $allowed_html); ?>
        <?php } else { ?>
          <?php echo wp_kses($options['txt_srch'], $allowed_html); ?>
        <?php } ?>
      </h2>
      <label class="es-fixed-grow">

        <?php
        if ($diflang && isset($options[esc_html($current_lang)]) && isset($options[esc_html($current_lang)]['txt_make']) && $options[esc_html($current_lang)]['txt_make'] != "") {
          echo esc_html($options[esc_html($current_lang)]['txt_make']);
        } else {
          if (isset($options['txt_make']) && $options['txt_make'] != "") {
            echo esc_html($options['txt_make']);
          } else {
            esc_html_e("Make", 'eurostocks');
          }
        }
        ?>
        <div class="eurofilters">
          <select id="make-select" class="form-control" name="make" <?php if (isset($car_options['live_models']) && $car_options['live_models'] == '1') {
                                                                      echo 'data-live-models="true"';
                                                                    } ?> <?php if (isset($car_options['make_only']) && $car_options['make_only'] != '2') { ?> required <?php } ?>>
            <option <?php if (isset($car_options['make_only']) && $car_options['make_only'] != '2') { ?>disabled <?php } ?> selected value="">
              <?php echo esc_html($select_make); ?>
            </option>
            <?php
            foreach ($makes as $eumake) {
              if (isset($car_options['live_models']) && $car_options['live_models'] == '1') {
                $exists = true;
              } else {
                $exists = false;
                foreach ($models as $model) {
                  if (strpos($model, $eumake) !== false) {
                    $exists = true;
                    break;
                  }
                }
              }
              if ($exists) {

                unset($eumakeDescription);

                if (is_array($makelist)) {
                  foreach ($makelist as $make) {
                    if (is_array($make) && isset($make['key']) && $make['key'] == $eumake) {
                      $eumakeDescription = $make['description'];
                      break;
                    } elseif (is_string($make) && $make == $eumake) {
                      $eumakeDescription = $make;
                      break;
                    }
                  }
                }
                if (!isset($eumakeDescription)) {
                  $eumakeDescription = $eumake;
                }

            ?>

                <option <?php echo (isset($_GET['make']) && $eumake == $_GET['make']) ? 'selected' : ''; ?>
                  value="<?php echo esc_html($eumake); ?>">
                  <?php echo esc_html($eumakeDescription); ?>
                </option>
            <?php }
            } ?>
          </select>
        </div>
      </label>
      <label class="es-fixed-grow">
        <?php
        if ($diflang && isset($options[esc_html($current_lang)]) && isset($options[esc_html($current_lang)]['txt_model']) && $options[esc_html($current_lang)]['txt_model'] != "") {
          echo esc_html($options[esc_html($current_lang)]['txt_model']);
        } else {
          if (isset($options['txt_model']) && $options['txt_model'] != "") {
            echo esc_html($options['txt_model']);
          } else {
            esc_html_e("Model", 'eurostocks');
          }
        }
        ?>
        <div class="eurofilters">
          <select id="model-select" class="form-control" name="model" <?php if (isset($atts['allow_make_only']) || (isset($car_options['make_only']) && ($car_options['make_only'] == '1' || $car_options['make_only'] == '2'))) {
                                                                        echo 'data-allow-empty="true"';
                                                                      } ?>>
            <option selected <?php if (isset($atts['allow_make_only']) || (isset($car_options['make_only']) && ($car_options['make_only'] == '1' || $car_options['make_only'] == '2'))) { ?> value="" <?php } else { ?> disabled <?php } ?>>
              <?php echo esc_html($select_model); ?>
            </option>

            <?php
            foreach ($models as $model) {
              $model_split = explode('|', $model);
              $app = (isset($model_split[2])) ? '|GROUP' : '';
              $model_c = $model_split[0];

              if (isset($_GET['model']) && $model_c . $app == stripcslashes(sanitize_text_field($_GET['model']))) {
                $modelDescription = $model_split[0];
              }
            ?>
              <option <?php echo (isset($_GET['model']) && $model_c . $app == $_GET['model']) ? 'selected' : ''; ?>
                data-make="<?php echo esc_html($model_split[1]); ?>"
                value="<?php echo esc_html($model_c); ?><?php echo (isset($model_split[2])) ? '|GROUP' : ''; ?>">
                <?php echo esc_html(str_replace('_', ' ', esc_html($model_split[0]))); ?>
              </option>
            <?php
            } ?>
          </select>
        </div>
      </label>
      <?php if (isset($atts['fuel'])) { ?>
        <div class="">
          <label>
            <?php esc_html_e('Fuel type', 'eurostocks'); ?>
            <div class="eurofilters d-flex">
              <select name="fuelType" class="">
                <option value="" <?php echo (!isset($_GET['fuelType']) ? 'selected="selected"' : '') ?>>
                  <?php esc_html_e('Make a choice', 'eurostocks'); ?>
                </option>
                <?php
                if (is_array($eurostocks_fuel_types)) {
                  foreach ($eurostocks_fuel_types as $option) {

                    if (is_array($option) && isset($option['description'])) {
                      if ($option['description'] == "Hybride (benzine/elektrisch)") {
                        $fueltype = "Hybride benzine";
                      } elseif ($option['description'] == "Hybride (diesel/elektrisch)") {
                        $fueltype = "Hybride diesel";
                      } else {
                        $fueltype = $option['description'];
                      }
                      $optionKey = $option['key'];
                    } elseif (is_string($option)) {
                      $fueltype = $option;
                      $optionKey = $option;
                    } else {
                      continue; // Skip invalid entries
                    }

                    echo "<option " . (isset($_GET['fuelType']) && $_GET['fuelType'] == $optionKey ? 'selected' : '') . " value='" . esc_html($optionKey) . "'>" . esc_html($fueltype) . "</option>";
                  }
                }
                ?>
              </select>
            </div>
          </label>
        </div>
      <?php } ?>

      <?php
      if ($show_transmission_filter) { ?>
        <div class="">
          <label>
            <?php esc_html_e('Transmission', 'eurostocks'); ?>
            <div class="eurofilters d-flex">
              <select name="transmission" class="">
                <option value="" <?php echo (!isset($_GET['transmission']) ? 'selected="selected"' : '') ?>>
                  <?php esc_html_e('Make a choice', 'eurostocks'); ?>
                </option>
                <?php
                if (is_array($eurostocks_transmissions)) {
                  foreach ($eurostocks_transmissions as $option) {
                    if (is_array($option) && isset($option['key']) && isset($option['description'])) {
                      if ($option['key'] == "SEMIAUTOMATIC_GEAR") {
                        continue;
                      }
                      $optionKey = $option['key'];
                      $optionDesc = $option['description'] == "Automatische transmissie" ? "Automaat" : $option['description'];
                    } elseif (is_string($option)) {
                      $optionKey = $option;
                      $optionDesc = $option;
                    } else {
                      continue; // Skip invalid entries
                    }
                    echo "<option " . (isset($_GET['transmission']) && $_GET['transmission'] == $optionKey ? 'selected' : '') . " value='" . esc_html($optionKey) . "'>" . esc_html($optionDesc) . "</option>";
                  }
                }
                ?>
              </select>
            </div>
          </label>
        </div>
      <?php } ?>
      <?php
      if ($show_mileage_filter) { ?>
        <div class="">
          <label>
            <?php esc_html_e('Mileage', 'eurostocks'); ?>
            <div class="<?php echo esc_attr(trim($mileage_wrapper_classes)); ?>">
              <?php if ($mileage_show_from) { ?>
                <select name="mileageFrom" style="width: 100%;right: 0;">
                  <option value="" <?php echo (!isset($_GET['mileageFrom']) || $_GET['mileageFrom'] == "" ? 'selected="selected"' : ''); ?>>
                    <?php esc_html_e('From', 'eurostocks'); ?>
                  </option>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 5000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 5000) ? 'selected="selected"' : ''; ?> value="5000">5.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 7500) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 7500) ? 'selected="selected"' : ''; ?> value="7500">7.500 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 10000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 10000) ? 'selected="selected"' : ''; ?> value="10000">10.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 15000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 15000) ? 'selected="selected"' : ''; ?> value="15000">15.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 20000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 20000) ? 'selected="selected"' : ''; ?> value="20000">20.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 30000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 30000) ? 'selected="selected"' : ''; ?> value="30000">30.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 40000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 40000) ? 'selected="selected"' : ''; ?> value="40000">40.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 50000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 50000) ? 'selected="selected"' : ''; ?> value="50000">50.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 60000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 60000) ? 'selected="selected"' : ''; ?> value="60000">60.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 70000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 70000) ? 'selected="selected"' : ''; ?> value="70000">70.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 80000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 80000) ? 'selected="selected"' : ''; ?> value="80000">80.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 90000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 90000) ? 'selected="selected"' : ''; ?> value="90000">90.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 100000) { ?>
                    <option <?php echo (isset($_GET['mileageFrom']) && $_GET['mileageFrom'] == 100000) ? 'selected="selected"' : ''; ?> value="100000">100.000 KM</option>
                  <?php } ?>
                </select>
              <?php } ?>
              <?php if ($mileage_show_to) { ?>
                <select name="mileageTo" style="width: 100%;right: 0;">
                  <option value="" <?php echo (!isset($_GET['mileageTo']) || $_GET['mileageTo'] == "" ? 'selected="selected"' : ''); ?>>
                    <?php esc_html_e('To', 'eurostocks'); ?>
                  </option>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 1000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 1000) ? 'selected="selected"' : ''; ?>
                      value="1000">1.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 2500) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 2500) ? 'selected="selected"' : ''; ?>
                      value="2500">2.500 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 5000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 5000) ? 'selected="selected"' : ''; ?>
                      value="5000">5.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 7500) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 7500) ? 'selected="selected"' : ''; ?>
                      value="7500">7.500 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 10000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 10000) ? 'selected="selected"' : ''; ?> value="10000">10.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 15000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 15000) ? 'selected="selected"' : ''; ?> value="15000">15.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 20000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 20000) ? 'selected="selected"' : ''; ?> value="20000">20.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 30000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 30000) ? 'selected="selected"' : ''; ?> value="30000">30.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 40000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 40000) ? 'selected="selected"' : ''; ?> value="40000">40.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 50000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 50000) ? 'selected="selected"' : ''; ?> value="50000">50.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 60000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 60000) ? 'selected="selected"' : ''; ?> value="60000">60.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 70000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 70000) ? 'selected="selected"' : ''; ?> value="70000">70.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 80000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 80000) ? 'selected="selected"' : ''; ?> value="80000">80.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 90000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 90000) ? 'selected="selected"' : ''; ?> value="90000">90.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 100000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 100000) ? 'selected="selected"' : ''; ?> value="100000">100.000 KM</option>
                  <?php } ?>
                  <?php if (!isset($options['max_kmstand']) || intval($options['max_kmstand']) >= 125000) { ?>
                    <option <?php echo (isset($_GET['mileageTo']) && $_GET['mileageTo'] == 125000) ? 'selected="selected"' : ''; ?> value="100000">125.000 KM</option>
                  <?php } ?>

                </select>
              <?php } ?>
            </div>
          </label>
        </div>
      <?php } ?>

      <?php if ($show_year_filter) { ?>
        <div class="">
          <label>
            <?php esc_html_e('Registration date', 'eurostocks'); ?>
            <div class="<?php echo esc_attr(trim($year_wrapper_classes)); ?>">
              <?php if ($year_show_from) { ?>
                <select name="yearFrom" style="width: 100%;left: 0;">
                  <option value="" <?php echo (!isset($_GET['yearFrom']) || $_GET['yearFrom'] == "" ? 'selected="selected"' : '') ?>>
                    <?php esc_html_e('From', 'eurostocks'); ?>
                  </option>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2025) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2025) ? 'selected="selected"' : ''; ?>
                      value="2025">2025</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2024) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2024) ? 'selected="selected"' : ''; ?>
                      value="2024">2024</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2023) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2023) ? 'selected="selected"' : ''; ?>
                      value="2023">2023</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2022) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2022) ? 'selected="selected"' : ''; ?>
                      value="2022">2022</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2021) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2021) ? 'selected="selected"' : ''; ?>
                      value="2021">2021</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2020) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2020) ? 'selected="selected"' : ''; ?>
                      value="2020">2020</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2019) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2019) ? 'selected="selected"' : ''; ?>
                      value="2019">2019</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2018) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2018) ? 'selected="selected"' : ''; ?>
                      value="2018">2018</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2017) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2017) ? 'selected="selected"' : ''; ?>
                      value="2017">2017</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2016) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2016) ? 'selected="selected"' : ''; ?>
                      value="2016">2016</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2015) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2015) ? 'selected="selected"' : ''; ?>
                      value="2015">2015</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2014) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2014) ? 'selected="selected"' : ''; ?>
                      value="2014">2014</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2013) { ?>
                    <option <?php echo (isset($_GET['yearFrom']) && $_GET['yearFrom'] == 2013) ? 'selected="selected"' : ''; ?>
                      value="2013">2013</option>
                  <?php } ?>
                </select>
              <?php } ?>

              <?php if ($year_show_to) { ?>
                <select name="yearTo" style="width: 100%;right: 0;">
                  <option value="" <?php echo (!isset($_GET['yearTo']) || $_GET['yearTo'] == "" ? 'selected="selected"' : '') ?>>
                    <?php esc_html_e('To', 'eurostocks'); ?>
                  </option>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2025) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2025) ? 'selected="selected"' : ''; ?>
                      value="2025">2025</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2024) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2024) ? 'selected="selected"' : ''; ?>
                      value="2024">2024</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2023) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2023) ? 'selected="selected"' : ''; ?>
                      value="2023">2023</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2022) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2022) ? 'selected="selected"' : ''; ?>
                      value="2022">2022</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2021) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2021) ? 'selected="selected"' : ''; ?>
                      value="2021">2021</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2020) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2020) ? 'selected="selected"' : ''; ?>
                      value="2020">2020</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2019) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2019) ? 'selected="selected"' : ''; ?>
                      value="2019">2019</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2018) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2018) ? 'selected="selected"' : ''; ?>
                      value="2018">2018</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2017) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2017) ? 'selected="selected"' : ''; ?>
                      value="2017">2017</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2016) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2016) ? 'selected="selected"' : ''; ?>
                      value="2016">2016</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2015) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2015) ? 'selected="selected"' : ''; ?>
                      value="2015">2015</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2014) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2014) ? 'selected="selected"' : ''; ?>
                      value="2014">2014</option>
                  <?php } ?>
                  <?php if (!isset($options['min_bouwjaar']) || intval($options['min_bouwjaar']) <= 2013) { ?>
                    <option <?php echo (isset($_GET['yearTo']) && $_GET['yearTo'] == 2013) ? 'selected="selected"' : ''; ?>
                      value="2013">2013</option>
                  <?php } ?>
                </select>
              <?php } ?>
            </div>
          </label>
        </div>
      <?php } ?>

      <label>
        <br>
        <button class="euro-btn euro-btn-primary es-flex-grow" type="submit" value="Filter">
          <?php if ($diflang && isset($options[esc_html($current_lang)]) && isset($options[esc_html($current_lang)]['txt_srch_btn']) && $options[esc_html($current_lang)]['txt_srch_btn'] != "") { ?>
            <?php echo esc_html($options[esc_html($current_lang)]['txt_srch_btn']); ?>
          <?php } else { ?>
          <?php if (isset($options['txt_srch_btn'])) {
              echo esc_html($options['txt_srch_btn']);
            } else {
              echo esc_html__("Search in 1000000+ cars", 'eurostocks');
            }
          }
          ?>
        </button>
      </label>
    </div>

    </form>
