<?php

  #
  # This template is used to show "All portfolio" page
  #

  # Retrieve data
  $portfolio = get_kob_object('portfolio_settings');

  # One column, Two columns, Three columns, Four columns
  $grid    = $portfolio->many->portfolio_grid;
  $masonry = $portfolio->many->portfolio_masonry;

  # Row class TODO 2 columns
  $masonry_classes = array(
    'One column'    => 'card-columns-1',
    'Two columns'   => 'card-columns-2',
    'Three columns' => 'card-columns',
    'Four columns'  => 'card-columns-4',
  );
  $row_class = $masonry ? $masonry_classes[$grid] : 'row';

  # Article clas
  $article_classes = array(
    'One column'    => 'col-lg-8 col-md-10 col-xs-6',
    'Two columns'   => 'col-md-6 col-xs-6',
    'Three columns' => 'col-md-4 col-sm-6 col-xs-6',
    'Four columns'  => 'col-lg-3 col-md-4 col-sm-6 col-xs-6'
  );
  $article_class = $masonry ? '' : $article_classes[$grid];

  # Item style
  $item = $portfolio->many->portfolio_item;
  if($item == 'Text on image') {
    $show_text = true;
    $on_image = true;
    $text_class = 'text-white';
  }
  if($item == 'Text above an image') {
    $show_text = true;
    $on_image = false;
    $text_class = '';
  }
  if($item == 'Image without text') {
    $show_text = false;
    $on_image = false;
    $text_class = '';
  }

  # Some settings
  $show_title   = $portfolio->many->portfolio_text->portfolio_item_title;
  $show_content = $portfolio->many->portfolio_text->portfolio_item_description;
  $show_cat     = $portfolio->many->portfolio_text->portfolio_item_category;

  # Text settings
  $text_direction = $portfolio->many->portfolio_text->portfolio_text_direction;

  if($text_direction == "Center")
    $article_class .= " text-xs-center";

  # Form slugs
  $count = wp_count_posts('portfolio');
  $terms = get_terms( array(
    'taxonomy' => 'portfolio_type',
    'hide_empty' => true,
  ));
  $slugs = array(
    array(
      'url'    => get_post_type_archive_link('portfolio'),
      'count'  => $count->publish,
      'name'   => __('All works', 'reddy'),
      'active' => is_post_type_archive( 'portfolio' )
    )
  );
  foreach($terms as $term) {
    $slugs[] = array(
      'url'    => get_term_link($term),
      'count'  => $term->count,
      'name'   => $term->name,
      'active' => is_tax( 'portfolio_type', $term->name )
    );
  }

  # Get all portfolio posts
  $posts = get_posts_from_loop();

  # Page
  get_header();

    view( 'partials/new/menu-classic', 'main' );
    wrap( 'start', 'container m-b-md' );
      view('partials/headings', 'simple', array('heading' => 'Portfolio'));
      wrap( 'start', 'page' );
        view('partials/taxonomies', 'categories', array('slugs' => $slugs));
        wrap( 'start', $row_class );

          view( 'partials/archives', 'portfolio', array(
            'on_image'      => $on_image,
            'article_class' => $article_class,
            'show_text'     => $show_text,
            'show_title'    => $show_title,
            'text_class'    => $text_class,
            'show_content'  => $show_content,
            'show_cat'      => $show_cat,
            'posts'         => $posts,
            'h_class'       => 'text-overflow-ellipsis'
          ) );

        wrap( 'end' );
        view('partials/navigation', 'pg-simple');
      wrap( 'end' );
    wrap( 'end' );
    view('partials/common', 'footer');
  get_footer();
