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

$language_locale = json_decode(get_post_meta( $shortcode_id, 'language_locale', true ));
// if empty field check file 
if (empty($language_locale) && file_exists( WP_PLUGIN_DIR . '/gocars-online/settings.json')) {
    $json_data = json_decode(file_get_contents(WP_PLUGIN_DIR . '/gocars-online/settings.json'), true)['language_locale'];
    $language_locale = (object)json_decode($json_data, true);
    foreach ($language_locale as $key => $value) {
        $language_locale->$key = (object) $value;
        $language_locale->$key->labels = (object) $value['labels'];
    }
}

$locale = get_locale();
$label_arr = array();

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;
    }
}

// $dates_data = get_post_meta( $shortcode_id, 'dates_data', true );
$dates_data = get_post_meta_without_cache($shortcode_id, 'dates_data');

// Define the cookie name
$cookie_name = "dates_data";
 
// Check if the cookie is not set
if (!isset($_COOKIE[$cookie_name])) {
    // Set the cookie to expire in 1 day (86400 seconds)
    setcookie($cookie_name, $dates_data, time() + 86400, "/");
}
// $data = isset($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name] != null ? json_decode(wp_unslash($_COOKIE[$cookie_name])) : json_decode($dates_data); // not used
$data = json_decode(wp_unslash($dates_data));
// if empty field check file 
if (empty($data) && json_decode(get_post_meta( $shortcode_id, 'dates_data', true )) && file_exists( WP_PLUGIN_DIR . '/gocars-online/settings.json')) {
    $json_data = json_decode(file_get_contents(WP_PLUGIN_DIR . '/gocars-online/settings.json'), true)['dates_data'];
    $data = (object)json_decode($json_data, true);
}

// FIELDS
$form_display = get_post_meta( $shortcode_id, 'form_display', true );
$vehicle_display = get_post_meta( $shortcode_id, 'vehicle_display', true );
$vehicle_type_border = get_post_meta( $shortcode_id, 'vehicle_type_border', true );
$header_text_color = get_post_meta( $shortcode_id, 'header_text_color', true );
$header_background_color = get_post_meta( $shortcode_id, 'header_background_color', true );
$header_text_content = get_post_meta( $shortcode_id, 'header_text_content', true );
$db_id = get_post_meta( $shortcode_id, 'gocars_database', true ); //gocars database is not being used anymore
$show_footer = get_post_meta( $shortcode_id, 'show_footer', true );
$footer_text = get_post_meta( $shortcode_id, 'footer_text', true );
$loading_effect = get_post_meta( $shortcode_id, 'loading_effect', true );
$online_admin_link = get_post_meta( $shortcode_id, 'online_admin_link', true );
$domain_slug = get_post_meta( $shortcode_id, 'domain', true );
$search_text = get_post_meta( $shortcode_id, 'search_text', true );

$display_keypoints = get_post_meta($shortcode_id, 'display_keypoints', true);
$keypoints_color = get_post_meta( $shortcode_id, 'keypoints_color', true );
$keypoints_data = get_post_meta($shortcode_id, 'keypoints_data', true);
$keypoints_data_arr = json_decode($keypoints_data);


$option_arr = json_decode(wp_unslash(get_post_meta( $shortcode_id, 'options_data', true )));
// if empty field check file 
if (empty($option_arr) && file_exists( WP_PLUGIN_DIR . '/gocars-online/settings.json')) {
    $json_data = json_decode(file_get_contents(WP_PLUGIN_DIR . '/gocars-online/settings.json'), true)['options_data'];
    $option_arr = (object)json_decode($json_data, true);
}

$locations_arr = json_decode(wp_unslash(get_post_meta( $shortcode_id, 'locations_data', true ))) == null ? json_decode(get_post_meta( $shortcode_id, 'locations_data', true ))->$language : json_decode(wp_unslash(get_post_meta( $shortcode_id, 'locations_data', true )))->$language;
// if empty field check file 
if (empty($locations_arr) && file_exists( WP_PLUGIN_DIR . '/gocars-online/settings.json')) {
    $json_data = json_decode(file_get_contents(WP_PLUGIN_DIR . '/gocars-online/settings.json'), true)['locations_data'];
    $locations_arr = (object) json_decode($json_data, true)[$language];
    foreach ($locations_arr as $key => $value) {
        $locations_arr->$key = (object) $value;
    }
}

$age_group_arr = json_decode(wp_unslash(get_post_meta( $shortcode_id, 'age_data', true )));
// if empty field check file 
if (empty($age_group_arr) && file_exists( WP_PLUGIN_DIR . '/gocars-online/settings.json')) {
    $json_data = json_decode(file_get_contents(WP_PLUGIN_DIR . '/gocars-online/settings.json'), true)['age_data'];
    $age_group_arr = json_decode($json_data, true);
    foreach ($age_group_arr as $key => $value) {
        $age_group_arr[$key] = (object) $value;
    }
}
$getGcVehicleTypes = json_decode(wp_unslash(get_post_meta( $shortcode_id, 'vehicle_data', true )));
 
$selected_locations = '';
if ( ! empty( get_post_meta( $shortcode_id, 'selected_locations', true ) ) ) {
    $selected_locations = get_post_meta( $shortcode_id, 'selected_locations', true );
    $selected_locations = explode(',', $selected_locations);
}

$display_selected_locations = get_post_meta($shortcode_id, 'display_selected_locations', true);
// Display selected locations logic
if ($display_selected_locations == 'yes') {
    foreach ($locations_arr as $location) {
        if (in_array($location->id, $selected_locations)) {
            $selected_locations_[] = $location;
        }
    }
    $selected_locations_ = $locations_arr; // If not displaying selected locations, use all cars
    // Sorting logic based on selected IDs
    $sorted_locations = [];

    foreach ($selected_locations as $selected_id) {
        $matching_location = array_filter($selected_locations_, function ($location) use ($selected_id) {
            return $location->id == $selected_id;
        });

        if (!empty($matching_location)) {
            $sorted_locations[] = reset($matching_location);
        }
        $locations_arr = $sorted_locations;
    }
}

$is_checked = false;
if ($option_arr->o_different_location_preselect == 1) { 
	$is_checked = true;
} else {
	if (isset($_REQUEST['pickup_id']) && isset($_REQUEST['return_id']) && $_REQUEST['pickup_id'] != $_REQUEST['return_id'] ) {
		$is_checked = true;
	} else {
		$is_checked = false;
	}
}

$default_age_group = $option_arr->o_default_age_group;
$default_location = $option_arr->o_default_location;

//PICKUP/RETURN

if(isset($_REQUEST['pickup_id']) && $_REQUEST['pickup_id'] == '') {
	$_REQUEST['pickup_id'] = $option_arr->o_default_location;
}
if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] == '') {
	$_REQUEST['return_id'] = $option_arr->o_default_location;
}

// ------------------------ //

// options
$timepicker_element = get_post_meta( $shortcode_id, 'timepicker', true ); // timepicker_select, timepicker_input select
$time_space = $option_arr->o_timer_step; // 15, 30, 60 select
$default_hour = $option_arr->o_default_hour;

if ($time_space == 60) {
	$max_hour_timepicker = '23:00';
} elseif ($time_space == 30) {
	$max_hour_timepicker = '23:30';
} elseif ($time_space == 15) {
	$max_hour_timepicker = '23:45';
}
$default_max_hour = $max_hour_timepicker;

$time_hours = array("00","01","02","03","04","05","06","07","08","09",10,11,12,13,14,15,16,17,18,19,20,21,22,23);
if ($time_space == 60) {
	$time_minutes = array("00");
} elseif ($time_space == 30) {
	$time_minutes = array("00",30);
} else {
	$time_minutes = array("00",15,30,45);
}


// ------------------------ //

$domain = $_SERVER['HTTP_HOST'];
$domain = explode('.', str_replace('www.', '', $domain));
$subdomain = $domain[0];


$last_search = json_decode(get_post_meta( $shortcode_id, 'attempts_data', true ));
$last_search_url = '';
if ($last_search != null) {
    $last_search_url = $last_search->url;
}

$user_area = $option_arr->o_allow_user_area;

$full_width_row = false;
$age_group_visible = (!empty($option_arr) && property_exists($option_arr, 'o_age_group_visible')) ? $option_arr->o_age_group_visible : 1;
if ($age_group_visible == 0) {
    $full_width_row = true;
}

$vehicle_types_row = !empty($getGcVehicleTypes) && count($getGcVehicleTypes) > 1 ? true : false;
$language_param = ($option_arr->o_translate_website == 1 && $language != '') ? '?lang='.$language : '';
$selected_vehicle_type = 'car';
$selected_vehicle_type = $vehicle_types_row && isset($option_arr->o_selected_vehicle_type) ? $option_arr->o_selected_vehicle_type : $selected_vehicle_type;
$vehicle_type_selected_condition = false;
if (!empty($getGcVehicleTypes)) {
	foreach ($getGcVehicleTypes as $key => $type) { 
	    if ($type == $selected_vehicle_type) {
	        $vehicle_type_selected_condition = true;
	    }
	}
	$selected_vehicle_type = $vehicle_type_selected_condition ? $selected_vehicle_type : '';
}


$areas_arr = array();
$location_pricing = false;
if (isset($option_arr->o_location_pricing) && $option_arr->o_location_pricing == 1) {
    $location_pricing = true;
    foreach ($locations_arr as $location) { 
        if (isset($location->area_name) && $location->area_name != '' && !in_array($location->area_name, $areas_arr)) {
            $areas_arr[] = $location->area_name;
        }
    }
}


if ($_SERVER["REMOTE_ADDR"] == '2.85.47.143') {
    // echo '<pre>';
    // var_dump($label_arr);
    // echo '</pre>';
    // $dotenv = parse_ini_file(realpath(__DIR__ . '/../../.env'));
    // var_dump($dotenv);
}

 
?>

<form action="#" id="search_form-<?php echo $shortcode_id; ?>"
    data-form="https://<?php echo $domain_slug; ?>.gocars.gr/"
    data-shortcode_type="search_form"
    data-locationpricing="<?php echo $option_arr->o_location_pricing; ?>"
    data-domain="<?php echo $domain_slug; ?>"
    data-shortcode="<?php echo $shortcode_id; ?>"
    class="gc-search-form<?php echo (esc_attr( $form_display ) == 'H' ? ' horizontal' : ' vertical'); ?><?php echo $user_area == 1 ? ' user-area-form' : ''; ?>">
    <div class="header-outer-wrapper">

        <div class="search_form-header main-form-header<?php echo ($vehicle_types_row) ? ' vehicle-type-header' : '' ?>">
            <p class="search-title">
                <?php echo ($header_text_content == '') ? __($label_arr->start_search,'gocars') : esc_attr( $header_text_content ) ; ?>
            </p>
        </div>
        <?php 
        if ($user_area == 1) {
            ?>
            <a href="https://<?php echo $domain_slug; ?>.gocars.gr/user-area<?php echo $language_param; ?>" class="search_form-header user-area-header<?php echo ($vehicle_types_row) ? ' vehicle-type-header' : '' ?>">
                <p class="search-title">
                    <?php echo __($label_arr->existing_client,'gocars') ; ?>
                </p>
            </a>
            <?php
        }
        ?>
    </div>

    <?php
    if ($form_display == 'H' && $vehicle_types_row) {
        ?>
        <fieldset>
            <div class="search_form-field vehicle-field-form vehicles-swiper swiper horizontal-field-row<?php echo ($loading_effect == 'opacity') ? " input-opacity" : "" ;?><?php echo ($loading_effect == 'blur') ? " blur-effect" : "" ;?>">
                <div class="form-group vehicles-group swiper-wrapper">
                    <?php 
                    foreach ($getGcVehicleTypes as $key => $type) { 
                        ?>
                        <label for="<?php echo $type; ?>-horizontal-<?php echo $shortcode_id; ?>" title="<?php echo $type; ?>" class="swiper-slide label-button<?php echo $type == $selected_vehicle_type ? ' active' : ''; ?>"<?php echo $type == $selected_vehicle_type ? ' style="order: -1;"' : ''; ?>>
                            <input name="vehicle" id="<?php echo $type; ?>-horizontal-<?php echo $shortcode_id; ?>" type="radio" value="<?php echo $type; ?>" >
                            <span class="icon-v3-<?php echo $type; ?>"></span>
                            <p><?php echo isset($label_arr->$type) && $label_arr->$type != '' ? __($label_arr->$type,'gocars') : __($type,'gocars') ; ?></p>
                        </label>
                    <?php } ?>
                </div>
            </div>
            <legend class="no-font"><?php echo __('Vehicle type','gocars') ; ?></legend>
        </fieldset>
        <?php
    }
    ?>
    <div class="search_form-body">

        <div class="fields-content-wrap locations-fields-wrap">

            <?php 
            if ($vehicle_types_row) {
                ?>
                <fieldset>
                    <div class="search_form-field vehicles-swiper swiper vehicle-field-form">
                        <div class="form-group vehicles-group swiper-wrapper">
                            <?php 
                            foreach ($getGcVehicleTypes as $key => $type) { 
                                ?>
                                <label for="<?php echo $type; ?>-<?php echo $shortcode_id; ?>" title="<?php echo $type; ?>" class="swiper-slide label-button<?php echo $type == $selected_vehicle_type ? ' active' : ''; ?>"<?php echo $type == $selected_vehicle_type ? ' style="order: -1;"' : ''; ?>>
                                    <input name="vehicle" id="<?php echo $type; ?>-<?php echo $shortcode_id; ?>" type="radio" value="<?php echo $type; ?>" >
                                    <span class="icon-v3-<?php echo $type; ?>"></span>
                                    <p><?php echo isset($label_arr->$type) && $label_arr->$type != '' ? __($label_arr->$type,'gocars') : __($type,'gocars') ; ?></p>
                                </label>
                            <?php } ?>
                        </div>
                    </div>
                    <legend class="no-font"><?php echo __('Vehicle type','gocars') ; ?></legend>
                </fieldset>
                <?php
            }
            ?>

            <div class="search_form-field pickup-field location-wrap">
                <label class="form-label" for="pickup_id-<?php echo $shortcode_id; ?>"><?php _e($label_arr->pickup_location ?? 'Pickup Location','gocars'); ?></label>
                <div class="select-item-wrap form-item location-item">
                    <span class="icon-pin"></span>
                    <select name="pickup_id" id="pickup_id-<?php echo $shortcode_id; ?>" data-label="<?php _e($label_arr->choose_location ?? 'Choose Location','gocars'); ?>" class="form-control has-icon select-2-item location-form required<?php echo ($default_location == '' || $default_location == 'none') ? ' placeholder-color' : ''; ?>">
                        <option value="" disabled selected hidden><?php _e($label_arr->location_placeholder ?? 'City, location, area, village or hotel','gocars'); ?></option>
                        <?php 
                        if ($location_pricing && !empty($areas_arr)) {
                            foreach ($areas_arr as $area) {
                                ?>
                                <optgroup label="<?php echo $area; ?>">
                                    <?php foreach ($locations_arr as $location) { 
                                        if ($location->area_name == $area) {
                                            ?>
                                            <option value="<?php echo $location->location_id; ?>"<?php echo ($default_location == $location->location_id) ? ' selected="selected"' : NULL; ?>>
                                                <?php echo stripslashes($location->location_name); ?>
                                            </option>
                                            <?php 
                                        }
                                    } ?>
                                </optgroup>
                                <?php
                            }
                        } else {
                            foreach ($locations_arr as $location) { 
                                ?>
                                <option value="<?php echo $location->location_id; ?>"<?php echo ($default_location == $location->location_id) ? ' selected="selected"' : NULL; ?>>
                                    <?php echo stripslashes($location->location_name); ?>
                                </option>
                                <?php 
                            } 
                        }
                        ?>
                    </select>
                </div>
                <div class="error-message-content">
                    <?php 
                    if (!empty($label_arr->please_fill) && !empty($label_arr->pickup_location)) {
                        _e($label_arr->please_fill . ' ' . $label_arr->pickup_location, 'gocars');
                    } elseif (!empty($label_arr->please_fill)) {
                        _e($label_arr->please_fill . ' Pickup Location', 'gocars');
                    } elseif (!empty($label_arr->pickup_location)) {
                        _e('Please fill ' . $label_arr->pickup_location, 'gocars');
                    } else {
                        _e('Please fill Pickup Location', 'gocars');
                    }
                    ?>
                </div>
            </div>

            <div class="search_form-field different-location-wrapper<?php echo ($loading_effect == 'opacity') ? " input-opacity" : "" ;?><?php echo ($loading_effect == 'blur') ? " blur-effect" : "" ;?>"
		    <?php echo $option_arr->o_different_location_preselect == '1' ? 'style="display:none;"' : '' ;?>>
                <label for="different_location-<?php echo $shortcode_id; ?>" class="form-label">
                    <input  type="checkbox" name="different_location" id="different_location-<?php echo $shortcode_id; ?>" value="<?php echo ($is_checked == true) ? '1' : '0'; ?>"<?php echo ($is_checked == true) ?  ' checked="checked"'  : NULL; ?>/>
                    <?php 
                    $vehicle_display = ($vehicle_display == '') ? __('vehicle','gocars') : esc_attr($vehicle_display) ;
                    // echo sprintf(__('Return %s in different location', 'gocars'), $vehicle_display); 
                    _e($label_arr->different_location ?? 'Return vehicle in different location','gocars');
                    ?>
                </label>
            </div>

            <div class="search_form-field location-wrap dropoff-field<?php echo ($is_checked == true) ? "" : " hide-field" ;?><?php echo ($loading_effect == 'opacity') ? " input-opacity" : "" ;?><?php echo ($loading_effect == 'blur') ? " blur-effect" : "" ;?>">
                <label class="form-label" for="return_id-<?php echo $shortcode_id; ?>"><?php _e($label_arr->dropoff_location ?? 'Drop-off Location','gocars'); ?></label>
                <div class="select-item-wrap form-item location-item">
                    <span class="icon-pin"></span>
                    <select name="return_id" id="return_id-<?php echo $shortcode_id; ?>" data-label="<?php _e($label_arr->choose_location ?? 'Choose Location','gocars'); ?>" class="form-control has-icon select-2-item location-form required<?php echo ($default_location == '' || $default_location == 'none') ? ' placeholder-color' : ''; ?>">
                        <option value="" disabled selected hidden><?php _e($label_arr->location_placeholder ?? 'City, location, area, village or hotel','gocars'); ?></option>
                        <?php 
                        if ($location_pricing && !empty($areas_arr)) {
                            foreach ($areas_arr as $area) {
                                ?>
                                <optgroup label="<?php echo $area; ?>">
                                    <?php foreach ($locations_arr as $location) { 
                                        if ($location->area_name == $area) {
                                            ?>
                                            <option value="<?php echo $location->location_id; ?>"<?php echo ($default_location == $location->location_id) ? ' selected="selected"' : NULL; ?>>
                                                    <?php echo stripslashes($location->location_name); ?>
                                            </option>
                                            <?php 
                                        }
                                    } ?>
                                </optgroup>
                                <?php
                            }
                        } else {
                            foreach ($locations_arr as $location) { 
                                ?>
                                <option value="<?php echo $location->location_id; ?>"<?php echo ($default_location == $location->location_id) ? ' selected="selected"' : NULL; ?>>
                                    <?php echo stripslashes($location->location_name); ?>
                                </option>
                                <?php 
                            } 
                        }
                        ?>
                    </select>
                </div>
                <div class="error-message-content">
                    <?php 
                    if (!empty($label_arr->please_fill) && !empty($label_arr->dropoff_location)) {
                        _e($label_arr->please_fill . ' ' . $label_arr->dropoff_location, 'gocars');
                    } elseif (!empty($label_arr->please_fill)) {
                        _e($label_arr->please_fill . ' Drop-off Location', 'gocars');
                    } elseif (!empty($label_arr->dropoff_location)) {
                        _e('Please fill ' . $label_arr->dropoff_location, 'gocars');
                    } else {
                        _e('Please fill Drop-off Location', 'gocars');
                    }
                    ?>
                </div>
            </div>

        </div>

        <div class="fields-content-wrap dates-fields-wrap">

            <div class="search_form-field date-wrap<?php echo ($loading_effect == 'opacity') ? " input-opacity" : "" ;?><?php echo ($loading_effect == 'blur') ? " blur-effect" : "" ;?>">

                <div class="form-group search-form-inner-wrap">

                    <label class="form-label date_from-label" data-label="<?php _e($label_arr->pickup_date ?? 'Pick-up Date/Time','gocars'); ?>" for="date_from-<?php echo $shortcode_id; ?>"><?php _e($label_arr->pickup_datetime ?? 'Pickup Date and Time','gocars'); ?>*</label>

                    <div id="date_time_pickup-<?php echo $shortcode_id; ?>" class="input-group field-wrapper date-group" data-date="<?php echo $data->pickup; ?>">
                        <div class="date-time-wrap">
                            <span class="icon-calendar"></span>
                            <input type="text" id="date_from-<?php echo $shortcode_id; ?>" name="date_from" class="form-control date-field has-icon required<?php echo ($option_arr->o_preselect_default_dates != 1) ? " hide-form-control" : "" ;?>" value="<?php echo $data->date_from; ?>" placeholder="<?php _e($label_arr->pickup_date,'gocars'); ?>" readonly="readonly"/>
                            <div class="select-item-wrap">
                                <label for="time_from-<?php echo $shortcode_id; ?>" class="form-label no-font"><?php _e($label_arr->time ?? 'Time','gocars'); ?></label>
                                <?php 
                                
                                $booking_starts_splitted = explode(" ", $data->reservation_starts_after);
                                $updated_booking_starts_time = ($booking_starts_splitted[0] != $data->reservation_starts_after) ? '' : $booking_starts_splitted[1];
                                $updated_default_hour = ($data->request_time_from) ? $data->request_time_from : $data->default_hour;
                                if ($timepicker_element == 'timepicker_select') { ?>
                                    <select id="time_from-<?php echo $shortcode_id; ?>" name="time_from" class="form-control timepick time-field required<?php echo (!$updated_default_hour && !$data->request_time_from) ? ' placeholder-color' : '' ; ?>" data-min_hour="<?php echo $data->min_hour; ?>" data-max_hour="<?php echo $data->default_max_hour; ?>">
                                        <option value="" selected hidden disabled><?php _e($label_arr->time ?? 'Time','gocars'); ?></option>
                                        <?php
                                        $selected = (!$data->default_hour && !$data->request_time_from) || $data->default_hour == NULL ? '' : 'selected';
                                        foreach ($time_hours as $hour) {
                                            foreach($time_minutes as $min) {
                                                $hour_minutes = $hour . ':' . $min;
                                                if($hour_minutes < $updated_booking_starts_time )
                                                    echo '<option hidden value="'.$hour_minutes.'">'.$hour_minutes.'</option>';
                                                elseif ($hour_minutes == $updated_default_hour && $hour_minutes > $updated_booking_starts_time)
                                                    echo '<option '.$selected.' value="'.$hour_minutes.'">'.$hour_minutes.'</option>';
                                                elseif ($hour_minutes == $updated_booking_starts_time )
                                                    echo '<option '.$selected.' value="'.$hour_minutes.'">'.$hour_minutes.'</option>';
                                                else
                                                    echo '<option value="'.$hour_minutes.'">'.$hour_minutes.'</option>';
                                            }
                                        } 
                                        ?>
                                    </select>
                                <?php } elseif ($timepicker_element == 'timepicker_input') { 
                                    $time_input = (!$data->default_hour) ? '' : $data->time_from; 
                                    ?>
                                    <input id="time_from-<?php echo $shortcode_id; ?>" type="text" class="form-control timepick time-field has-icon required" name="time_from" placeholder="<?php _e($label_arr->time ?? 'Time','gocars'); ?>" data-display="<?php echo $form_display; ?>" data-min_hour="<?php echo $data->min_hour; ?>" data-max_hour="<?php echo $data->default_max_hour; ?>" value="<?php echo ($data->request_time_from) ? $data->request_time_from : $time_input; ?>" readonly />
                                <?php } ?>
                            </div>
                        </div>
                    </div>

                    <div class="error-message-content">
                        <?php 
                        if (!empty($label_arr->please_fill) && !empty($label_arr->pickup_datetime)) {
                            _e($label_arr->please_fill . ' ' . $label_arr->pickup_datetime, 'gocars');
                        } elseif (!empty($label_arr->please_fill)) {
                            _e($label_arr->please_fill . ' Pick-up Date/Time', 'gocars');
                        } elseif (!empty($label_arr->pickup_datetime)) {
                            _e('Please fill ' . $label_arr->pickup_datetime, 'gocars');
                        } else {
                            _e('Please fill Pick-up Date/Time', 'gocars');
                        }
                        ?>
                    </div>

                </div>

            </div>

        </div>

        <div class="fields-content-wrap dates-fields-wrap">
            <div class="search_form-field date-wrap<?php echo ($loading_effect == 'opacity') ? " input-opacity" : "" ;?><?php echo ($loading_effect == 'blur') ? " blur-effect" : "" ;?>">

                <div class="form-group search-form-inner-wrap">

                    <label class="form-label date_to-label" data-label="<?php _e($label_arr->dropoff_date ?? 'Drop-off Date/Time','gocars'); ?>" for="date_to-<?php echo $shortcode_id; ?>"><?php _e($label_arr->dropoff_datetime ?? 'Dropoff Date and Time','gocars'); ?>*</label>

                    <div id="date_time_dropoff-<?php echo $shortcode_id; ?>" class="input-group field-wrapper date-group" data-date="<?php echo $data->dropoff; ?>">
                        <div class="date-time-wrap">
                            <span class="icon-calendar"></span>
                            <input type="text" id="date_to-<?php echo $shortcode_id; ?>" name="date_to" class="form-control date-field has-icon required<?php echo ($option_arr->o_preselect_default_dates != 1) ? " hide-form-control" : "" ;?>" value="<?php echo $data->date_to; ?>" placeholder="<?php _e($label_arr->dropoff_date,'gocars'); ?>" readonly="readonly"/>
                            <div class="select-item-wrap">
                                <label for="time_to-<?php echo $shortcode_id; ?>" class="form-label no-font"><?php _e($label_arr->time ?? 'Time','gocars'); ?></label>

                                <?php 
                                $updated_minimum_booking_splitted = explode(" ", $data->minimum_reservation_datetime);
                                $updated_minimum_booking_time = ($updated_minimum_booking_splitted[0] != date("Y-m-d", strtotime($data->minimum_reservation_datetime))) ? '00:00' : $updated_minimum_booking_splitted[1];
                                $updated_default_hour = ($data->request_time_to) ? $data->request_time_to : $data->default_hour;
                                
                                if ($timepicker_element == 'timepicker_select') { ?>
                                    <select id="time_to-<?php echo $shortcode_id; ?>" name="time_to" class="form-control time-field has-icon timepick required<?php echo (!$updated_default_hour && !$data->request_time_to) ? ' placeholder-color' : '' ; ?>" data-min_hour="<?php echo $data->min_hour; ?>" data-max_hour="<?php echo $data->default_max_hour; ?>">
                                        <option value="" selected hidden disabled><?php _e($label_arr->time ?? 'Time','gocars'); ?></option>
                                        <?php
                                        $selected = (!$data->default_hour && !$data->request_time_to) ? '' : 'selected';
                                        foreach ($time_hours as $hour) {
                                            foreach($time_minutes as $min) {
                                                $hour_minutes = $hour . ':' . $min;
                                                if($hour_minutes < $updated_minimum_booking_time )
                                                    echo '<option hidden value="'.$hour_minutes.'">'.$hour_minutes.'</option>';
                                                elseif ($hour_minutes == $updated_default_hour && $hour_minutes > $updated_minimum_booking_time)
                                                    echo '<option '.$selected.' value="'.$hour_minutes.'">'.$hour_minutes.'</option>';
                                                // elseif ($hour_minutes == $selected_dropoff_time)
                                                //     echo '<option '.$selected.' value="'.$hour_minutes.'">'.$hour_minutes.'</option>';
                                                // elseif ($hour_minutes == $default_minimum_booking_time )
                                                //     echo '<option '.$selected.' value="'.$hour_minutes.'">'.$hour_minutes.'</option>';
                                                else
                                                    echo '<option value="'.$hour_minutes.'">'.$hour_minutes.'</option>';
                                            }
                                        } 
                                        ?>
                                    </select>
                                <?php } elseif ($timepicker_element == 'timepicker_input') { ?>
                                    <?php 
                                        $updated_minimum_booking_time = (date("Y-m-d", strtotime($data->minimum_reservation_datetime)) == date("Y-m-d", strtotime($data->default_booking_datetime))) ? $updated_minimum_booking_splitted[1] : ''; 
                                        $updated_max_hour_timepicker = (date("Y-m-d", strtotime($data->minimum_reservation_datetime)) == date("Y-m-d", strtotime($data->default_booking_datetime))) ? $data->default_max_hour : ''; 
                                        $time_input = (!$data->default_hour) ? '' : $data->time_to;   
                                    ?>
                                    <input id="time_to-<?php echo $shortcode_id; ?>" type="text" class="form-control time-field has-icon timepick required" placeholder="<?php _e($label_arr->time ?? 'Time','gocars'); ?>" name="time_to" data-display="<?php echo $form_display; ?>" data-min_hour="<?php echo $updated_minimum_booking_time; ?>" data-max_hour="<?php echo $updated_max_hour_timepicker; ?>" value="<?php echo ($data->request_time_to) ? $data->request_time_to : $time_input; ?>" readonly />
                                <?php } ?>
                            </div>
                        </div>
                    </div>

                    <div class="error-message-content">
                        <?php 
                        if (!empty($label_arr->please_fill) && !empty($label_arr->dropoff_datetime)) {
                            _e($label_arr->please_fill . ' ' . $label_arr->dropoff_datetime, 'gocars');
                        } elseif (!empty($label_arr->please_fill)) {
                            _e($label_arr->please_fill . ' Drop-off Date/Time', 'gocars');
                        } elseif (!empty($label_arr->dropoff_datetime)) {
                            _e('Please fill ' . $label_arr->dropoff_datetime, 'gocars');
                        } else {
                            _e('Please fill Drop-off Date/Time', 'gocars');
                        }
                    ?>
                    </div>

                </div>

            </div>

        </div>
        
        <div class="fields-content-wrap age-group-fields-wrap"<?php echo $age_group_visible == 0 ? ' style="display:none;"' : ''; ?>>

            <div class="search_form-field age-wrap<?php echo ($loading_effect == 'opacity') ? " input-opacity" : "" ;?><?php echo ($loading_effect == 'blur') ? " blur-effect" : "" ;?>">
                <label for="age_group_id-<?php echo $shortcode_id; ?>" class="form-label"><?php _e($label_arr->age_group ?? 'Age Group','gocars'); ?>*</label>
                <?php 
                $age_group_placeholder_color = true ;
                foreach ($age_group_arr as $age) { 
                    if ($default_age_group == $age->id && $default_age_group != '') {
                        $age_group_placeholder_color = false;
                    }
                } 
                $age_ranges = array();
                foreach ($age_group_arr as $item) {
                    $age_ranges[] = $item->age_range;
                }
                ?>
                <div class="select-item-wrap form-item">
                    <select name="age_group_id" id="age_group_id-<?php echo $shortcode_id; ?>" class="form-control age-form required<?php echo ($age_group_placeholder_color && count($age_group_arr) > 1) ? ' placeholder-color' : ''; ?>">
                        <option value="" selected disabled hidden>
                            <?php echo implode(', ', $age_ranges); ?>
        				</option>
        				<?php foreach ($age_group_arr as $age) { ?>
        					<option value="<?php echo $age->id;?>"<?php echo ($default_age_group == $age->id || count($age_group_arr) == 1) ? ' selected="selected"' : '' ;?>><?php echo $age->age_range;?></option>
                        <?php } ?>

                    </select>
                </div>
                <div class="error-message-content">
                    <?php 
                        if (!empty($label_arr->please_fill) && !empty($label_arr->age_group)) {
                            _e($label_arr->please_fill . ' ' . $label_arr->age_group, 'gocars');
                        } elseif (!empty($label_arr->please_fill)) {
                            _e($label_arr->please_fill . ' Age Group', 'gocars');
                        } elseif (!empty($label_arr->age_group)) {
                            _e('Please fill ' . $label_arr->age_group, 'gocars');
                        } else {
                            _e('Please fill Age Group', 'gocars');
                        }
                    ?>
                </div>
            </div>

        </div>

        <div class="fields-content-wrap search-fields-wrap<?php echo $full_width_row ? ' full-width-row' : ''; ?>">

            <div class="search_form-field<?php echo ($loading_effect == 'opacity') ? " input-opacity" : "" ;?><?php echo ($loading_effect == 'blur') ? " blur-effect" : "" ;?>">

                <label for="search_button" class="form-label no-font search-label"><?php _e($label_arr->search ?? 'Search','gocars'); ?></label>
                
                <a class="submit-button search-submit" id="search_button-<?php echo $shortcode_id; ?>" href="https://<?php echo $domain_slug; ?>.gocars.gr/select?pickup_id=<?php foreach ($locations_arr as $location) { echo ($default_location == $location->location_id) ? $location->location_id : "" ; } ?>&return_id=<?php foreach ($locations_arr as $location) { echo ($default_location == $location->location_id) ? $location->location_id : "" ; } ?>&date_from=<?php echo $data->date_from; ?>&time_from=<?php echo ($data->request_time_from) ? $data->request_time_from : $data->time_from; ?>&date_to=<?php echo $data->date_to; ?>&time_to=<?php echo ($data->request_time_to) ? $data->request_time_to : $data->time_to; ?>&age_group_id=<?php foreach ($age_group_arr as $age) { echo $option_arr->o_default_age_group == $age->id ? $age->id : "" ; } ?>">
                    <?php echo $search_text == '' ? __($label_arr->search_prices ?? 'Search Prices','gocars') : __($search_text,'gocars'); ?>
                </a>
            </div>

            <?php if ($show_footer == 'show'): ?>

                <span class="footer-form-wrap">
                    <span class="icon-award"></span>
                    <p><?php echo ($footer_text == '') ? __($label_arr->best_price ?? 'Best Price Guarantee','gocars') : esc_attr($footer_text) ; ?></p>
                </span>

            <?php endif; ?>

        </div>

    </div>

    <?php if ($last_search != null ) : ?>
        <a class="last_button-button primary-color primary-dark-hover-color" href="<?php echo $last_search_url; ?>"><?php _e($label_arr->last_search ?? 'Last Search','gocars'); ?></a>
    <?php endif; ?>
    
    <?php if ($vehicle_types_row): ?>
        <input type="hidden" name="vehicle_type" class="required" value="<?php echo $selected_vehicle_type != '' && $vehicle_type_selected_condition ?  $selected_vehicle_type : 'all' ; ?>"/>
    <?php endif; ?>

    <?php if ($option_arr->o_sort_type != 'vehicle_order'): ?>
        <input type="hidden" name="vehicles_sort_by" id="vehicles_sort_by-<?php echo $shortcode_id; ?>" value="<?php echo $option_arr->o_sort_type; ?>"/>
    <?php endif; ?>

    <?php if (isset($_REQUEST['agent_code']) && ($_REQUEST['agent_code'] != NULL || $_REQUEST['agent_code'] != '')): ?>
        <input type="hidden" name="agent_code" id="agent_code-<?php echo $shortcode_id; ?>" value="<?php echo $_REQUEST['agent_code']; ?>"/>
    <?php endif; ?>

    <?php if ($option_arr->o_allow_website == 1): ?>
        <input type="hidden" name="website" id="website-<?php echo $shortcode_id; ?>" value="<?php echo $subdomain; ?>"/>
    <?php endif; ?>

    <?php if ($option_arr->o_preselect_default_dates != 1): ?>
        <input type="hidden" name="preselect_default_dates" id="preselect_default_dates-<?php echo $shortcode_id; ?>" value="<?php echo $option_arr->o_preselect_default_dates; ?>"/>
    <?php endif; ?>

    <div class="gc-utm-inputs"></div>

    <?php 
    if (!empty($language_locale)): 
        
        foreach ($language_locale as $language => $language_data) {
            if ($language_data->id == $lang && $language_data->is_active_frontend == 1) {
                ?>
                <input type="hidden" name="language" id="language-<?php echo $shortcode_id; ?>" value="<?php echo $language; ?>"/>
                <?php 
                break;
            }
        }
    elseif (defined('ICL_LANGUAGE_CODE')) :
            ?>
            <input type="hidden" name="language" id="language-<?php echo $shortcode_id; ?>" value="<?php echo ICL_LANGUAGE_CODE; ?>"/>
            <?php 
    elseif (!defined('ICL_LANGUAGE_CODE') && $locale != '') :
        ?>
        <input type="hidden" name="language" id="language-<?php echo $shortcode_id; ?>" value="<?php echo substr($locale, 0, 2); ?>"/>
        <?php 
    endif; 
    ?>

    <?php 
    if ( $display_keypoints == 'yes' && !empty($keypoints_data_arr) ) : 
        ?>
        <ul class="keypoints-wrapper">
            <?php
            $i = 0.2;
            foreach ($keypoints_data_arr as $key => $point) {
                ?>
                <li class="single-keypoint show-on-scroll slide-up" style="transition-delay: <?php echo $i; ?>s;">
                    <i class="icon-check"></i>
                    <?php echo $point; ?>
                </li>
                <?php
                $i = $i + 0.2;
            } 
            ?>
        </ul>
        <?php
    endif; 
    ?>
    
</form>

<div class="datetime_options" data-domain="<?php echo esc_attr($domain_slug); ?>" data-shortcode="<?php echo $shortcode_id; ?>" style="display: none;">

    <?php 
    foreach ($data as $key => $value) {
        echo "<input type='hidden' name='$key' value='$value'>";
    }
    ?>
	
</div>
