<?php
/**
 * Team Section
 *
 * @package Excel_Business
 */

$ed_section = get_theme_mod( 'ed_team', true );
$title      = get_theme_mod( 'team_title', __( 'Meet The Team', 'excel-business' ) );
$sub_title  = get_theme_mod( 'team_subtitle', __( 'Show your team member from here. You can customize this section from Appearance > Customize > Home Page Settings > Team Section.', 'excel-business' ) );
$team_one   = get_theme_mod( 'team_one' );
$team_two   = get_theme_mod( 'team_two' );
$team_three = get_theme_mod( 'team_three' );
$team_four  = get_theme_mod( 'team_four' );

$team_posts = array( $team_one, $team_two, $team_three, $team_four );
$team_posts = array_diff( array_unique( $team_posts ), array('') );

$args = array(
    'post_type'      => 'ea_team',
    'post_status'    => 'publish',
    'post__in'       => $team_posts,
    'orderby'        => 'post__in',
    'posts_per_page' => -1
);

$qry = new WP_Query( $args );

if( $ed_section && ( $title || $sub_title || ( $qry->have_posts() && $team_posts ) ) ){ ?>
<section class="team">
	<div class="container">		
        <?php 
            excel_business_get_section_header( $title, $sub_title );
            
            if( excel_business_is_ea_active() && $qry->have_posts() && $team_posts ){
            ?>
            <div class="row">
    			<?php 
                while( $qry->have_posts() ){ 
                    $qry->the_post();
                    $designation = get_post_meta( get_the_ID(), '_ea_team_position', true );
                    $sociallinks = get_post_meta( get_the_ID(), '_ea_team_social', true );
                    ?>
                    <div class="col">
        				<div class="team-holder">
        					<div class="img-holder">
                                <?php 
                                    if( has_post_thumbnail() ){
                                        the_post_thumbnail( 'excel-business-team' );
                                    }else{
                                        echo '<img src="' . esc_url( get_template_directory_uri() . '/images/team-fall-back.jpg' ) .'" alt="' . esc_attr( get_the_title() ) . '">';    
                                    }
                                ?>                                
                            </div>        					
                            <h3 class="name-holder"><?php the_title(); ?></h3>
        					
                            <div class="text-holder">
        						<header class="heading">
        							<h3 class="name"><?php the_title(); ?></h3>
        							<?php if( $designation ) echo '<span class="designation">' . esc_html( $designation ) . '</span>'; ?>
        						</header>
        						<?php the_excerpt(); ?>
                                <?php if( $sociallinks ){ ?>
                    			<ul class="social-networks">
                    				<?php 
                                        foreach( $sociallinks as $key => $link ){
                                            $add = ( $key == 'youtube' ) ? '-play' : '';
                                            if( $link ) echo '<li><a href="' . esc_url( $link ) . '" class="fa fa-' . esc_attr( $key.$add ) . '"></a></li>';               					   
                                        }
                                    ?>
                    			</ul>
                                <?php } ?>                                
        					</div>
        				</div>
        			</div>
        			<?php 
                }
                wp_reset_postdata();
                ?>    			
    		</div><!-- .row -->
    		<?php 
            }
        ?>
	</div>
</section>
<?php
}