<?php defined('ABSPATH') or die('No Script Cuddies');
/*
Template Name: Habilidades
*/
get_header();
$img=(wp_get_attachment_image_src(get_post_thumbnail_id())!==false)?wp_get_attachment_image_src(get_post_thumbnail_id(),'full'):wp_get_attachment_image_src(get_post_thumbnail_id(get_bloginfo('page_on_front')),'full');
?>
<div class="coloured-madness-cast">
	<div class="container">
		<div class="spacer-85"></div>
		<div class="cast-container">
			<div class="cast-tabs row">
				<h3 align="center"><?=the_title();?></h3>
			</div>
		</div>
		<div class="cast-container">
			<?php 
				$terms = get_terms( array(
				    'taxonomy' => 'skill-g',
				) );
				$post_organize=array();
				if(!empty($terms)){
					foreach( $terms as $term){
						if(!is_user_logged_in()){
							$posts = get_posts(array(
							  'post_type' => 'skill',
							  'numberposts' => -1,
							  'order'=>'ASC',
							  'orderby'=>'date',
							  'tax_query' => array(
							    array(
							      'taxonomy' => 'skill-g',
							      'field' => 'id',
							      'terms' => $term->term_id, // Where term_id of Term 1 is "1".
							      'include_children' => false
							    )
							  ),
							'meta_query'=>array(
								array(
									'key'     => 'skill_level',
									'value'   => '70',
									'compare' => '>=',
									'type'    => 'NUMERIC',
								),
							),
							));
						}
						else{
							$posts = get_posts(array(
							  'post_type' => 'skill',
							  'numberposts' => -1,
							  'order'=>'ASC',
							  'orderby'=>'date',
							  'tax_query' => array(
							    array(
							      'taxonomy' => 'skill-g',
							      'field' => 'id',
							      'terms' => $term->term_id, // Where term_id of Term 1 is "1".
							      'include_children' => false
							    )
							  )
							));
						}
						
						$post_organize[$term->term_id]=array('term'=>(array)$term,'posts'=>(array) $posts);
					}
				}
			?>
			<ul class="cast-tabs row">
				<?php 
				$c=false;
				if(!empty($post_organize)){
					?><li data-cast-tab="_all" class="<?=($c==false)?'active':'';?>"><?=__('All Skills','portfolio_madness');?></li><?php
					if($c==false){
						$c=true;
					} 
					foreach($post_organize as $i=>$t){
						?>
					<li data-cast-tab="<?=$t['term']['slug'];?>" class="<?=($c==false)?'active':'';?>"><?=$t['term']['name'];?></li><?php
					
					}
				}
				?>
			</ul>
		</div>
		<div class="cast-container row row-siblings-container">
			<div class="cast-tabs-container col-xs-12">
				<?php 
				if(!empty($post_organize)){
					foreach($post_organize as $i=>$t){
						if(!empty($t['posts'])){
							?>
				<div class="cast-tab row active" data-cast-tab="<?=$t['term']['slug']?>" id="<?=$t['term']['slug']?>_cast" class="row"><?php
							foreach($t['posts'] as $post){
								$style=get_field('cor_icone_css',$post->ID)?'color:'.get_field('cor_icone_css',$post->ID).';':'';
								$title=(get_field('nome_icone_css',$post->ID)!='')?'<i class="'.get_field('nome_icone_css',$post->ID).'"></i> - '.get_the_title($post->ID):get_the_title($post->ID);
								$skill_level=intval(get_field('skill_level',$post->ID));
								if(($skill_level>0) && ($skill_level<=20)){
									$skill_name=__('Very Poor','portfolio_madness');
								}
								elseif(($skill_level>20) && ($skill_level<50)){
									$skill_name=__('Poor','portfolio_madness');
								}
								elseif(($skill_level>=50) && ($skill_level<70)){
									$skill_name=__('OK','portfolio_madness');
								}
								elseif(($skill_level>=70) && ($skill_level<90)){
									$skill_name=__('Good','portfolio_madness');
								}
								elseif(($skill_level>=90) && ($skill_level<100)){
									$skill_name=__('Very Good','portfolio_madness');
								}
								elseif(($skill_level=100)){
									$skill_name=__('Excelent','portfolio_madness');
								}
								?>
					<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
						<div class="fac3-title-container" style="<?=$style;?>"><?=$title;?></div>
						<div class="fac3-slider-container">
							<div class="slide_value" style="width:<?=$skill_level;?>%;<?=($style!='')?'background-'.$style:'background-color:#353c48;';?>"></div>
							<div class="slide_upper_text">
								<?=$skill_name;?>
							</div>
						</div>
					</div><?php	}
						?>
				</div><?php
						} 
					}
					?>
					<script>
						jQuery('ul.cast-tabs li').on('click',function(){
							var t=$(this);
							if(t.attr('data-cast-tab')!='_all'){
								if(!t.hasClass('active') || !$('#'+t.attr('data-cast-tab')+'_cast').is(':visible')){
									t.parent().children().each(function(){
										var temp=$(this);
										if(temp.hasClass('active')){
											temp.removeClass('active');
										}
										if(t.attr('data-cast-tab') != temp.attr('data-cast-tab')){
											$('#'+temp.attr('data-cast-tab')+'_cast').slideUp();
										}
									});
									t.addClass('active');
									$('#'+t.attr('data-cast-tab')+'_cast').slideDown();
								}
							}else{
								t.parent().children().each(function(){
									var temp=$(this);
									if(temp.hasClass('active')){
										temp.removeClass('active');
									}
									$('#'+temp.attr('data-cast-tab')+'_cast').slideDown();
								});
								t.addClass('active');
							}
						});
					</script>
					<?php
				}
				?>
			</div>
		</div>
	</div>
</div>
<?php
get_footer();

