<?php
/**
 * Created by PhpStorm.
 * User: marco
 * Date: 16/07/18
 * Time: 18.44
 */


function jet_flotta_index()
{

    $content = get_component('simple_content');
    $sidebar = get_component('sidebar');
    $col_main = html5_div($content, null, 'col-md-12');
    $col_side = html5_div($sidebar, null, 'col-md-4 col-index-side col-index-side-flotta');
    $row = html5_div($col_main, null, 'row');

    //$title_sub = '<h2>' . get_label('Alcuni dei tour') . '</h2>';
    
    $title_sub = '';
    $sub_posts = '';
    $subs_args = array(
        'post_type' => 'jet',
        'posts_per_page' => 999,
    );
    $the_query = new WP_Query($subs_args);

// The Loop
    if ($the_query->have_posts()) :


        while ($the_query->have_posts()) : $the_query->the_post();
            $sub_posts .= '<div class ="elicotteri_flotta_sub_post_item">';
            $sub_posts .= '<div class ="row">';

            $this_sub_id = get_the_ID();
            $image_size = o66_image_sizes::rect43;
            $primary_image_field = get_field('primary_image', $this_sub_id);
            $secondary_image_field = get_field('secondary_image', $this_sub_id);
            $primary_image = $primary_image_field['sizes'][$image_size];
            $primary_image_full = $primary_image_field['url'];
            $secondary_image = $secondary_image_field['sizes'][$image_size];
            $secondary_image_full = $secondary_image_field['url'];
            $list = '';
            $passengers = get_field('passengers', $title_sub);
            $max_range = get_field('max_range', $this_sub_id);
            $cruise_speed = get_field('cruise_speed', $this_sub_id);

            if (!empty($passengers) or !empty($max_range) or !empty($cruise_speed)){
                $list .= '<ul>';
                if (!empty($passengers)){
                    $list .= '<li><div class="list-left"><i class="fa fa-users" aria-hidden="true"></i> '.get_label('Passengers').'</div><div class="list-right">'.$passengers.'</div></li>';
                }
                if (!empty($max_range)){
                    $list .= '<li><div class="list-left"><i class="fa fa-map-o" aria-hidden="true"></i> '.get_label('Max range').'</div><div class="list-right">'.$max_range.'</div></li>';
                }
                if (!empty($cruise_speed)){
                    $list .= '<li><div class="list-left"><i class="fa fa-tachometer" aria-hidden="true"></i> '.get_label('Cruise speed').'</div><div class="list-right">'.$cruise_speed.'</div></li>';
                }
                $list .= '</ul>';

            }



            $sub_posts .= '<div class="col-md-6">';
            $sub_posts .= '<div class="item_element item_figure"><figure class="entry-content__gallery__image gal_js"><a href="'.$primary_image_full.'"><img src="' . $primary_image . '" class="img-responsive"></a>
                            <div class="secondary_over"><a href="'.$secondary_image_full.'"><img src="' . $secondary_image . '" class="img-responsive"></a></div></figure>';
            $sub_posts .= '</div>';
            $sub_posts .= '</div>';

            $sub_posts .= '<div class="col-md-6">';
            $sub_posts .= '<div class="item_element item_attributes"><h2>' . get_the_title($this_sub_id) . '</h2>'.$list;
            $sub_posts .= '</div>';
            $sub_posts .= '</div>';


            $sub_posts .= '</div></div>';
        endwhile;

    endif;
    wp_reset_query();
    wp_reset_postdata();

    $content_sub = '<div class="sub_post_index">' . $title_sub . $sub_posts . '</div>';

    $col_sub_main = html5_div($content_sub, null, 'col-md-8');
    $row_2 = html5_div($col_sub_main . $col_side, null, 'row');
    $container = html5_div($row . $row_2, null, 'container');
    $section = html5_div($container, null, 'blok');

    return $section;
}
//get_footer();