<?php
/**
 * Created by PhpStorm.
 * User: marco
 * Date: 15/08/17
 * Time: 17.02
 */
?>
<section id="menu-mobile" class="blok section-menu-mobile hidden-lg hidden-md">
	<div class="container-fluid container-menu-mobile-header">
		<div class="div-logo-mobile" style="">
			<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
				<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/scLogoVectMobile.svg" class="img-responsive">
			</a>
		</div>
		<div class="div-hamburger-mobile" id="hmbTrigger">
			<div class="div-hamburger-mobile-bar" id="hmb1"></div>
			<div class="div-hamburger-mobile-bar" id="hmb2"></div>
			<div class="div-hamburger-mobile-bar" id="hmb3"></div>
		</div>
	</div>
	<div class="blok" id="back-menu-mob-abs">


					<?php //wp_nav_menu( array( 'theme_location' => 'main-menu', 'menu_class' => 'ul-blok-menu-mobile' ) );
                //    include ('menu-mobile-v2.php');
					wp_nav_menu( array(

						'theme_location' => 'primary',
						'menu_class'     => 'ul-blok-menu-mobile',
						//'walker'         => new O66_Wp_Clean_Walker(),
						'container'      => false,
						'items_wrap'     => '<ul class="ul-blok-menu-mobile">%3$s</ul>'
					) );
//
//				//	o66s::enqueueCoreJs( 'blok-menu-mobile' );
					$allLangs  = icl_get_languages( 'skip_missing=0' );
					$contaLang = 0;
					?>
					<div class="blok" style="display: none" id="menuMobLang">
						<?php foreach ( $allLangs

						as $lang ) :
						$langClass = '';
						$contaLang ++;

						if ( $lang['code'] == ICL_LANGUAGE_CODE ) {
							$langClass = 'currentLang';
						}
						$allLangs = icl_get_languages( 'skip_missing=0' );

						?>


								 <li><a href="<?php echo get_site_url(); ?>/?lang=<?php echo $lang['code']; ?>"
								   class="<?php echo $langClass; ?>" style="width: auto; min-width: 25px!important"><i class="fa fa-globe"></i> <?php echo $lang['code']; ?></a>
                                 </li>
							<?php endforeach; ?>
					</div>

			</div>
</section>

<?php
function video_media_side_menu_mob() {
	global $post;
	global $scope_year;
	global $scope_media_type;
	global $global_post_id;

	$postIndex = get_field('pagina_indice_press_zone', 'option');
	$this_post_id = get_the_ID();
	//vars
	$label            =  get_field('label_video',$postIndex->ID );
	$first_query_var  = 'mediatype';
	$media_type_value = 'video';
	$year_query_var   = 'tyear';
	$fa_tag           = '<i class="fa fa-calendar-o"></i>';

	$label            =  get_field('label_video',$postIndex->ID );

	//get model from acf
	$year_array = []; ?>
	<?php if ( have_rows( $media_type_value . '_media', $postIndex->ID ) ) : ?>
		<?php while ( have_rows( $media_type_value . '_media', $postIndex->ID ) ) : the_row(); ?>
			<?php
			$date = get_sub_field( 'press_date' ); ?>
			<?php
			$year = substr( $date, 0, 4 );
			array_push( $year_array, $year );
		endwhile; ?>
	<?php else : ?>
		<?php // no rows found ?>
	<?php endif; ?>
	<?php
	$year_array_unique = array_unique( $year_array );
	rsort( $year_array_unique );
	//var_dump( $year_array_unique );
	//view
	if ( ! empty( $year_array_unique ) ) : ?>
        <ul id="video-mob-js" class="sub-menu">
            <li class="menu-item-has-children"><?php echo $label; ?>
                <ul class="sub-menu">
					<?php foreach ( $year_array_unique as $item ) :
						//submodel
						//submodel
						$li_class_attribute = '';
						if ( $item === $scope_year ) {

							if ( $scope_media_type === 'press' ) {
								//var_dump($scope_media_type);
								$li_class_attribute = ' class="current"';
							}
						}
						$media_query_url = get_the_permalink( $postIndex->ID ) . '?' . $first_query_var . '=' . $media_type_value . '&' . $year_query_var . '=' . $item;
						?>
                        <li<?php echo $li_class_attribute;?>><a href="<?php echo $media_query_url; ?>"><?php echo  $item; ?></a></li>
					<?php endforeach; ?>
                </ul>
            </li>
        </ul>
	<?php endif;
}

function press_media_side_menu_mob() {
	global $post;
	global $global_post_id;
	$postIndex = get_field('pagina_indice_press_zone', 'option');
	 $scope_year = 2018;
	$scope_media_type = 'press';
	$this_post_id = get_the_ID();
	//vars
	$label            =  get_field('label_stampa',$postIndex->ID );
	$first_query_var  = 'mediatype';
	$media_type_value = 'press';
	$year_query_var   = 'tyear';
	$fa_tag           = '<i class="fa fa-calendar-o"></i>';

	//get model from acf
	$year_array = []; ?>

	<?php
    //var_dump($postIndex);
    if ( have_rows( $media_type_value . '_media', $postIndex->ID ) ) : ?>

		<?php while ( have_rows( $media_type_value . '_media', $postIndex->ID ) ) : the_row(); ?>

			<?php
			$date = get_sub_field( 'press_date' ); ?>
			<?php
			$year = substr( $date, 0, 4 );
			array_push( $year_array, $year );
		endwhile; ?>
	<?php else : ?>
		<?php // no rows found ?>
	<?php endif; ?>
	<?php
  //  var_dump($year_array);
	$year_array_unique = array_unique( $year_array );
	rsort( $year_array_unique );
	//var_dump( $year_array_unique );
	//view
	if ( ! empty( $year_array_unique ) ) : ?>
    <ul id="press-mob-js" class="sub-menu">
                <li class="menu-item-has-children"><?php echo $label; ?>
                    <ul class="sub-menu">
		                <?php foreach ( $year_array_unique as $item ) :
			                //submodel
			                //submodel
			                $li_class_attribute = '';
			                if ( $item === $scope_year ) {

				                if ( $scope_media_type === 'press' ) {
					                //var_dump($scope_media_type);
					                $li_class_attribute = ' class="current"';
				                }
			                }
			                $media_query_url = get_the_permalink( $postIndex->ID ) . '?' . $first_query_var . '=' . $media_type_value . '&' . $year_query_var . '=' . $item;
			                ?>
                            <li<?php echo $li_class_attribute;?>><a href="<?php echo $media_query_url; ?>"><?php echo  $item; ?></a></li>
		                <?php endforeach; ?>
                    </ul>
                </li>
    </ul>
	<?php endif;
}
?>
<?php
function o66fswp_the_posts_acf_filtered_team_mob( $post_type, $meta_key_acf_field, $icon_tag = '<i class="fa fa-arrow-circle-o-down"></i>', $link = 'single' ) {

$args        = array(
'posts_per_page'   => 999,
'offset'           => 0,
//	'category'         => '',
//	'category_name'    => '',
'orderby'          => 'meta_value',
'order'            => 'ASC',
'include'          => '',
'exclude'          => '',
'meta_key'         => $meta_key_acf_field,
//'meta_value'       => 'gestionale',
'post_type'        => $post_type,
'post_mime_type'   => '',
'post_parent'      => '',
'author'           => '',
'author_name'      => '',
'post_status'      => 'publish',
'suppress_filters' => true,
'fields'           => '',
);
$posts_array = get_posts( $args );
$cat_array   = array();

foreach ( $posts_array as $item ) {
array_push( $cat_array, get_field( 'team_category', $item->ID ) );
}
$cat_array_unique = array_unique( $cat_array );
//var_dump($cat_array_unique);
if ( ! empty( $cat_array_unique ) ) : ?>

	<?php
	$globalCurrentPostId = get_the_ID();
	foreach ( $cat_array_unique as $cat_item ) :
	//echo $cat_item;
	//multi orderby
	$args = array(
		'meta_query' => array(
			'relation' => 'AND',
			'team_cat_mq' => array(
				'key' => 'team_category',
				'value' => $cat_item,
			),
			'cognome' => array(
				'key' => 'cognome',
				// 'value' => 'Mach'

			),
		),
		'orderby' => array(
			//	'city_clause' => 'ASC',
			'cognome' => 'ASC',
		),
		'posts_per_page'   => 999,
		'offset'           => 0,

		'post_type'        => $post_type





	);

	$this_cat_posts = get_posts( $args );
	$sorter = new o66_FieldSorter('cognome');
	//$query = new WP_Query( array( 'post_type' => 'page' ) );
	//usort($this_cat_posts, array($sorter, "cmp"));
	//$sorted_and_reversed = array_reverse($acf_reapeter);
	//var_dump($this_cat_posts[0]->post_title);
	//global $global_post_id;
	$postIndex = get_field('pagine_indice_team', 'option');

	//  <ul id="press-mob-js" class="sub-menu">
		//                <li class="menu-item-has-children">

	?>


        <ul class="sub-menu" id="team-mob-js-<?php echo $cat_item;?>">
            <li class="menu-item-has-children"><?php echo get_field('label_'.$cat_item, $postIndex);?>
                <ul class="sub-menu">
		            <?php foreach ( $this_cat_posts as $post_item ) :
			            $stringClassLi = '';
			            if ($globalCurrentPostId === $post_item->ID) {$stringClassLi = ' class="current"';}
			            if ( $link === 'single' ) {
				            $aTagStart = '<a href="' . get_the_permalink( $post_item->ID ) . '">';
				            $aTagEnd   = '</a>';
			            }
			            ?>
                        <li<?php echo $stringClassLi;?>><?php echo $aTagStart . $icon_tag; ?><?php echo $post_item->post_title . $aTagEnd; ?></li>
		            <?php endforeach; ?>
                </ul>
            </li>
        </ul>

		<?php endforeach; ?>

    <?php endif;
}
?>


<div class="menu-mobile-hidden" style="display: none" hidden>
<?php o66fswp_the_posts_acf_filtered_team_mob( 'membro_team', 'team_category', '<i class="fa fa-user-circle-o" style="display: none"></i>' );  ?>
    <?php press_media_side_menu_mob();?>
    <?php video_media_side_menu_mob();?>
</div>
