<?php
/**
 * The template for displaying portfolio items
 *
 * @package Signify
 */
?>

<?php
$enable = get_theme_mod( 'signify_portfolio_option', 'disabled' );

if ( ! signify_check_section( $enable ) ) {
	// Bail if portfolio section is disabled.
	return;
}

$signify_type        = get_theme_mod( 'signify_portfolio_type', 'category' );

$signify_sub_title   = get_theme_mod( 'signify_portfolio_sub_title' );
$signify_title       = get_theme_mod( 'signify_portfolio_title' );
$signify_description = get_theme_mod( 'signify_portfolio_description' );

if ( 'jetpack-portfolio' === $signify_type ) {
	$signify_title       = get_option( 'jetpack_portfolio_title', esc_html__( 'Projects', 'signify-pro' ) );
	$signify_description = get_option( 'jetpack_portfolio_content' );
}

if ( ! $signify_sub_title && ! $signify_title && ! $signify_description ) {
	$classes[] = 'no-section-heading';
}

$layout 	  	   = get_theme_mod( 'signify_portfolio_layout', 'layout-three' );
$fluid_layout 	   = get_theme_mod( 'signify_portfolio_fluid_layout', 0 );
$cat_nav_alignment = get_theme_mod( 'signify_portfolio_category_nav_alignment', 'nav-left' );

$classes[] = 'section portfolio-section';
$classes[] = $signify_type;
$classes[] = $layout;


if ( 'category' === $signify_type && ! empty( $cats = get_theme_mod( 'signify_portfolio_select_category' ) ) ) {
	$classes[] = $cat_nav_alignment;
}

if( $fluid_layout ) {
	$classes[] = 'section-fluid';
} else {
	$classes[] = 'section-boxed';
}
?>

<div id="portfolio-content-section" class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
	<div class="wrapper">
		<?php signify_section_header( $signify_sub_title, $signify_title, $signify_description ); ?>

		<div class="section-content-wrapper <?php echo esc_attr( $layout ); ?>">

			<?php if ( 'category' === $signify_type && ! empty( $cats = get_theme_mod( 'signify_portfolio_select_category' ) ) ) : ?>
			<div class="filter-button-group button-group">
				<button class="button is-checked" data-filter="*"><?php esc_html_e( 'Show All', 'signify-pro' ) ?></button>
				<?php
				foreach ( $cats as $signify_cat ) {
					$catinfo = get_category( $signify_cat );
					?>
					<button class="button" data-filter=".<?php if (isset($catinfo->slug)) : echo esc_attr( $catinfo->slug ); endif; ?>"><?php if (isset($catinfo->name)) : echo esc_html( $catinfo->name ); endif; ?></button>
					<?php
				}
			    ?>
			</div>
			<?php endif;?>

			<div class="grid">
				<?php
				if ( 'post' === $signify_type || 'jetpack-portfolio' === $signify_type || 'page' === $signify_type || 'category' === $signify_type  ) {
					get_template_part( 'template-parts/portfolio/post-types', 'portfolio' );
				} elseif ( 'custom' === $signify_type ) {
					get_template_part( 'template-parts/portfolio/image', 'portfolio' );
				}
				?>
			</div>
		</div><!-- .section-content-wrap -->

		<?php
			$target       = get_theme_mod( 'signify_portfolio_target' ) ? '_blank': '_self';
			$signify_link = get_theme_mod( 'signify_portfolio_link', '#' );
			$text         = get_theme_mod( 'signify_portfolio_text' );

			if ( $text ) :
		?>

		<p class="view-more">
			<a class="button" target="<?php echo $target; ?>" href="<?php echo esc_url( $signify_link ); ?>"><?php echo esc_html( $text ); ?></a>
		</p>
		<?php endif; ?>
	</div><!-- .wrapper -->
</div><!-- #portfolio-section -->
