<?php 

$lang = 1;
$language = 'en';
$shortcode_id = $params['id'];

$language_locale = json_decode(get_post_meta( $shortcode_id, 'language_locale', true ));
$label_arr = array();
$locale = get_locale();
if ( !empty($language_locale)) {
    $language = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : $language;
    $language = !defined('ICL_LANGUAGE_CODE') && $locale != '' ? substr($locale, 0, 2) : $language;

    if (!isset($language_locale->$language) || $language_locale->$language == null) {
        $language = 'en';
        $label_arr = $language_locale->$language->labels;
    } else {
        $lang = $language_locale->$language == null ? $language_locale->en->id : $language_locale->$language->id;
        $label_arr = $language_locale->$language == null ? $language_locale->en->labels : $language_locale->$language->labels;
    }
}

$option_arr = json_decode(get_post_meta( $shortcode_id, 'options_data', true ));

// all models from every type
$cars_arr = json_decode(get_post_meta( $shortcode_id, 'all_vehicles_data', true ))->$language;

$number = 0;
$fleet_number = '';
if ( ! empty( get_post_meta( $shortcode_id, 'fleet_number', true ) ) ) {
    $fleet_number = get_post_meta( $shortcode_id, 'fleet_number', true );
}
$fleet_sorting = '';
if ( ! empty( get_post_meta( $shortcode_id, 'fleet_sorting', true ) ) ) {
    $fleet_sorting = get_post_meta( $shortcode_id, 'fleet_sorting', true );
}
$car_info_display = '';
if ( ! empty( get_post_meta( $shortcode_id, 'car_info_display', true ) ) ) {
    $car_info_display = get_post_meta( $shortcode_id, 'car_info_display', true );
    $car_info_display = explode(',', $car_info_display);
}
$selected_vehicles = '';
if ( ! empty( get_post_meta( $shortcode_id, 'selected_vehicles', true ) ) ) {
    $selected_vehicles = get_post_meta( $shortcode_id, 'selected_vehicles', true );
    $selected_vehicles = explode(',', $selected_vehicles);
}
$car_features = array();
if ( ! empty( get_post_meta( $shortcode_id, 'car_features', true ) ) ) {
    $car_features = get_post_meta( $shortcode_id, 'car_features', true );
    $car_features = explode(',', $car_features);
}

$vehicle_type = '';
if ( ! empty( get_post_meta( $shortcode_id, 'vehicle_type', true ) ) ) {
    $vehicle_type = get_post_meta( $shortcode_id, 'vehicle_type', true );
    $cars_arr = json_decode(get_post_meta( $shortcode_id, 'vehicles_type_data', true ))->$language->$vehicle_type;
}
$fleet_type = '';
if ( ! empty( get_post_meta( $shortcode_id, 'fleet_type', true ) ) ) {
    $fleet_type = get_post_meta( $shortcode_id, 'fleet_type', true );
    $cars_arr = json_decode(get_post_meta( $shortcode_id, 'model_type_data', true ))->$language->$fleet_type;
}

$once = '';
if ( ! empty( $params['once'] ) ) {
    $once = $params['once'];
    $cars_arr = json_decode(get_post_meta( $shortcode_id, 'vehicles_data', true ))->$language;
}

$slider = false;
if ( $params['slider'] == 'true' ) {
    $slider = true;
}

$vehicle = false;
if ( ! empty( $params['vehicle'] ) ) {
    $vehicle = true;
}

$button_text = get_post_meta($shortcode_id, 'button_text', true) ? get_post_meta($shortcode_id, 'button_text', true) :  __( $label_arr->book_now, 'gocars' );
$button_classes = get_post_meta($shortcode_id, 'button_classes', true) ? ' ' . get_post_meta($shortcode_id, 'button_classes', true) : '';
$fleet_wrap_classes = get_post_meta($shortcode_id, 'fleet_wrap_classes', true) ? ' ' . get_post_meta($shortcode_id, 'fleet_wrap_classes', true) : '';
$single_fleet_classes = get_post_meta($shortcode_id, 'single_fleet_classes', true) ? ' ' . get_post_meta($shortcode_id, 'single_fleet_classes', true) : '';
$basic_style = get_post_meta($shortcode_id, 'basic_style', true) == 'yes' ? ' basic-styling' : '';
$price_text = get_post_meta($shortcode_id, 'price_text', true);
$display_selected_vehicles = get_post_meta($shortcode_id, 'display_selected_vehicles', true);
$display_elements_wrapper = get_post_meta($shortcode_id, 'display_elements_wrapper', true);
$elements_wrapper_data = get_post_meta($shortcode_id, 'elements_wrapper_data', true);
$elements_wrapper_data_arr = json_decode($elements_wrapper_data);


$cars_arr = (array) $cars_arr;
if (!empty($cars_arr)) {
    if ($fleet_sorting == 'price_asc') {
        usort($cars_arr, function ($a, $b) {
            $a_price = property_exists($a, 'lowest_price') ? floatval($a->lowest_price) : PHP_FLOAT_MAX;
            $b_price = property_exists($b, 'lowest_price') ? floatval($b->lowest_price) : PHP_FLOAT_MAX;

            return $a_price <=> $b_price;
        });
    } elseif ($fleet_sorting == 'price_desc') {
        usort($cars_arr, function ($a, $b) {
            $a_price = property_exists($a, 'lowest_price') ? floatval($a->lowest_price) : PHP_FLOAT_MIN;
            $b_price = property_exists($b, 'lowest_price') ? floatval($b->lowest_price) : PHP_FLOAT_MIN;

            return $b_price <=> $a_price;
        });
    }


    // Display selected vehicles logic
    if ($display_selected_vehicles == 'yes' && !empty($selected_vehicles)) {
        $selected_cars = array();
        foreach ($cars_arr as $car) {
            if (in_array($car->id, $selected_vehicles)) {
                $selected_cars[] = $car;
            }
        }
        if (empty($selected_cars)) {
            $selected_cars = $cars_arr;
        }    
        
        // Sorting logic based on selected IDs
        $sorted_cars = [];

        if (!empty($selected_vehicles)) {
            
            foreach ($selected_vehicles as $selected_id) {
                // Use array_filter to find matching cars
                $matching_car = array_filter($selected_cars, function ($car) use ($selected_id) {
                    return $car->id == $selected_id;
                });

                // If there are matching cars, add the first one to sorted_cars
                if (!empty($matching_car)) {
                    $sorted_cars[] = reset($matching_car);
                }
            }
        }
        $cars_arr = $sorted_cars;
    }
}

$db_id = get_post_meta( $shortcode_id, 'gocars_database', true ); //gocars database is Not being used anymore
$online_admin_link = ($db_id != '' && get_post_meta( $shortcode_id, 'online_admin_link', true ) == '') ? get_post_meta( $db_id, 'online_admin_link', true ) : get_post_meta( $shortcode_id, 'online_admin_link', true );
$domain_slug = ($db_id != '' && get_post_meta( $shortcode_id, 'domain', true ) == '') ? get_post_meta( $db_id, 'domain', true ) : get_post_meta( $shortcode_id, 'domain', true );
$language_param = ($option_arr->o_translate_website == 1 && $language != '') ? '&lang='.$language : '';

$getGcVehicleTypes = json_decode(wp_unslash(get_post_meta( $shortcode_id, 'vehicle_data', true )));
$vehicle_types_row = !empty($getGcVehicleTypes) && count($getGcVehicleTypes) > 1 ? true : false;



if ($cars_arr) {
    ?>
    <ul data-code="<?php echo $shortcode_id; ?>" data-shortcode_type="fleet" class="fleet-collection-wrap <?php echo $fleet_wrap_classes; ?><?php echo $basic_style; ?>">
        <?php 
        
        foreach($cars_arr as $key => $car) { 
            
            if ($car->status == 'T') {
                
                $image = $car->thumb_path;
                $order = 0;
                $position = 0;
                $make_model = false;
                $vehicle_type_param = $vehicle_types_row ? '&vehicle_type=' . $car->vehicle_type : '';
                ?>
                <li class="single-fleet-wrap<?php echo $single_fleet_classes; ?>">
                    <a class="gc-car_search" href="<?php echo 'https://' . $domain_slug . '.gocars.gr/?model_id=' . $car->id . $vehicle_type_param . $language_param; ?>">
                        <?php 
                        $rent_type = '';
                        if (isset($label_arr->reservation) || isset($label_arr->day)) {
                            $rent_type = $car->rent_type == 'reservation' ? $label_arr->reservation : $label_arr->day;
                        }
                        $rent_type = $rent_type == '' ? $car->rent_type : __('day','gocars');

                        if ($display_elements_wrapper == 'yes' && !empty($elements_wrapper_data_arr)) {
                            foreach ($elements_wrapper_data_arr as $row => $wrapper) {
                                ?>
                                <div class="inner-wrapper inner-wrapper-content-<?php echo $row; ?>">
                                    <?php
                                    foreach ($wrapper as $key => $value) {
                                        if ($value =='image'):
                                            ?>
                                            <div class="gc-image-wrap" style="order:<?php echo $key; ?>">
                                                <?php 
                                                if( !empty($image) ): ?>
                                                    <img class="contain" loading="lazy" src="<?php echo $image; ?>" alt="<?php echo $car->make_name . ' ' . $car->model_name; ?>"/>
                                                <?php endif;?>
                                            </div>
                                            <?php
                                        endif;
                                        if (($value =='make' || $value == 'model') && !$make_model):
                                            ?>
                                            <p class="gc-car_name" style="order:<?php echo $key; ?>">
                                                <?php echo '<span data-name="make">' . $car->make_name . '</span> <span data-name="model">' . $car->model_name . '</span>'; ?>
                                            </p>
                                            <?php
                                            $make_model = true;
                                        endif;
                                        if ($value == 'type'):
                                            ?>
                                            <p class="gc-car_category" style="order:<?php echo $key; ?>">
                                                <?php _e($car->type_name,'gocars'); ?>
                                            </p>
                                            <?php
                                        endif;
                                        if ($value == 'description'):
                                            ?>
                                            <span class="gc-car_description" style="order:<?php echo $key; ?>">
                                                <?php _e($car->model_description,'gocars'); ?>
                                            </span>
                                            <?php
                                        endif;
                                        if ($value == 'features'):
                                            ?>
                                            <ul class="gc-car_features" style="order:<?php echo $key; ?>">
                                                <?php if ( $car->doors != null && in_array('doors', $car_features) && $car->vehicle_type == 'car') : ?>
                                                    <li data-feature="doors" style="order:<?php echo $position++; ?>;<?php echo $car->doors < 1 ? 'display: none;' : '';?>">
                                                        <span class="icon-car-doors"></span>
                                                        <p><?php echo $car->doors; ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->passengers != null && in_array('passengers', $car_features)) : ?>
                                                    <li data-feature="passengers" style="order:<?php echo $position++; ?>;<?php echo $car->passengers < 1 ? 'display: none;' : '';?>">
                                                        <span class="icon-seat"></span>
                                                        <p><?php echo $car->passengers; ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->luggages != null && in_array('luggages', $car_features)) : ?>
                                                    <li data-feature="luggages" style="order:<?php echo $position++; ?>;<?php echo $car->luggages < 1 ? 'display: none;' : '';?>">
                                                        <span class="icon-luggage"></span>
                                                        <p><?php echo $car->luggages; ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->handbags != null && in_array('handbags', $car_features)) : ?>
                                                    <li data-feature="handbags" style="order:<?php echo $position++; ?>;<?php echo $car->handbags < 1 ? 'display: none;' : '';?>">
                                                        <span class="icon-handbag"></span>
                                                        <p><?php echo $car->handbags; ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->transmission != null && in_array('transmission', $car_features)) : ?>
                                                    <li data-feature="transmission" style="order:<?php echo $position++; ?>;<?php echo $car->transmission == '' ? 'display: none;' : '';?>">
                                                        <span class="icon-<?php echo $car->transmission == 'manual' ? 'manual' : 'auto'; ?>"></span>
                                                        <p><?php _e(ucfirst($car->transmission),'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->air_condition != null && in_array('air_condition', $car_features) && $car->vehicle_type == 'car') : ?>
                                                    <li data-feature="air_condition" style="order:<?php echo $position++; ?>;<?php echo $car->air_condition == 'noaircondition' ? 'display: none;' : '';?>">
                                                        <span class="icon-clima"></span>
                                                        <?php $air_condition = $car->air_condition == 'noaircondition' ? 'No A/C' : 'A/C'; ?>
                                                        <p><?php _e($air_condition,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->fuel != null && in_array('fuel', $car_features)) : ?>
                                                    <li data-feature="fuel" style="order:<?php echo $position++; ?>">
                                                        <span class="icon-fuel"></span>
                                                        <p><?php _e(ucfirst($car->fuel),'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->abs != null && in_array('abs', $car_features)) : ?>
                                                    <li data-feature="abs" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-abs"></span>
                                                        <?php $abs = $car->abs == 'F' ? 'No' : 'Yes'; ?>
                                                        <p><?php _e($abs,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->bluetooth != null && in_array('bluetooth', $car_features)) : ?>
                                                    <li data-feature="bluetooth" style="order:<?php echo $position++; ?>;<?php echo $car->bluetooth == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-bluetooth"></span>
                                                        <?php $bluetooth = $car->bluetooth == 'F' ? 'No' : 'Yes'; ?>
                                                        <p><?php _e($bluetooth,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->navigation != null && in_array('navigation', $car_features)) : ?>
                                                    <li data-feature="navigation" style="order:<?php echo $position++; ?>;<?php echo $car->navigation == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-navigation"></span>
                                                        <?php $navigation = $car->navigation == 'F' ? 'No' : 'Navigation'; ?>
                                                        <p><?php _e($navigation,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->usb != null && in_array('usb', $car_features)) : ?>
                                                    <li data-feature="usb" style="order:<?php echo $position++; ?>;<?php echo $car->usb == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-usb"></span>
                                                        <?php $usb = $car->usb == 'F' ? 'No' : 'USB'; ?>
                                                        <p><?php _e($usb,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->keyless != null && in_array('keyless', $car_features)) : ?>
                                                    <li data-feature="keyless" style="order:<?php echo $position++; ?>;<?php echo $car->keyless == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-keyless"></span>
                                                        <?php $keyless = $car->keyless == 'F' ? 'No' : 'Keyless'; ?>
                                                        <p><?php _e($keyless,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->rear_trunk != null && in_array('rear_trunk', $car_features) && $car->vehicle_type != 'car') : ?>
                                                    <li data-feature="rear_trunk" style="order:<?php echo $position++; ?>;<?php echo $car->rear_trunk == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-rear-trunk"></span>
                                                        <?php $rear_trunk = $car->rear_trunk == 'F' ? 'No' : 'Yes'; ?>
                                                        <p><?php _e($rear_trunk,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->cc != null && in_array('cc', $car_features)) : ?>
                                                    <li data-feature="cc" style="order:<?php echo $position++; ?>;<?php echo $car->cc == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-cc"></span>
                                                        <?php $cc = $car->cc == 'F' ? 'No' : 'Yes'; ?>
                                                        <p><?php _e( $car->cc,'gocars' ); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->under_seat_space != null && in_array('under_seat_space', $car_features) && $car->under_seat_space == 'moto') : ?>
                                                    <li data-feature="under_seat_space" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-under-seat-space"></span>
                                                        <?php $under_seat_space = $car->under_seat_space == 'F' ? 'No' : 'Yes'; ?>
                                                        <p><?php _e($under_seat_space,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->antispeed != null && in_array('antispeed', $car_features) && $car->antispeed == 'car') : ?>
                                                    <li data-feature="antispeed" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-antispeed"></span>
                                                        <?php $antispeed = $car->antispeed == 'F' ? 'No' : 'Anti-Speed'; ?>
                                                        <p><?php _e($antispeed,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->apple_carplay != null && in_array('apple_carplay', $car_features) && $car->apple_carplay == 'car') : ?>
                                                    <li data-feature="apple_carplay" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-apple"></span>
                                                        <?php $apple_carplay = $car->apple_carplay == 'F' ? 'No' : 'Apple Car Play'; ?>
                                                        <p><?php _e($apple_carplay,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                                <?php if ( $car->android_auto != null && in_array('android_auto', $car_features) && $car->android_auto == 'car') : ?>
                                                    <li data-feature="android_auto" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                        <span class="icon-android"></span>
                                                        <?php $android_auto = $car->android_auto == 'F' ? 'No' : 'Android Auto'; ?>
                                                        <p><?php _e($android_auto,'gocars'); ?></p>
                                                    </li>
                                                <?php endif; ?>
                                            </ul>
                                        <?php
                                        endif;
                                        if ($value == 'price' && property_exists($car, 'lowest_price') && $car->lowest_price > 0):
                                            ?>
                                            <div class="gc-car_price" style="order:<?php echo $key; ?>">
                                                <?php 
                                                $price = number_format($car->lowest_price,2);
                                                if ($price_text != '') {
                                                    $price_content = str_replace(array('{price}'), '<p class="price marg-left">'.$price.'</p>', $price_text); 
                                                    echo $price_content;
                                                } else {
                                                    ?>
                                                    <span><?php echo __( $label_arr->from, 'gocars' ); ?></span>
                                                    <p class="price"><?php echo $price; ?><span>€</span></p>
                                                    <span class="rent-type">/<?php _e($rent_type,'gocars'); ?></span>
                                                    <?php
                                                }
                                                ?>
                                            </div>
                                            <?php
                                        endif;
                                        if ($value == 'button'):
                                            ?>
                                            <button class="gc-car_button button<?php echo $button_classes; ?>" style="order:<?php echo $key; ?>">
                                                <?php _e($button_text,'gocars'); ?>
                                            </button>
                                            <?php
                                        endif;
                                    } 
                                    ?>
                                </div>
                                <?php
                            }
                        } else {
                            foreach ($car_info_display as $key => $value) {
                                if ($value =='image'):
                                    ?>
                                    <div class="gc-image-wrap" style="order:<?php echo $key; ?>">
                                        <?php 
                                        if( !empty($image) ): ?>
                                            <img class="contain" loading="lazy" src="<?php echo $image; ?>" alt="<?php echo $car->make_name . ' ' . $car->model_name; ?>"/>
                                        <?php endif;?>
                                    </div>
                                    <?php
                                endif;
                                if (($value =='make' || $value == 'model') && !$make_model):
                                    ?>
                                    <p class="gc-car_name" style="order:<?php echo $key; ?>">
                                        <?php echo '<span data-name="make">' . $car->make_name . '</span> <span data-name="model">' . $car->model_name . '</span>'; ?>
                                    </p>
                                    <?php
                                    $make_model = true;
                                endif;
                                if ($value == 'type'):
                                    ?>
                                    <p class="gc-car_category" style="order:<?php echo $key; ?>">
                                        <?php _e($car->type_name,'gocars'); ?>
                                    </p>
                                    <?php
                                endif;
                                if ($value == 'description'):
                                    ?>
                                    <span class="gc-car_description" style="order:<?php echo $key; ?>">
                                        <?php _e($car->model_description,'gocars'); ?>
                                    </span>
                                    <?php
                                endif;
                                if ($value == 'features'):
                                    ?>
                                    <ul class="gc-car_features" style="order:<?php echo $key; ?>">
                                        <?php if ( $car->doors != null && in_array('doors', $car_features) && $car->vehicle_type == 'car') : ?>
                                            <li data-feature="doors" style="order:<?php echo $position++; ?>;<?php echo $car->doors < 1 ? 'display: none;' : '';?>">
                                                <span class="icon-car-doors"></span>
                                                <p><?php echo $car->doors; ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->passengers != null && in_array('passengers', $car_features)) : ?>
                                            <li data-feature="passengers" style="order:<?php echo $position++; ?>;<?php echo $car->passengers < 1 ? 'display: none;' : '';?>">
                                                <span class="icon-seat"></span>
                                                <p><?php echo $car->passengers; ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->luggages != null && in_array('luggages', $car_features)) : ?>
                                            <li data-feature="luggages" style="order:<?php echo $position++; ?>;<?php echo $car->luggages < 1 ? 'display: none;' : '';?>">
                                                <span class="icon-luggage"></span>
                                                <p><?php echo $car->luggages; ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->handbags != null && in_array('handbags', $car_features)) : ?>
                                            <li data-feature="handbags" style="order:<?php echo $position++; ?>;<?php echo $car->handbags < 1 ? 'display: none;' : '';?>">
                                                <span class="icon-handbag"></span>
                                                <p><?php echo $car->handbags; ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->transmission != null && in_array('transmission', $car_features)) : ?>
                                            <li data-feature="transmission" style="order:<?php echo $position++; ?>;<?php echo $car->transmission == '' ? 'display: none;' : '';?>">
                                                <span class="icon-<?php echo $car->transmission == 'manual' ? 'manual' : 'auto'; ?>"></span>
                                                <p><?php _e(ucfirst($car->transmission),'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->air_condition != null && in_array('air_condition', $car_features) && $car->vehicle_type == 'car') : ?>
                                            <li data-feature="air_condition" style="order:<?php echo $position++; ?>;<?php echo $car->air_condition == 'noaircondition' ? 'display: none;' : '';?>">
                                                <span class="icon-clima"></span>
                                                <?php $air_condition = $car->air_condition == 'noaircondition' ? 'No A/C' : 'A/C'; ?>
                                                <p><?php _e($air_condition,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->fuel != null && in_array('fuel', $car_features)) : ?>
                                            <li data-feature="fuel" style="order:<?php echo $position++; ?>">
                                                <span class="icon-fuel"></span>
                                                <p><?php _e(ucfirst($car->fuel),'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->abs != null && in_array('abs', $car_features)) : ?>
                                            <li data-feature="abs" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-abs"></span>
                                                <?php $abs = $car->abs == 'F' ? 'No' : 'Yes'; ?>
                                                <p><?php _e($abs,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->bluetooth != null && in_array('bluetooth', $car_features)) : ?>
                                            <li data-feature="bluetooth" style="order:<?php echo $position++; ?>;<?php echo $car->bluetooth == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-bluetooth"></span>
                                                <?php $bluetooth = $car->bluetooth == 'F' ? 'No' : 'Yes'; ?>
                                                <p><?php _e($bluetooth,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->navigation != null && in_array('navigation', $car_features)) : ?>
                                            <li data-feature="navigation" style="order:<?php echo $position++; ?>;<?php echo $car->navigation == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-navigation"></span>
                                                <?php $navigation = $car->navigation == 'F' ? 'No' : 'Navigation'; ?>
                                                <p><?php _e($navigation,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->usb != null && in_array('usb', $car_features)) : ?>
                                            <li data-feature="usb" style="order:<?php echo $position++; ?>;<?php echo $car->usb == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-usb"></span>
                                                <?php $usb = $car->usb == 'F' ? 'No' : 'USB'; ?>
                                                <p><?php _e($usb,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->keyless != null && in_array('keyless', $car_features)) : ?>
                                            <li data-feature="keyless" style="order:<?php echo $position++; ?>;<?php echo $car->keyless == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-keyless"></span>
                                                <?php $keyless = $car->keyless == 'F' ? 'No' : 'Keyless'; ?>
                                                <p><?php _e($keyless,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->rear_trunk != null && in_array('rear_trunk', $car_features) && $car->vehicle_type != 'car') : ?>
                                            <li data-feature="rear_trunk" style="order:<?php echo $position++; ?>;<?php echo $car->rear_trunk == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-rear-trunk"></span>
                                                <?php $rear_trunk = $car->rear_trunk == 'F' ? 'No' : 'Yes'; ?>
                                                <p><?php _e($rear_trunk,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->cc != null && in_array('cc', $car_features)) : ?>
                                            <li data-feature="cc" style="order:<?php echo $position++; ?>;<?php echo $car->cc == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-cc"></span>
                                                <?php $cc = $car->cc == 'F' ? 'No' : 'Yes'; ?>
                                                <p><?php _e( $car->cc,'gocars' ); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->under_seat_space != null && in_array('under_seat_space', $car_features) && $car->under_seat_space == 'moto') : ?>
                                            <li data-feature="under_seat_space" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-under-seat-space"></span>
                                                <?php $under_seat_space = $car->under_seat_space == 'F' ? 'No' : 'Yes'; ?>
                                                <p><?php _e($under_seat_space,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->antispeed != null && in_array('antispeed', $car_features) && $car->antispeed == 'car') : ?>
                                            <li data-feature="antispeed" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-antispeed"></span>
                                                <?php $antispeed = $car->antispeed == 'F' ? 'No' : 'Anti-Speed'; ?>
                                                <p><?php _e($antispeed,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->apple_carplay != null && in_array('apple_carplay', $car_features) && $car->apple_carplay == 'car') : ?>
                                            <li data-feature="apple_carplay" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-apple"></span>
                                                <?php $apple_carplay = $car->apple_carplay == 'F' ? 'No' : 'Apple Car Play'; ?>
                                                <p><?php _e($apple_carplay,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                        <?php if ( $car->android_auto != null && in_array('android_auto', $car_features) && $car->android_auto == 'car') : ?>
                                            <li data-feature="android_auto" style="order:<?php echo $position++; ?>;<?php echo $car->abs == 'F' ? 'display: none;' : '';?>">
                                                <span class="icon-android"></span>
                                                <?php $android_auto = $car->android_auto == 'F' ? 'No' : 'Android Auto'; ?>
                                                <p><?php _e($android_auto,'gocars'); ?></p>
                                            </li>
                                        <?php endif; ?>
                                    </ul>
                                <?php
                                endif;
                                if ($value == 'price' && property_exists($car, 'lowest_price') && $car->lowest_price > 0):
                                    ?>
                                    <div class="gc-car_price" style="order:<?php echo $key; ?>">
                                        <?php 
                                        $price = number_format($car->lowest_price,2);
                                        if ($price_text != '') {
                                            $price_content = str_replace(array('{price}'), '<p class="price marg-left">'.$price.'</p>', $price_text); 
                                            echo $price_content;
                                        } else {
                                            ?>
                                            <span><?php echo __( $label_arr->from, 'gocars' ); ?></span>
                                            <p class="price"><?php echo $price; ?><span>€</span></p>
                                            <span class="rent-type">/<?php _e($rent_type,'gocars'); ?></span>
                                            <?php
                                        }
                                        ?>
                                    </div>
                                    <?php
                                endif;
                                if ($value == 'button'):
                                    ?>
                                    <button class="gc-car_button button<?php echo $button_classes; ?>" style="order:<?php echo $key; ?>">
                                        <?php _e($button_text,'gocars'); ?>
                                    </button>
                                    <?php
                                endif;
                            } 
                        }
                        ?>
                    </a>

                </li>

                <?php 
                if ( ! empty( $fleet_number ) ) {
                    $number++;
                    if ($number == $fleet_number) break;
                }
            }
        }
        ?>
    </ul>
<?php 
}

?>
