<?php

class PZY_Posts_Slider extends \PEZESHKYAR\CORE\PZY_SWIPER
{
    public function get_name()
    {
        return 'pzy_posts_slider';
    }

    public function get_title()
    {
        return esc_html__('اسلایدر نوشته ها', 'pezeshkyar');
    }

    public function get_icon()
    {
        return 'eicon-post-list';
    }

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

    public function get_keywords()
    {
        return ['pzy', 'post', 'posts', 'slider'];
    }

    public function get_script_depends()
    {
        return ["swiper.js", "theme-script.js"];
    }

    public function get_style_depends()
    {
        return ['swiper.css'];
    }

    protected function register_controls()
    {
        $this->start_controls_section(
            'section_content',
            [
                'label' => esc_html__('فیلتر نوشته ها', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control('post_count', [
            'label' => esc_html__('چند اسلاید نشان داده شود؟', 'pezeshkyar'),
            'type' => \Elementor\Controls_Manager::NUMBER,
            'default' => 3,
        ]);

        $this->add_control('order_by', [
            'label' => esc_html__('مرتب سازی بر اساس', 'pezeshkyar'),
            'type' => \Elementor\Controls_Manager::SELECT,
            'default' => 'date',
            'options' => [
                'date' => esc_html__('تاریخ', 'pezeshkyar'),
                'title' => esc_html__('عنوان', 'pezeshkyar'),
                'comments_count' => esc_html__('تعداد دیدگاه', 'pezeshkyar'),
                'last_modified' => esc_html__('آخرین ویرایش', 'pezeshkyar'),
                'random' => esc_html__('تصادفی', 'pezeshkyar'),
            ],
        ]);

        $this->add_control('order', [
            'label' => esc_html__('ترتیب', 'pezeshkyar'),
            'type' => \Elementor\Controls_Manager::SELECT,
            'default' => 'asc',
            'options' => [
                'asc' => esc_html__('صعودی', 'pezeshkyar'),
                'desc' => esc_html__('نزولی', 'pezeshkyar'),
            ],
        ]);

        $this->add_control('date', [
            'label' => esc_html__('تاریخ', 'pezeshkyar'),
            'type' => \Elementor\Controls_Manager::SELECT,
            'default' => 'all',
            'options' => [
                'all' => esc_html__('همه', 'pezeshkyar'),
                'past_day' => esc_html__('روز گذشته', 'pezeshkyar'),
                'past_week' => esc_html__('هفته گذشته', 'pezeshkyar'),
                'past_month' => esc_html__('ماه گذشته', 'pezeshkyar'),
                'past_quarter' => esc_html__('فصل گذشته', 'pezeshkyar'),
                'past_year' => esc_html__('سال گذشته', 'pezeshkyar'),
                'custom' => esc_html__('سفارشی', 'pezeshkyar'),
            ],
        ]);

        $this->add_control(
            'start_time',
            [
                'label' => esc_html__('از تاریخ', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DATE_TIME,
                'condition' => [
                    'date' => 'custom',
                ],
            ]
        );

        $this->add_control(
            'end_time',
            [
                'label' => esc_html__('تا تاریخ', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DATE_TIME,
                'condition' => [
                    'date' => 'custom',
                ],
            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'post_cart_content',
            [
                'label' => esc_html__('کارتهای نوشته', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
            'read_more_text',
            [
                'label' => esc_html__('متن لینک مطالعه نوشته', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('مطالعه', 'pezeshkyar'),
            ]
        );
        $this->add_control(
            'show_comments_count',
            [
                'label' => esc_html__('تعداد کامنت ها را نشان بده؟', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('بله', 'pezeshkyar'),
                'label_off' => esc_html__('خیر', 'pezeshkyar'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );
        $this->add_control(
            'show_views_count',
            [
                'label' => esc_html__('تعداد بازدیدها را نشان بده؟', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('بله', 'pezeshkyar'),
                'label_off' => esc_html__('خیر', 'pezeshkyar'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'post_cart_style',
            [
                'label' => esc_html__('کارتهای نوشته', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'post_carts_container_margin',
            [
                'label' => esc_html__('حاشیه خارجی کانتینر کارتها', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'default' => [
                    'top' => 0,
                    'right' => 0,
                    'bottom' => 0,
                    'left' => 0,
                    'unit' => 'px',
                    'isLinked' => true,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-posts-slider' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_cart_padding',
            [
                'label' => esc_html__('فاصله داخلی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'default' => [
                    'top' => 0,
                    'right' => 0,
                    'bottom' => 0,
                    'left' => 0,
                    'unit' => 'px',
                    'isLinked' => true,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'post_cart_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-post',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'post_cart_border',
                'selector' => '{{WRAPPER}} .pzy-post',
            ]
        );
        $this->add_control(
            'post_cart_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_hover_cart_heading',
            [
                'label' => esc_html__('حالت هاور', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'post_hover_cart_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-post:hover',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'post_hover_cart_border',
                'selector' => '{{WRAPPER}} .pzy-post:hover',
            ]
        );
        $this->end_controls_section();


        $this->start_controls_section(
            'post_feature_style',
            [
                'label' => esc_html__('باکس تصویر شاخص', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Css_Filter::get_type(),
            [
                'name' => 'post_feature_filters',
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-header img',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'post_feature_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-header',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'post_feature_border',
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-header',
            ]
        );
        $this->add_control(
            'post_feature_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-header' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_hover_feature_heading',
            [
                'label' => esc_html__('حالت هاور', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Css_Filter::get_type(),
            [
                'name' => 'post_hover_feature_filters',
                'selector' => '{{WRAPPER}} .pzy-post:hover .pzy-post-header img',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'post_hover_feature_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-post:hover .pzy-post-header',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'post_hover_feature_border',
                'selector' => '{{WRAPPER}} .pzy-post:hover .pzy-post-header',
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'post_reading_time_style',
            [
                'label' => esc_html__('زمان مطالعه نوشته', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'post_reading_time_padding',
            [
                'label' => esc_html__('فاصله داخلی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_reading_time_bottom_offset',
            [
                'label' => esc_html__('فاصله از پایین', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time' => 'bottom: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_reading_time_left_offset',
            [
                'label' => esc_html__('فاصله از چپ', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time' => 'left: {{SIZE}}{{UNIT}};',
                ]
            ]
        );
        $this->add_control(
            'post_reading_time_min_width',
            [
                'label' => esc_html__('کمترین عرض', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'default' => [
                    'unit' => 'px',
                    'size' => 74,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time' => 'min-width: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'post_reading_time_background',
                'types' => ['classic', 'gradient', 'video'],
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'post_reading_time_border',
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time',
            ]
        );
        $this->add_control(
            'post_reading_time_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_reading_time_number_text_color',
            [
                'label' => esc_html__('رنگ متن زمان', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time .pzy-read-time-number' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'post_reading_time_number_typography',
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time .pzy-read-time-number',
            ]
        );
        $this->add_control(
            'post_reading_time_unit_text_color',
            [
                'label' => esc_html__('رنگ متن واحد زمان', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time .pzy-read-time-unit' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'post_reading_time_unit_typography',
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time .pzy-read-time-unit',
            ]
        );
        $this->add_control(
            'post_reading_time_gap',
            [
                'label' => esc_html__('فاصله زمان و واحد زمان', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-header .pzy-read-time' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'post_title_style',
            [
                'label' => esc_html__('عنوان نوشته', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'post_title_margin',
            [
                'label' => esc_html__('حاشیه خارجی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_title_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-title a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'post_title_typography',
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-title',
            ]
        );
        $this->add_control(
            'post_hover_title_style',
            [
                'label' => esc_html__('حالت هاور', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'post_hover_title_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post:hover .pzy-post-title a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'post_excerpt_style',
            [
                'label' => esc_html__('چکیده نوشته', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'post_excerpt_margin',
            [
                'label' => esc_html__('حاشیه خارجی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-excerpt' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_excerpt_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-excerpt' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'post_excerpt_typography',
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-excerpt',
            ]
        );

        $this->add_control(
            'post_hover_excerpt_style',
            [
                'label' => esc_html__('حالت هاور', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'post_hover_excerpt_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post:hover .pzy-post-excerpt' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'post_info_style',
            [
                'label' => esc_html__('آمار نوشته', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'post_info_text_color',
            [
                'label' => esc_html__('رنگ متن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-footer .pzy-post-info' => 'color: {{VALUE}}',
                    '{{WRAPPER}} .pzy-post .pzy-post-footer .pzy-post-info .iawp-view-counter' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'post_info_typography',
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-footer .pzy-post-info .pzy-post-info-text',
            ]
        );
        $this->add_control(
            'post_info_icon_size',
            [
                'label' => esc_html__('سایز آیکون', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-footer .pzy-post-info .pzy-post-info-icon' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_info_gap',
            [
                'label' => esc_html__('فاصله بین نوشته و آیکون', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-footer .pzy-post-info' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_footer_gap',
            [
                'label' => esc_html__('فاصله بین اجزای فوتر کارت', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-footer' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'post_footer_margin',
            [
                'label' => esc_html__('حاشیه خارجی فوتر کارت', 'pezeshkyar-core'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-footer' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_hover_info_style',
            [
                'label' => esc_html__('حالت هاور', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'post_hover_info_text_color',
            [
                'label' => esc_html__('رنگ متن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post:hover .pzy-post-footer .pzy-post-info' => 'color: {{VALUE}}',
                    '{{WRAPPER}} .pzy-post:hover .pzy-post-footer .pzy-post-info .iawp-view-counter' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'read_more_style',
            [
                'label' => esc_html__('لینک مطالعه نوشته', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'post_read_more_text_color',
            [
                'label' => esc_html__('رنگ متن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-footer .pzy-read-more' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'post_read_more_typography',
                'selector' => '{{WRAPPER}} .pzy-post .pzy-post-footer .pzy-read-more',
            ]
        );
        $this->add_control(
            'post_read_more_icon_size',
            [
                'label' => esc_html__('سایز آیکون', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-footer .pzy-read-more .pzy-read-more-icon' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_read_more_gap',
            [
                'label' => esc_html__('فاصله بین متن و آیکون', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-post .pzy-post-footer .pzy-read-more' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'post_hover_read_more',
            [
                'label' => esc_html__('حالت هاور', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'post_hover_read_more_text_color',
            [
                'label' => esc_html__('رنگ متن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-post:hover .pzy-post-footer .pzy-read-more' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->end_controls_section();

        parent::register_controls();

    }

    protected function render_slides()
    {
        $query = $this->items;
        $read_more_text = $this->get_settings_for_display('read_more_text');
        $show_comments_count = $this->get_settings_for_display('show_comments_count') == 'yes';
        $show_views_count = $this->get_settings_for_display('show_views_count') == 'yes';
        while ($query->have_posts()) {
            $query->the_post();
            // Output your post template here
            ?>
            <div class="swiper-slide">
                <article class="pzy-post">
                    <div class="pzy-post-header">
                        <a class="pzy-post-img-link" href="<?php the_permalink(); ?>">
                            <img src="<?php echo get_the_post_thumbnail_url(get_the_ID()) ?>"
                                 alt="<?php echo get_the_title() ?>"/>
                        </a>
                        <div class="pzy-read-time">
                            <span class="pzy-read-time-number"><?php echo estimate_reading_time_in_minutes(get_the_ID())['reading_time'] ?></span>
                            <span class="pzy-read-time-unit"><?php esc_html_e('دقیقه', 'pezeshkyar'); ?></span>
                        </div>
                    </div>
                    <div class="pzy-post-body">
                        <h3 class="pzy-post-title"><a
                                    href="<?php the_permalink(); ?>"><?php the_title() ?></a></h3>
                        <div class="pzy-post-excerpt"><?php echo get_the_excerpt() ?></div>
                    </div>
                    <div class="pzy-post-footer">
                        <?php if ($show_comments_count): ?>
                            <div class="pzy-post-info">
                                <i class="pzy-post-info-icon" data-feather="message-square"></i>
                                <span class="pzy-post-info-text"><?php echo get_comments_number(); ?></span>
                            </div>
                        <?php endif; ?>
                        <?php if (pzy_independent_analytics_enabled() && $show_views_count): ?>
                            <div class="pzy-post-info">
                                <i class="pzy-post-info-icon" data-feather="bar-chart-2"></i>
                                <span class="pzy-post-info-text">
                                    <?php 
                                    $views = get_post_meta(get_the_ID(),'iawp_total_views',true);
                                    if(is_numeric($views)){
                                        $views = number_format($views);
                                    }
                                    ?>
                                    <?php echo $views ?>
                                </span>
                            </div>
                        <?php endif; ?>
                        <div class="pzy-cover-gap"></div>
                        <a class="pzy-read-more" href="<?php the_permalink(); ?>">
                            <span class="pzy-read-more-text"><?php echo $read_more_text ?? __('مطالعه', 'pezeshkyar') ?></span>
                            <i class="pzy-read-more-icon" data-feather="arrow-left"></i>
                        </a>
                    </div>
                </article>
            </div>
            <?php
        }
    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();

        $args = [
            'post_type' => 'post',  // Change 'custom_post' to your custom post type
            'posts_per_page' => $settings['post_count'],
            'orderby' => $settings['order_by'],
            'order' => $settings['order'],
        ];

        // Handle different date filters
        switch ($settings['date']) {
            case 'past_day':
                $args['date_query'] = [
                    'after' => '1 day ago',
                ];
                break;
            case 'past_week':
                $args['date_query'] = [
                    'after' => '1 week ago',
                ];
                break;
            case 'past_month':
                $args['date_query'] = [
                    'after' => '1 month ago',
                ];
                break;
            case 'past_quarter':
                $args['date_query'] = [
                    'after' => '3 months ago',
                ];
                break;
            case 'past_year':
                $args['date_query'] = [
                    'after' => '1 year ago',
                ];
                break;
            case 'custom':
                $date_query = [];

                if (!empty($settings['start_time'])) {
                    $date_query['after'] = $settings['start_time'];
                }

                if (!empty($settings['end_time'])) {
                    $date_query['before'] = $settings['end_time'];
                }

                if (!empty($date_query)) {
                    $date_query['inclusive'] = true;
                    $args['date_query'] = [$date_query];
                }
                break;
        }

        // Adjust the orderby parameter if necessary
        if ($settings['order_by'] === 'comments_count') {
            $args['orderby'] = 'comment_count';
        } elseif ($settings['order_by'] === 'last_modified') {
            $args['orderby'] = 'modified';
        } elseif ($settings['order_by'] === 'random') {
            $args['orderby'] = 'rand';
        }

        // Execute the query
        $query = new \WP_Query($args);
        $this->set_items($query);

        if ($query->have_posts()) {
            ?>
            <div class="pzy-posts-slider">
                <?php parent::render(); ?>
            </div>
            <?php
            wp_reset_postdata();
        }

        echo <<<EOL
<script>
feather.replace();
</script>
EOL;

    }
}

