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


function elicotteri_trasfer_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' => 'trasferimento',
        'posts_per_page' => 999,
    );
    $the_query = new WP_Query($subs_args);

// The Loop
    if ($the_query->have_posts()) :
        $sub_posts .= '<div class ="row">';


        while ($the_query->have_posts()) : $the_query->the_post();



            $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);
            $destinazioni_field = get_field('destinazioni', $this_sub_id);
            $post_thumbnail_url = get_the_post_thumbnail_url($this_sub_id, o66_image_sizes::nocrop_container);
            $wp_text = get_the_content($this_sub_id);
            $wp_cont_heli = '';
            if (!empty($wp_text)) {$wp_cont_heli = '<div class="blok transfer_text">'.get_the_content($this_sub_id).'</div>';}
            $img = '';
            if (!empty($post_thumbnail_url)){
                $img = '<div class="blok item_post_thumbnail"><img src="'.$post_thumbnail_url.'" class="img-responsive"></div>';
            }
//            $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($destinazioni_field)){
                $list .= '<ul>';
                foreach ($destinazioni_field as $destinazione_row)
                {

                    $list .= '<li><div class="list-left">'.$destinazione_row['destinazione'].'</div><div class="list-right"><i class="fa fa-clock-o" aria-hidden="true"></i> '.$destinazione_row['durata'].'</div></li>';
                }
//                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 ="elicotteri_transfer_sub_post_item">';
            $sub_posts .= '<div class="item_element item_attributes"><h2>' . get_the_title($this_sub_id) . '</h2>'.$img.$list.$wp_cont_heli;
            $sub_posts .= '</div>';
            $sub_posts .= '</div>';
            $sub_posts .= '</div>';



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

    endif;
    wp_reset_query();
    wp_reset_postdata();
    $prenota_transfer_link = get_field( 'prenota_transfer_link' );
    $prenota_link = $prenota_transfer_link;
    $prenota_label = get_field( 'prenota_transfer_label' );
    $prenota_content = '<div class="transfer_index button_container prenota"><a href="' . $prenota_link['url'] . '"><i class="fa fa-calendar"></i> ' . $prenota_label . '</a></div>';

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

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

    return $section;
}
//get_footer();