<?php if (!defined('ABSPATH')) {
    return;
}
/*
 Name: Portfolio Archive
 Description: Create and display a Portfolio archive element
 Class: TH_PortfolioArchive
 Category: content
 Level: 3
*/
/**
 * Class TH_PortfolioArchive
 *
 * Create and display a Portfolio Category element
 *
 * @package  Kallyas
 * @category Page Builder
 * @author   Team Hogash
 * @since    4.0.0
 */
class TH_PortfolioArchive extends ZnElements
{
    public static function getName(){
        return __( "Portfolio Category", 'zn_framework' );
    }

    /**
     * This method is used to display the output of the element.
     * @return void
     */
    function element()
    {
        global $paged, $zn_config;


        $portfolio_style = $this->opt( 'portfolio_style', 'portfolio_sortable' );
        // Forwared element set-up to templates
        $zn_config['port_columns'] = $this->opt( 'ports_num_columns', '4' );
        $zn_config['frame_style'] = $this->opt( 'frame_style', 'classic' );
        $zn_config['portfolio_categories'] = $this->opt( 'portfolio_categories' );
        $zn_config['posts_per_page'] = $this->opt( 'ports_per_page_visible', 4 );

        // Build query
        $queryArgs = array(
            'post_type' => 'portfolio',
            'paged' => $paged,
            'posts_per_page' => $zn_config['posts_per_page'],
        );

        if( !empty( $portfolio_categories ) ){
            $queryArgs['tax_query'] = array(
                array(
                    'taxonomy' => 'project_category',
                    'field' => 'id',
                    'terms' => $zn_config['portfolio_categories']
                ),
            );
        }

        query_posts($queryArgs);
        get_template_part( 'inc/loop', $portfolio_style );
        wp_reset_query();
    }

    function scripts() {
        $portfolio_style = $this->opt( 'portfolio_style', 'portfolio_sortable' );

        if( $portfolio_style == 'portfolio_sortable' || $portfolio_style == 'portfolio_carousel' ){
            wp_enqueue_script( 'isotope');
        }
        elseif( $portfolio_style == 'portfolio_carousel' ){
            wp_enqueue_script( 'caroufredsel');
        }
    }

    /**
     * This method is used to retrieve the configurable options of the element.
     * @return array The list of options that compose the element and then passed as the argument for the render() function
     */
    function options()
    {
        return array(
                array(
                    "name" => __("Archive style", 'zn_framework'),
                    "description" => __("Please choose the desired archive style to display.", 'zn_framework'),
                    "id" => "portfolio_style",
                    "std" => 'portfolio_sortable',
                    "type" => "select",
                    "options" => array(
                        'portfolio_category' => __( 'Portfolio Category', 'zn_framework' ),
                        'portfolio_sortable' => __( 'Portfolio Sortable', 'zn_framework' ),
                        'portfolio_carousel' => __( 'Portfolio Carousel Layout', 'zn_framework' ),
                    ),
                ),
                array(
                    "name" => __("Frame Style", 'zn_framework'),
                    "description" => __("Please choose which frame style to apply.", 'zn_framework'),
                    "id" => "frame_style",
                    "std" => 'classic',
                    "type" => "select",
                    "options" => array(
                        "classic" => 'Classic',
                        "modern" => 'Modern',
                        "minimal" => 'Minimal',
                    ),
                    'dependency'  => array( 'element' => 'portfolio_style' , 'value'=> array('portfolio_carousel') ),
                ),
                array(
                    "name" => __("Portfolio Category", 'zn_framework'),
                    "description" => __("Select the portfolio category to show items", 'zn_framework'),
                    "id" => "portfolio_categories",
                    "multiple"    => true,
                    "std" => "0",
                    "type" => "select",
                    "options" => WpkZn::getPortfolioCategories(),
                ),
                array(
                    "name" => __("Number of portfolio Items Per Page", 'zn_framework'),
                    "description" => __("Please enter how many portfolio items you want to load on a page.", 'zn_framework'),
                    "id" => "ports_per_page_visible",
                    "std" => "4",
                    "type" => "text"
                ),
                array(
                    "name" => __("Number of columns", 'zn_framework'),
                    "description" => __("Please enter how many portfolio items you want to load on a page.", 'zn_framework'),
                    "id" => "ports_num_columns",
                    "std" => "4",
                    "options" => array(
                        '1' => __('1', 'zn_framework'),
                        '2' => __('2', 'zn_framework'),
                        '3' => __('3', 'zn_framework'),
                        '4' => __('4', 'zn_framework'),
                    ),
                    "type" => "select",
                    'dependency'  => array( 'element' => 'portfolio_style' , 'value'=> array( 'portfolio_sortable', 'portfolio_category' ) ),
                )
        );
    }
}
