<?php

namespace Elementor;


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


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


class PostsSwiper1 extends Widget_Base
{

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

    public function get_title()
    {
        return __('Posts Carousel 1', TEXT_DOMAIN);
    }

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

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

    public function get_keywords()
    {
        return ['card', 'box', 'list', 'carousel', 'slider', 'post','swiper','feed'];
    }


    protected function _register_controls()
    {
        // content tab
        $this->register_content_tab_posts();
        $this->register_content_tab_query();
        $this->register_content_tab_carousel_controls();

        // style tab
        $this->register_style_tab_card_controls();
        $this->register_style_tab_image_controls();
        $this->register_style_tab_title_controls();
        $this->register_style_tab_date_controls();
        $this->register_style_tab_more_button_controls();
        $this->register_style_tab_category_badge_controls();
        $this->register_style_tab_carousel_controls();
    }


    // posts content
    protected function register_content_tab_posts()
    {
        $this->start_controls_section(
            'posts_section',
            [
                'label' => esc_html__('Posts', 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_date',
            [
                'label' => esc_html__('Show date', 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 more button', 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(
            'more_btn_text',
            [
                'label' => esc_html__('More button text', TEXT_DOMAIN),
                'default' => esc_html__('Read more', TEXT_DOMAIN),
                'type' => \Elementor\Controls_Manager::TEXT,
                'placeholder' => esc_html__('enter your text', TEXT_DOMAIN),
            ]
        );

        $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' => 9,
                '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',
            ]
        );
        $taxonomies = get_object_taxonomies('post', '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();

    }

    // carousel
    protected function register_content_tab_carousel_controls()
    {
        $this->start_controls_section(
            'section_swiper',
            [
                'label' => esc_html__('Carousel', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        // items
        $this->add_control(
            'carousel_items_heading',
            [
                'label' => esc_html__('Slides per view', TEXT_DOMAIN),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',

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

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

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

            ]
        );

        $this->add_control(
            'carousel_autoplay',
            [
                'label' => esc_html__('autoplay', TEXT_DOMAIN),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('active', TEXT_DOMAIN),
                'label_off' => esc_html__('off', TEXT_DOMAIN),
                'return_value' => 'yes',
                'default' => 'no',
                'separator' => 'before',

            ]
        );

        $this->add_control(
            'carousel_autoplay_delay',
            [
                'label' => __('animation delay', TEXT_DOMAIN),
                'type' => Controls_Manager::NUMBER,
                'default' => 4000,
                'condition' => [
                    'carousel_autoplay' => 'yes'
                ]

            ]
        );

        $this->add_control(
            'carousel_smart_speed',
            [
                'label' => __('animation speed', TEXT_DOMAIN),
                'type' => Controls_Manager::NUMBER,
                'default' => 400,

            ]
        );

        $this->add_control(
            'carousel_center',
            [
                'label' => esc_html__('center mode', TEXT_DOMAIN),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('active', TEXT_DOMAIN),
                'label_off' => esc_html__('off', TEXT_DOMAIN),
                'return_value' => 'yes',
                'default' => 'no',

            ]
        );

        $this->add_control(
            'carousel_loop',
            [
                'label' => esc_html__('infinite loop', TEXT_DOMAIN),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('active', TEXT_DOMAIN),
                'label_off' => esc_html__('off', TEXT_DOMAIN),
                'return_value' => 'yes',
                'default' => 'no',
            ]
        );

        $this->add_control(
            'carousel_margin',
            [
                'label' => esc_html__('items margin', TEXT_DOMAIN),
                'type' => Controls_Manager::NUMBER,
                'default' => 22,
                'placeholder' => esc_html__('enter the value', TEXT_DOMAIN),

            ]
        );

        $this->add_control(
            'carousel_items_per_group',
            [
                'label' => esc_html__('Item to change', TEXT_DOMAIN),
                'type' => \Elementor\Controls_Manager::NUMBER,
                'default' => 1,
                'placeholder' => esc_html__('enter the number', TEXT_DOMAIN),

            ]
        );

        $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_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->start_controls_tabs(
            'box_style_tabs',[
                'separator' => 'before'
            ]
        );

        // normal tab
        $this->start_controls_tab(
            'box_style_normal_tab',
            [
                'label' => esc_html__( 'normal', TEXT_DOMAIN ),
            ]
        );
        $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_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_badge_color',
            [
                'label'     => esc_html__( 'Badge color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item .post-item-content:before,{{WRAPPER}} .post-item:before' => 'background: {{VALUE}};',
                ],
            ]
        );
        $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_tab();

        // hover tab
        $this->start_controls_tab(
            'box_style_hover_tab',
            [
                'label' => esc_html__( 'hover', TEXT_DOMAIN ),
            ]
        );
        $this->add_responsive_control(
            'box_radius_hover',
            [
                'label'      => __( 'border radius', TEXT_DOMAIN ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', 'em', 'rem' ],
                'selectors'  => [
                    '{{WRAPPER}} .post-item:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'box_color_hover',
            [
                'label'     => esc_html__( 'background color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item:hover' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'box_badge_color_hover',
            [
                'label'     => esc_html__( 'Badge color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item:hover .post-item-content:before,{{WRAPPER}} .post-item:hover:before' => 'background: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name'     => 'box_border_type_hover',
                'label'    => esc_html__( 'border', TEXT_DOMAIN ),
                'selector' => '{{WRAPPER}} .post-item:hover',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name'    => 'box_shadow_hover',
                'selector' => '{{WRAPPER}} .post-item:hover',
            ]
        );
        $this->end_controls_tab();

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

    // style image
    protected function register_style_tab_image_controls(){
        $this->start_controls_section(
            'section_image_style',
            [
                'label' => esc_html__( 'Image', TEXT_DOMAIN ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

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

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

        $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->add_responsive_control(
            'title_margin',
            [
                'label'      => __( 'margin', TEXT_DOMAIN ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => [ 'px', 'em', 'rem' ],
                'range'      => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors'  => [
                    '{{WRAPPER}} .post-item .title' => 'margin-bottom: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $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(
            'title_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 date
    protected function register_style_tab_date_controls(){
        $this->start_controls_section(
            'section_date_style',
            [
                'label' => esc_html__( 'Date', TEXT_DOMAIN ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

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

        $this->add_responsive_control(
            'date_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-item-time .iconlyBulk-Time-Square' => 'font-size: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

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

        $this->add_control(
            'date_icon_color',
            [
                'label'     => esc_html__( 'Icon color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .post-item-time .iconlyBulk-Time-Square' => 'color: {{VALUE}};',
                ],
            ]
        );

        $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 Button', TEXT_DOMAIN ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

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

        $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}} .more i' => 'font-size: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

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

        $this->add_control(
            'more_icon_color',
            [
                'label'     => esc_html__( 'Icon color', TEXT_DOMAIN ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .more i' => '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(
            'category_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 carousel
    protected function register_style_tab_carousel_controls()
    {
        $this->start_controls_section(
            'section_carousel_style',
            [
                'label' => esc_html__('Carousel', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_STYLE,

            ]
        );

        // buttons backdrop
        $this->add_control(
            'carousel_arrows_backdrop_style_heading',
            [
                'label' => esc_html__('Arrows backdrop', TEXT_DOMAIN),
                'type' => Controls_Manager::HEADING,
            ]
        );

        $this->add_control(
            'carousel_arrows_backdrop_color',
            [
                'label' => esc_html__('color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .swiper-backdrop-button.prev' => 'background: linear-gradient(to left, transparent,{{VALUE}});',
                    '{{WRAPPER}} .swiper-backdrop-button.next' => 'background: linear-gradient(to right, transparent,{{VALUE}});',
                ],
            ]
        );




        // nav
        $this->add_control(
            'carousel_nav_style_heading',
            [
                'label' => esc_html__('arrows', TEXT_DOMAIN),
                'type' => Controls_Manager::HEADING,
            ]
        );
        $this->add_responsive_control(
            'carousel_nav_width',
            [
                'label' => __('width', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 1,
                        'max' => 200,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-prev,{{WRAPPER}} .custom-swiper-button-next' => 'width: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_responsive_control(
            'carousel_nav_height',
            [
                'label' => __('height', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 1,
                        'max' => 200,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-prev,{{WRAPPER}} .custom-swiper-button-next' => 'height: {{SIZE}}{{UNIT}}!important;line-height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'carousel_nav_offset',
            [
                'label' => __('margin', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => -100,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-next' => 'left: {{SIZE}}{{UNIT}}!important;',
                    '{{WRAPPER}} .custom-swiper-button-prev' => 'right: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_responsive_control(
            'carousel_arrow_size',
            [
                'label' => __('icon size', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-next,{{WRAPPER}} .custom-swiper-button-prev' => 'font-size: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );



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

        // nav normal tab
        $this->start_controls_tab(
            'carousel_nav_style_normal_tab',
            [
                'label' => esc_html__('normal', TEXT_DOMAIN),
            ]
        );
        $this->add_control(
            'carousel_nav_icon_color',
            [
                'label' => esc_html__('Icon color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-next,{{WRAPPER}} .custom-swiper-button-prev' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'carousel_nav_bg_color',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-prev,{{WRAPPER}} .custom-swiper-button-next' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'carousel_nav_border_type',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .custom-swiper-button-prev.swiper-button-primary,{{WRAPPER}} .custom-swiper-button-next.swiper-button-primary',
            ]
        );
        $this->add_responsive_control(
            'carousel_nav_border_radius',
            [
                'label' => esc_html__('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-prev,{{WRAPPER}} .custom-swiper-button-next' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'carousel_nav_shadow',
                'selector' => '{{WRAPPER}} .custom-swiper-button-prev,{{WRAPPER}} .custom-swiper-button-next',
            ]
        );
        $this->end_controls_tab();

        // nav hover tab
        $this->start_controls_tab(
            'carousel_nav_style_hover_tab',
            [
                'label' => esc_html__('hover', TEXT_DOMAIN),
            ]
        );
        $this->add_control(
            'carousel_nav_icon_color_hover',
            [
                'label' => esc_html__('Icon color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-prev:hover,{{WRAPPER}} .custom-swiper-button-next:hover' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'carousel_nav_bg_color_hover',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-prev:hover,{{WRAPPER}} .custom-swiper-button-next:hover' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'carousel_nav_border_type_hover',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .custom-swiper-button-prev.swiper-button-primary:hover,{{WRAPPER}} .custom-swiper-button-next.swiper-button-primary:hover',
            ]
        );
        $this->add_responsive_control(
            'carousel_nav_border_radius_hover',
            [
                'label' => esc_html__('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .custom-swiper-button-prev:hover,{{WRAPPER}} .custom-swiper-button-next:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'carousel_nav_shadow_hover',
                'selector' => '{{WRAPPER}} .custom-swiper-button-prev:hover,{{WRAPPER}} .custom-swiper-button-next:hover',
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();


        $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";
        }

        $args = array(
            'posts_per_page' => $settings['count'],
            'post_status' => 'publish',
            'post_type' => 'post',
            'orderby' => $orderBy,
            'order' => $order,
        );
        $taxonomies = get_object_taxonomies('post', '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);

        // swiper
        $itemsPerGroup = $settings['carousel_items_per_group'];
        $items = $settings['carousel_items'];
        $itemsTablet = $settings['carousel_items_tablet'];
        $itemsMobile = $settings['carousel_items_mobile'];
        $autoplay = $settings['carousel_autoplay'];
        $center = $settings['carousel_center'];
        $loop = $settings['carousel_loop'];
        $margin = $settings['carousel_margin'];
        $smartSpeed = $settings['carousel_smart_speed'];
        $autoplayDelay = $settings['carousel_autoplay_delay'];

        // content
        $showCategory = $settings['show_category'];
        $showDate = $settings['show_date'];
        $showPostMoreBtn = $settings['show_more_btn'];
        $pstMoreBtnText = $settings['more_btn_text'];

        echo "<div class='swiper swiper-before-init products-swiper elementor-swiper buttons-backdrop-desktop' swiper-items-per-group='".$itemsPerGroup."' swiper-items='" . $items . "' swiper-items-tablet='" . $itemsTablet . "' swiper-items-mobile='" . $itemsMobile . "' swiper-autoplay='" . $autoplay . "' swiper-speed='" . $smartSpeed . "' swiper-autoplay-delay='" . $autoplayDelay . "' swiper-center='" . $center . "' swiper-loop='" . $loop . "' swiper-margin='" . $margin . "'>";

        // main swiper wrapper
        echo "<div class='swiper-wrapper'>";
        $query = new \WP_Query($args);
        while ($query->have_posts()): $query->the_post();?>
            <div class="swiper-slide">
                <div class="post-item">
                    <div class="post-item-image">
                        <a href="<?php the_permalink() ?>">
                            <?php if (has_post_thumbnail()): the_post_thumbnail('medium');
                            else:
                                echo "<img src='" . esc_url(get_template_directory_uri() . '/images/default.jpg') . "' alt='image'>";
                            endif; ?>
                        </a>
                        <?php if ($showCategory === 'yes') {
                            $category = get_the_category();
                            $firstCategory = $category[0];?>
                            <a href="<?php echo get_term_link($firstCategory);?>" class="post-item-cat"><?php echo $firstCategory->cat_name;?></a>
                        <?php } ?>

                    </div>
                    <div class="post-item-content">
                        <a href="<?php the_permalink() ?>" class="title"><div><?php the_title(); ?></div></a>

                        <div class="d-flex align-items-center justify-content-between">
                            <?php if ($showDate === 'yes') { ?>
                                <div class="post-item-time"><span class="iconlyBulk-Time-Square"><span class="path1"></span><span class="path2"></span></span><span class="ms-2"><?php banta_date( 'j F Y' ,get_the_date('y-m-d'));?></span></div>
                            <?php } ?>

                            <?php if ($showPostMoreBtn === 'yes') { ?>
                                <a href="<?php the_permalink() ?>" class="more">
                                    <span class="more-title"><?php echo $pstMoreBtnText; ?></span>
                                    <i class="iconly-Arrow-Left icbo font-24"></i>
                                </a>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            </div>
        <?php endwhile; ?>
        <?php wp_reset_postdata();
        echo "</div>";

        // button navigations
        echo "<div class='swiper-backdrop-button prev'></div>";
        echo "<div class='swiper-backdrop-button next'></div>";
        echo "<div class='custom-swiper-button-prev swiper-button-primary'><i class='iconly-Arrow-Right'></i></div>";
        echo "<div class='custom-swiper-button-next swiper-button-primary'><i class='iconly-Arrow-Left'></i></div>";

        echo "<div class='swiper-spinner'></div>";

        echo "</div>";
    }


}

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