<?php

namespace Elementor;


include get_template_directory() . '/elementor/' . 'contracts.php';


if (!defined('ABSPATH')) exit;


class PortfoliosList extends Widget_Base
{

    public function get_name()
    {
        return 'banta_portfolios_list';
    }

    public function get_title()
    {
        return __('Portfolios List', TEXT_DOMAIN);
    }

    public function get_icon()
    {
        return 'eicon-posts-grid';
    }

    public function get_categories()
    {
        return ['jiawaz_theme'];
    }

    public function get_keywords()
    {
        return ['card', 'box', 'list', 'portfolios','feed'];
    }


    protected function _register_controls()
    {
        // content tab
        $this->register_content_tab_products_controls();
        $this->register_content_tab_query();
        $this->register_content_tab_items();

        // style tab
        $this->register_style_tab_card_controls();
        $this->register_style_tab_title_controls();
        $this->register_style_tab_more_button_controls();
        $this->register_style_tab_category_badge_controls();
        $this->register_style_tab_pagination_controls();
    }


    // posts content
    protected function register_content_tab_products_controls(){
        $this->start_controls_section(
            'section_content',
            [
                'label' => esc_html__( 'Content', TEXT_DOMAIN ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'show_category',
            [
                'label' => esc_html__('Show category', TEXT_DOMAIN),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('show', TEXT_DOMAIN),
                'label_off' => esc_html__('hide', TEXT_DOMAIN),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->add_control(
            'show_more_btn',
            [
                'label' => esc_html__('Show Icon', TEXT_DOMAIN),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('show', TEXT_DOMAIN),
                'label_off' => esc_html__('hide', TEXT_DOMAIN),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->add_control(
            'image_size',
            [
                'type' => Controls_Manager::SELECT,
                'label' => esc_html__( 'image size', TEXT_DOMAIN ),
                'options' => THUMB_SIZES,
                'default' => 'medium',
            ]
        );

        $this->end_controls_section();
    }

    // query
    protected function register_content_tab_query(){
        $this->start_controls_section(
            'query_section',
            [
                'label' => esc_html__('Query', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'count',
            [
                'label' => esc_html__( 'number', TEXT_DOMAIN ),
                'type' => \Elementor\Controls_Manager::NUMBER,
                'default' =>12,
                'placeholder' => esc_html__( 'enter the number', TEXT_DOMAIN ),
            ]
        );

        $this->add_control(
            'orderby',
            [
                'type' => \Elementor\Controls_Manager::SELECT,
                'label' => esc_html__( 'order by', TEXT_DOMAIN ),
                'options' => [
                    'modified' => [
                        'title' => esc_html__( 'last update', TEXT_DOMAIN ),
                    ],
                    'newest' => [
                        'title' => esc_html__( 'newest', TEXT_DOMAIN ),
                    ],
                    'oldest' => [
                        'title' => esc_html__( 'oldest', TEXT_DOMAIN ),
                    ],
                    'rand' => [
                        'title' => esc_html__( 'random', TEXT_DOMAIN ),
                    ],
                ],
                'default' => 'newest',
            ]
        );

        $this->add_control(
            'paged',
            [
                'label' => esc_html__( 'show pagination', TEXT_DOMAIN ),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__( 'show', TEXT_DOMAIN ),
                'label_off' => esc_html__( 'hide', TEXT_DOMAIN ),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->add_control(
            'pagination_align',
            [
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label' => esc_html__('alignment', TEXT_DOMAIN),
                'options' => [
                    'justify-content-end' => [
                        'title' => esc_html__('left', TEXT_DOMAIN),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'justify-content-center' => [
                        'title' => esc_html__('center', TEXT_DOMAIN),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'justify-content-start' => [
                        'title' => esc_html__('right', TEXT_DOMAIN),
                        'icon' => 'eicon-text-align-right',
                    ],
                ],
                'default' => 'justify-content-center',
                'condition'   => [
                    'paged'    => 'yes',
                ],
            ]
        );

        $taxonomies = get_object_taxonomies('portfolios', 'objects');
        unset($taxonomies['post_translations'],$taxonomies['post_format'],$taxonomies['language']);
        foreach ( $taxonomies as $object ) {
            if ($object !== 'post_translations' && $object !== 'post_format' && $object !== 'language'){
                $taxonomy = is_string($object) ? $object : $object->name;
                $categories = get_terms( array(
                    'taxonomy'    => $taxonomy,
                    'hide_empty' => 0,
                ) );
                $cat_array  = array();
                foreach( $categories as $cat_id => $cat_name ) {
                    $cat_array[ $cat_name->term_id ] = $cat_name->name;
                }
                @$this->add_control(
                    $taxonomy,
                    [
                        'label' => $taxonomy,
                        'type' => Controls_Manager::SELECT2,
                        'label_block' => true,
                        'multiple' => true,
                        'options' => $cat_array,
                    ]
                );
            }
        }

        $this->end_controls_section();

    }

    // items
    protected function register_content_tab_items(){
        $this->start_controls_section(
            'items_section',
            [
                'label' => esc_html__('Items', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'col',
            [
                'type' => Controls_Manager::SELECT,
                'label' => esc_html__( 'desktop', TEXT_DOMAIN ),
                'options' => BS_ROWS,
                'default' => '4',
            ]
        );
        $this->add_control(
            'col_tablet',
            [
                'type' => Controls_Manager::SELECT,
                'label' => esc_html__( 'tablet', TEXT_DOMAIN ),
                'options' => BS_ROWS,
                'default' => '6',
            ]
        );
        $this->add_control(
            'col_mobile',
            [
                'type' => Controls_Manager::SELECT,
                'label' => esc_html__( 'mobile', TEXT_DOMAIN ),
                'options' => BS_ROWS,
                'default' => '12'
            ]
        );

        $this->end_controls_section();
    }


    // style box
    protected function register_style_tab_card_controls(){
        $this->start_controls_section(
            'section_box_style',
            [
                'label' => esc_html__( 'Box', TEXT_DOMAIN ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control(
            'box_margin',
            [
                'label'      => __( 'margin', TEXT_DOMAIN ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => [ 'px', 'em', 'rem' ],
                'range'      => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'default' => [
                    'size' => 25,
                    'unit' => 'px',
                ],
                'selectors'  => [
                    '{{WRAPPER}} .post-item' => 'margin-bottom: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_responsive_control(
            'box_height',
            [
                'label' => __('height', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 50,
                        'max' => 1000,
                    ],
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => '240',
                ],
                'selectors' => [
                    '{{WRAPPER}} .post-item' => 'height: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_responsive_control(
            'box_padding',
            [
                'label'      => esc_html__( 'padding', TEXT_DOMAIN ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors'  => [
                    '{{WRAPPER}} .post-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'box_radius',
            [
                'label'      => __( 'border radius', TEXT_DOMAIN ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', 'em', 'rem' ],
                'selectors'  => [
                    '{{WRAPPER}} .post-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'box_image_radius',
            [
                'label'      => __( 'image border radius', TEXT_DOMAIN ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', 'em', 'rem' ],
                'selectors'  => [
                    '{{WRAPPER}} .post-item-image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'box_color',
            [
                'label'     => esc_html__( 'background color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'box_title_bg_color',
            [
                'label'     => esc_html__( 'title background color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item-content' => 'background: linear-gradient(0, transparent, {{VALUE}}, transparent)',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name'     => 'box_border_type',
                'label'    => esc_html__( 'border', TEXT_DOMAIN ),
                'selector' => '{{WRAPPER}} .post-item',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name'    => 'box_shadow',
                'selector' => '{{WRAPPER}} .post-item',
            ]
        );

        $this->end_controls_section();
    }

    // style title
    protected function register_style_tab_title_controls(){
        $this->start_controls_section(
            'section_title_style',
            [
                'label' => esc_html__( 'Title', TEXT_DOMAIN ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'     => 'title_typography',
                'label'    => esc_html__( 'typography', TEXT_DOMAIN ),
                'selector' => '{{WRAPPER}} .post-item .title',
            ]
        );

        $this->start_controls_tabs(
            'title_style_tabs',[
                'separator' => 'before'
            ]
        );

        // normal tab
        $this->start_controls_tab(
            'title_style_normal_tab',
            [
                'label' => esc_html__( 'normal', TEXT_DOMAIN ),
            ]
        );
        $this->add_control(
            'title_color',
            [
                'label'     => esc_html__( 'color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item .title' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Text_Shadow::get_type(),
            [
                'name'     => 'title_text_shadow',
                'selector' => '{{WRAPPER}} .post-item .title',
            ]
        );
        $this->end_controls_tab();

        // hover tab
        $this->start_controls_tab(
            'category_style_hover_tab',
            [
                'label' => esc_html__( 'hover', TEXT_DOMAIN ),
            ]
        );
        $this->add_control(
            'title_color_hover',
            [
                'label'     => esc_html__( 'color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item:hover .title' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Text_Shadow::get_type(),
            [
                'name'     => 'title_text_shadow_hover',
                'selector' => '{{WRAPPER}} .post-item:hover .title',
            ]
        );
        $this->end_controls_tab();

        $this->end_controls_tabs();
        $this->end_controls_section();
    }

    // style more button
    protected function register_style_tab_more_button_controls(){
        $this->start_controls_section(
            'section_more_style',
            [
                'label' => esc_html__( 'Read More Icon', TEXT_DOMAIN ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control(
            'more_icon_size',
            [
                'label' => __('Icon size', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 1,
                        'max' => 200,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .post-overly-icon' => 'font-size: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_control(
            'more_color',
            [
                'label'     => esc_html__( 'color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-overly-icon' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->end_controls_section();
    }

    // style category badge
    protected function register_style_tab_category_badge_controls(){
        $this->start_controls_section(
            'section_category_badge_style',
            [
                'label' => esc_html__( 'Category Badge', TEXT_DOMAIN ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control(
            'category_border_radius',
            [
                'label' => esc_html__('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .post-item-cat' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_responsive_control(
            'category_offset',
            [
                'label' => __('margin', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .post-item-cat' => 'top: {{SIZE}}{{UNIT}}!important;right: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->start_controls_tabs(
            'category_style_tabs',[
                'separator' => 'before'
            ]
        );
        // normal tab
        $this->start_controls_tab(
            'category_style_normal_tab',
            [
                'label' => esc_html__( 'normal', TEXT_DOMAIN ),
            ]
        );
        $this->add_control(
            'category_bg_color',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item-cat' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'category_color',
            [
                'label' => esc_html__('color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item-cat' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->end_controls_tab();
        // hover tab
        $this->start_controls_tab(
            'title_style_hover_tab',
            [
                'label' => esc_html__( 'hover', TEXT_DOMAIN ),
            ]
        );
        $this->add_control(
            'category_bg_color_hover',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item-cat:hover' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'category_color_hover',
            [
                'label' => esc_html__('color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item-cat:hover' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();

        $this->end_controls_section();
    }

    // style pagination
    protected function register_style_tab_pagination_controls(){
        $this->start_controls_section(
            'section_pagination_style',
            [
                'label' => esc_html__( 'Pagination', TEXT_DOMAIN ),
                'tab' => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'paged' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'pagination_size',
            [
                'label'      => __( 'items size', TEXT_DOMAIN ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range'      => [
                    'px' => [
                        'min' => 1,
                        'max' => 1000,
                    ],
                ],
                'default' =>[
                    'unit' => 'px',
                    'size' => 40
                ],
                'selectors'  => [
                    '{{WRAPPER}} .page-numbers' => 'width: {{SIZE}}{{UNIT}}!important;height: {{SIZE}}{{UNIT}}!important;line-height: {{SIZE}}{{UNIT}}',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'     => 'pagination_typography',
                'label'    => esc_html__( 'typography', TEXT_DOMAIN ),
                'selector' => '{{WRAPPER}} .page-numbers',
            ]
        );
        $this->add_responsive_control(
            'pagination_border_radius',
            [
                'label'      => esc_html__( 'border radius', TEXT_DOMAIN ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors'  => [
                    '{{WRAPPER}} .page-numbers' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_responsive_control(
            'pagination_padding',
            [
                'label'      => esc_html__( 'padding', TEXT_DOMAIN ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors'  => [
                    '{{WRAPPER}} .bcp-pagination' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'pagination_margin',
            [
                'label'      => esc_html__( 'items margin', TEXT_DOMAIN ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors'  => [
                    '{{WRAPPER}} .page-numbers' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'pagination_transition',
            [
                'label'      => __( 'transition', TEXT_DOMAIN ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => [ 's', 'ms'],
                'range'      => [
                    's' => [
                        'min' => 1,
                        'max' => 100,
                    ],
                    'ms' => [
                        'min' => 1,
                        'max' => 1000,
                    ],
                ],
                'default' =>[
                    'unit' => 'ms',
                    'size' => 200
                ],
                'selectors'  => [
                    '{{WRAPPER}} .page-numbers' => 'transition: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->start_controls_tabs(
            'pagination_style_tabs',[
                'separator' => 'before'
            ]
        );

        $this->start_controls_tab(
            'pagination_style_normal_tab',
            [
                'label' => esc_html__( 'normal', TEXT_DOMAIN ),
            ]
        );
        $this->add_control(
            'pagination_text_color',
            [
                'label'     => esc_html__( 'text color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .page-numbers' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'pagination_bg_color',
            [
                'label'     => esc_html__( 'background color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .page-numbers' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name'     => 'pagination_border_type',
                'label'    => esc_html__( 'border', TEXT_DOMAIN ),
                'selector' => '{{WRAPPER}} .page-numbers',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name'    => 'pagination_shadow',
                'selector' => '{{WRAPPER}} .page-numbers',
            ]
        );
        $this->end_controls_tab();

        $this->start_controls_tab(
            'pagination_style_hover_tab',
            [
                'label' => esc_html__( 'hover', TEXT_DOMAIN ),
            ]
        );
        $this->add_control(
            'pagination_text_color_hover',
            [
                'label'     => esc_html__( 'text color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .page-numbers:hover' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'pagination_bg_color_hover',
            [
                'label'     => esc_html__( 'background color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .page-numbers:hover' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name'     => 'pagination_border_type_hover',
                'label'    => esc_html__( 'border', TEXT_DOMAIN ),
                'selector' => '{{WRAPPER}} .page-numbers:hover',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name'    => 'pagination_shadow_hover',
                'selector' => '{{WRAPPER}} .page-numbers:hover',
            ]
        );
        $this->end_controls_tab();

        $this->start_controls_tab(
            'pagination_style_current_tab',
            [
                'label' => esc_html__( 'active', TEXT_DOMAIN ),
            ]
        );
        $this->add_control(
            'pagination_text_color_active',
            [
                'label'     => esc_html__( 'text color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .page-numbers.current' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'pagination_bg_color_current',
            [
                'label'     => esc_html__( 'background color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .page-numbers.current' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name'     => 'pagination_border_type_current',
                'label'    => esc_html__( 'border', TEXT_DOMAIN ),
                'selector' => '{{WRAPPER}} .page-numbers.current',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name'    => 'pagination_shadow_current',
                'selector' => '{{WRAPPER}} .page-numbers.current',
            ]
        );
        $this->end_controls_tab();

        $this->end_controls_tabs();

        $this->end_controls_section();
    }


    protected function renderQuery($settings):array{
        $order = "DESC";
        $orderBy = $settings['orderby'];
        if($orderBy == 'newest'){
            $orderBy = 'date';
        }
        if($orderBy == 'oldest'){
            $orderBy = 'date';
            $order = "ASC";
        }

        if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
        elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
        else { $paged = 1; }

        $args = array(
            'posts_per_page' => $settings['count'],
            'post_status' => 'publish',
            'post_type' => 'portfolios',
            'orderby' => $orderBy,
            'order' => $order,
            'paged' => $paged,

        );
        $taxonomies = get_object_taxonomies('portfolios', 'objects');
        foreach ( $taxonomies as $object ) {
            if (! empty($settings[$object->name])) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => $object->name,
                        'terms' => $settings[$object->name],
                    )
                );
            }
        }


        return $args;
    }

    protected function render()
    {

        $settings = $this->get_settings_for_display();
        $args = $this->renderQuery($settings);

        // content
        $showCategory = $settings['show_category'];
        $showPostMoreBtn = $settings['show_more_btn'];

        // grid
        $col = 'col-lg-' . $settings['col'] . ' col-md-' . $settings['col_tablet'] . ' col-' . $settings['col_mobile'];


        $query = new \WP_Query($args);
        echo "<div class='row'>";
        while ($query->have_posts()): $query->the_post();
            echo "<div class='$col'>";?>
            <div class="post-item portfolio-item elementor-portfolio">
                <div class="post-item-image">
                    <a href="<?php the_permalink() ?>">
                        <?php if (has_post_thumbnail()): the_post_thumbnail($settings['image_size']);
                        else:
                            echo "<img src='" . esc_url(get_template_directory_uri() . '/images/default.jpg') . "' alt='image'>";
                        endif; ?>
                    </a>
                    <?php if ($showCategory === 'yes') {
                        $category = get_the_terms( $post, 'portfolio_cat' );
                        if (is_array($category)){
                            $firstCategory = $category[0];
                        }
                        if(!empty($firstCategory)):?>
                            <a href="<?php echo get_term_link($firstCategory->term_id,'portfolio_cat');?>" class="post-item-cat"><?php echo $firstCategory->name;?></a>
                        <?php endif; } ?>

                </div>
                <div class="post-item-content">
                    <a href="<?php the_permalink() ?>" class="title"><div><?php the_title(); ?></div></a>
                </div>
                <?php if($showPostMoreBtn === 'yes'):?>
                    <a href="<?php the_permalink() ?>" class="post-overly-icon"><i class="icon-arrow-right"></i></a>
                <?php endif;?>
            </div>
            <?php echo "</div>";?>
        <?php endwhile;
        echo "</div>"; ?>
        <?php
        // pagination
        if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
        elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
        else { $paged = 1; }
        if($settings['paged'] == 'yes') {
            $paginationAlign = $settings['pagination_align'];
            echo "<div class='bcp-pagination $paginationAlign'>";
            echo paginate_links(array(
                'format' => '?paged=%#%',
                'current' => max(1, $paged),
                'total' => $query->max_num_pages,
                'prev_text' => ('<i class="iconly-Arrow-Right-3 icbo"></i>'),
                'next_text' => ('<i class="iconly-Arrow-Left-3 icbo"></i>'),
            ));
            echo "</div>";
        }
        ?>

        <?php wp_reset_postdata();

    }


}

Plugin::instance()->widgets_manager->register_widget_type(new PortfoliosList());