<?php
/**
 * @copyright Copyright (c) 2016 AmyTheme (http://www.amytheme.com). All rights reserved.
 * @license  http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

get_header();

$queried_object = get_queried_object();
$term_id 		= $queried_object->term_id;
$term 			= get_term( $term_id, 'amy_director' );
$term_data 		= get_term_meta( $term_id, '_custom_amy_director', true );

$class = (isset( $term_data['banner'] ) && $term_data['banner'] != null) ? 'has-banner' : '';
?>

<section class="main-content amy-actor single-actor <?php echo esc_attr( $class ); ?>">
	<?php if ( isset( $term_data['banner'] ) ) : ?>
		<div class="actor-banner">
			<?php echo wp_get_attachment_image( $term_data['banner'], 'full' ); ?>
		</div>
	<?php endif; ?>
	<div class="container">
		<div class="row">
			<div class="actor-left col-md-3 col-sm-3">
				<?php if ( isset( $term_data['avatar'] ) ) : ?>
					<div class="actor-avatar">
						<?php echo wp_get_attachment_image( $term_data['avatar'], 'full' ); ?>
					</div>
				<?php endif; ?>
				<div class="actor-info">
					<ul>
						<?php if ( isset( $term_data['birth_date'] ) ) : ?>
							<li>
								<label><?php echo esc_html__( 'Birth Day:', 'amy-movie' ); ?></label>
								<span><?php echo esc_attr( $term_data['birth_date'] ); ?></span>
							</li>
						<?php endif; ?>
						<?php if ( isset( $term_data['birth_place'] ) ) : ?>
							<li>
								<label><?php echo esc_html__( 'Birth Place:', 'amy-movie' ); ?></label>
								<span><?php echo esc_attr( $term_data['birth_place'] ); ?></span>
							</li>
						<?php endif; ?>
						<?php if ( isset( $term_data['gender'] ) ) : ?>
							<li>
								<label><?php echo esc_html__( 'Gender:', 'amy-movie' ); ?></label>
								<span><?php echo esc_attr( $term_data['gender'] ); ?></span>
							</li>
						<?php endif; ?>
						<?php if ( isset( $term_data['national'] ) ) : ?>
							<li>
								<label><?php echo esc_html__( 'National:', 'amy-movie' ); ?></label>
								<span><?php echo esc_attr( $term_data['national'] ); ?></span>
							</li>
						<?php endif; ?>
					</ul>
				</div>
			</div>
			<div class="actor-right col-md-9 col-sm-9">
				<h1 class="actor-name"><?php echo esc_attr( $term->name ); ?></h1>
				<div class="actor-summary">
					<?php if ( isset( $term_data['summary'] ) && ! empty( $term_data['summary'] ) ) : ?>
						<ul>
							<?php foreach ( $term_data['summary'] as $i => $summary ) : ?>
								<li><?php echo esc_attr( $summary['content'] ); ?></li>
							<?php endforeach; ?>
						</ul>
					<?php endif; ?>
				</div>
				<div class="actor-biography">
					<h3 class="amy-title"><?php echo esc_html__( 'Biography', 'amy-movie' ); ?></h3>
					<p><?php echo $term->description; ?></p>
				</div>
				<div class="actor-movie">
					<h3 class="amy-title"><?php echo esc_html__( 'Filmography', 'amy-movie' ); ?></h3>
					<table>
						<thead>
							<tr>
								<th><?php echo esc_html__( 'Movie Name', 'amy-movie' ); ?></th>
								<th><?php echo esc_html__( 'Release Date', 'amy-movie' ); ?></th>
							</tr>
						</thead>
						<tbody>
							<?php
							$args = array(
								'post_type' => 'amy_movie',
								'tax_query' => array(
									array(
										'taxonomy' 	=> 'amy_director',
										'field' 	=> 'term_id',
										'terms' 	=> $term_id,
									),
								),
								'posts_per_page'	=> '10',
							);

							query_posts( $args );

							if ( have_posts() ) :
								while ( have_posts() ) :
									the_post();

									$mdetails 	= amy_movie_get_details( $post->ID );
									?>
									<tr>
										<td>
											<?php echo amy_movie_get_poster( $post->ID, array( '115', '85' ) ); ?>
											<?php echo get_the_title(); ?>
										</td>
										<td>
											<?php echo esc_attr( $mdetails['movie_release'] ); ?>
										</td>
									</tr>
								<?php
								endwhile;
							endif;

							wp_reset_query();
							?>
						</tbody>
					</table>
				</div>
			</div>
			<div class="clearfix"></div>
		</div>
	</div>
</section>


<?php

get_footer();
