<?php
/**
 * Elementor Widget
 * @package Pubzi
 * @since 1.0.0
 */

namespace Elementor;

class Blog_Post extends Widget_Base
{

    /**
     * Get widget name.
     *
     * Retrieve Elementor widget name.
     *
     * @return string Widget name.
     * @since 1.0.0
     * @access public
     *
     */
    public function get_name()
    {
        return 'pubzi-blog-post-widget';
    }

    /**
     * Get widget title.
     *
     * Retrieve Elementor widget title.
     *
     * @return string Widget title.
     * @since 1.0.0
     * @access public
     *
     */
    public function get_title()
    {
        return esc_html__('Blog Post', 'pubzi-core');
    }

    /**
     * Get widget icon.
     *
     * Retrieve Elementor widget icon.
     *
     * @return string Widget icon.
     * @since 1.0.0
     * @access public
     *
     */
    public function get_icon()
    {
        return 'eicon-post';
    }

    /**
     * Get widget categories.
     *
     * Retrieve the list of categories the Elementor widget belongs to.
     *
     * @return array Widget categories.
     * @since 1.0.0
     * @access public
     *
     */
    public function get_categories()
    {
        return ['pubzi_widgets'];
    }

    /**
     * Register Elementor widget controls.
     *
     * Adds different input fields to allow the user to change and customize the widget settings.
     *
     * @since 1.0.0
     * @access protected
     */
    protected function register_controls()
    {

        $this->start_controls_section(
            'settings_section',
            [
                'label' => esc_html__('General Settings', 'pubzi-core'),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'style',
            [
                'label'   => esc_html__( 'Select Style', 'pubzi-core' ),
                'type'    => Controls_Manager::SELECT,
                'default' => 'style1',
                'options' => array(
                    'style1'   => esc_html__( 'Style One', 'pubzi-core' ),
                    'style2'   => esc_html__( 'Style Two', 'pubzi-core' ),
                    'style3'   => esc_html__( 'Style Three', 'pubzi-core' ),
                    'style4'   => esc_html__( 'Style Four', 'pubzi-core' ),
                ),
            ]
        );
        
        $this->add_control('blog_grid', [
            'label' => esc_html__('Blog Grid', 'pubzi-core'),
            'type' => Controls_Manager::SELECT,
            'options' => array(
                'col-lg-2' => esc_html__('col-lg-2', 'pubzi-core'),
                'col-lg-3' => esc_html__('col-lg-3', 'pubzi-core'),
                'col-lg-4' => esc_html__('col-lg-4', 'pubzi-core'),
                'col-lg-6' => esc_html__('col-lg-6', 'pubzi-core'),
                'col-lg-12' => esc_html__('col-lg-12', 'pubzi-core'),
            ),
            'default' => 'col-lg-3',
            'description' => esc_html__('Select Blog Grid', 'pubzi-core')
        ]);   
        
        $this->add_control(
			'button',
			[
				'label'       => __( 'Button', 'pubzi-core' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => esc_html__( 'Enter your button text', 'pubzi-core' ),
				'default' => esc_html__('Read More', 'pubzi-core'),
			]
		);	

        $this->add_control(
            'word_limit',
            [
                'label' => esc_html__('Word Limit', 'pubzi-core'),
                'type' => Controls_Manager::NUMBER,
                'default' => 20,
                'description' => esc_html__('Set the number of words to display from the post content.', 'pubzi-core'),
            ]
        );

        $this->add_control(
            'more_text',
            [
                'label' => esc_html__('More Text', 'pubzi-core'),
                'type' => Controls_Manager::TEXT,
                'default' => '...',
                'description' => esc_html__('Set the text to append after the trimmed words, e.g., "Read More". Leave blank for no text.', 'pubzi-core'),
            ]
        );
   
        $this->add_control('total', [
            'label' => esc_html__('Total Posts', 'pubzi-core'),
            'type' => Controls_Manager::TEXT,
            'default' => '-1',
            'description' => esc_html__('enter how many post you want in masonry , enter -1 for unlimited post.')
        ]);
        $this->add_control('offset', [
            'label' => esc_html__('Offset Posts', 'pubzi-core'),
            'type' => Controls_Manager::TEXT,
            'default' => '0',
            'description' => esc_html__('enter how many post you want in masonry , enter -1 for unlimited post.')
        ]);
        $this->add_control('category', [
            'label' => esc_html__('Category', 'pubzi-core'),
            'type' => Controls_Manager::SELECT2,
            'multiple' => true,
            'options' => pubzi_core()->get_terms_names('category', 'id'),
            'description' => esc_html__('Select category as you want, leave it blank for all categories', 'pubzi-core'),
        ]);        

        $this->add_control('order', [
            'label' => esc_html__('Order', 'pubzi-core'),
            'type' => Controls_Manager::SELECT,
            'options' => array(
                'ASC' => esc_html__('Ascending', 'pubzi-core'),
                'DESC' => esc_html__('Descending', 'pubzi-core'),
            ),
            'default' => 'DESC',
            'description' => esc_html__('select order', 'pubzi-core')
        ]);
        $this->add_control('orderby', [
            'label' => esc_html__('OrderBy', 'pubzi-core'),
            'type' => Controls_Manager::SELECT,
            'options' => array(
                'ID' => esc_html__('ID', 'pubzi-core'),
                'title' => esc_html__('Title', 'pubzi-core'),
                'date' => esc_html__('Date', 'pubzi-core'),
                'rand' => esc_html__('Random', 'pubzi-core'),
                'comment_count' => esc_html__('Most Comments', 'pubzi-core'),
            ),
            'default' => 'ID',
            'description' => esc_html__('select order', 'pubzi-core')
        ]);      
        
           $this->add_control(
            'image_thumb_display',
            [
                'label' => esc_html__('Image Display', 'pubzi-core'),
                'type' => Controls_Manager::SWITCHER,
                'description' => esc_html__('show/hide description', 'pubzi-core'),
            ]
        );
        
        $this->add_control(
            'thumb_date',
            [
                'label' => esc_html__('Thumb Date Show/Hide', 'pubzi-core'),
                'type' => Controls_Manager::SWITCHER,
                'description' => esc_html__('show/hide description', 'pubzi-core'),
            ]
        );
      
        $this->add_control(
            'pagination',
            [
                'label' => esc_html__('Pagination', 'pubzi-core'),
                'type' => Controls_Manager::SWITCHER,
                'description' => esc_html__('you can set yes to show pagination.', 'pubzi-core'),
                'default' => 'no',
            ]
        );
        
          $this->add_control(
            'category_display',
            [
                'label' => esc_html__('Category Display', 'pubzi-core'),
                'type' => Controls_Manager::SWITCHER,
                'description' => esc_html__('Show  Or Hide Category.', 'pubzi-core'),
            ]
        );

          $this->add_control(
            'tag_display',
            [
                'label' => esc_html__('Tags Display', 'pubzi-core'),
                'type' => Controls_Manager::SWITCHER,
                'description' => esc_html__('Show  Or Hide Tags.', 'pubzi-core'),
            ]
        );
        
        $this->add_control(
            'pagination_alignment',
            [
                'label' => esc_html__('Pagination Alignment', 'pubzi-core'),
                'type' => Controls_Manager::SELECT,
                'options' => array(
                    'start' => esc_html__('Left Align', 'pubzi-core'),
                    'center' => esc_html__('Center Align', 'pubzi-core'),
                    'end' => esc_html__('Right Align', 'pubzi-core'),
                ),
                'description' => esc_html__('you can set pagination alignment.', 'pubzi-core'),
                'default' => 'start',
                'condition' => array('pagination' => 'yes'),
            ]
        );
        $this->end_controls_section();



        		// ===== Tab Start - 5: Title Settings =====

		$this->start_controls_section(
			'title_settings',
			[
				'label' => __( 'Title Setting', 'pubzi-core' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'show_title',
			[
				'label'   => esc_html__( 'Show Title', 'pubzi-core' ),
				'type'    => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => esc_html__( 'Show', 'pubzi-core' ),
						'icon'  => 'eicon-check-circle',
					],
					'none' => [
						'title' => esc_html__( 'Hide', 'pubzi-core' ),
						'icon'  => 'eicon-close-circle',
					],
				],
				'default'   => 'show',
				'selectors' => [
					'{{WRAPPER}} .news-box-items .content h3 a' => 'display: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'title_alignment',
			[
				'label'     => esc_html__( 'Alignment', 'pubzi-core' ),
				'type'      => \Elementor\Controls_Manager::CHOOSE,
				'options'   => [
					'left' => [
						'title' => esc_html__( 'Left', 'pubzi-core' ),
						'icon'  => 'eicon-text-align-left',
					],
					'center' => [
						'title' => esc_html__( 'Center', 'pubzi-core' ),
						'icon'  => 'eicon-text-align-center',
					],
					'right' => [
						'title' => esc_html__( 'Right', 'pubzi-core' ),
						'icon'  => 'eicon-text-align-right',
					],
				],
				'toggle'    => true,
				'condition' => [ 'show_title' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .news-box-items .content h3 a' => 'text-align: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'title_margin',
			[
				'label'      => __( 'Margin', 'pubzi-core' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'condition'  => [ 'show_title' => 'show' ],
				'selectors'  => [
					'{{WRAPPER}} .news-box-items .content h3 a' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
				],
			]
		);

		$this->add_control(
			'title_padding',
			[
				'label'      => __( 'Padding', 'pubzi-core' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'condition'  => [ 'show_title' => 'show' ],
				'selectors'  => [
					'{{WRAPPER}} .news-box-items .content h3 a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
				],
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			[
				'name'      => 'title_typography',
				'label'     => __( 'Typography', 'pubzi-core' ),
				'selector'  => '{{WRAPPER}} .news-box-items .content h3 a',
				'condition' => [ 'show_title' => 'show' ],
			]
		);

		$this->add_control(
			'title_color',
			[
				'label'     => __( 'Color', 'pubzi-core' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'condition' => [ 'show_title' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .news-box-items .content h3 a' => 'color: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'title_hover_color',
			[
				'label'     => __( 'Hover Color', 'pubzi-core' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'condition' => [ 'show_title' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .news-box-items .content h3 a:hover' => 'color: {{VALUE}} !important',
				],
			]
		);

		$this->end_controls_section();

		// ===== End Tab - 5: Title Settings =====


        // ===== Tab Start - 6: Date Settings =====

        $this->start_controls_section(
            'date_settings',
            [
                'label' => __( 'Date Setting', 'pubzi-core' ),
                'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control(
            'show_date',
            [
                'label'   => esc_html__( 'Show Date', 'pubzi-core' ),
                'type'    => \Elementor\Controls_Manager::CHOOSE,
                'options' => [
                    'show' => [
                        'title' => esc_html__( 'Show', 'pubzi-core' ),
                        'icon'  => 'eicon-check-circle',
                    ],
                    'none' => [
                        'title' => esc_html__( 'Hide', 'pubzi-core' ),
                        'icon'  => 'eicon-close-circle',
                    ],
                ],
                'default'   => 'show',
                'selectors' => [
                    '{{WRAPPER}} .news-box-items .content span' => 'display: {{VALUE}} !important',
                ],
            ]
        );

        $this->add_control(
            'date_alignment',
            [
                'label'     => esc_html__( 'Alignment', 'pubzi-core' ),
                'type'      => \Elementor\Controls_Manager::CHOOSE,
                'options'   => [
                    'left' => [
                        'title' => esc_html__( 'Left', 'pubzi-core' ),
                        'icon'  => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__( 'Center', 'pubzi-core' ),
                        'icon'  => 'eicon-text-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__( 'Right', 'pubzi-core' ),
                        'icon'  => 'eicon-text-align-right',
                    ],
                ],
                'toggle'    => true,
                'condition' => [ 'show_date' => 'show' ],
                'selectors' => [
                    '{{WRAPPER}} .news-box-items .content span' => 'text-align: {{VALUE}} !important',
                ],
            ]
        );

        $this->add_control(
            'date_margin',
            [
                'label'      => __( 'Margin', 'pubzi-core' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%', 'em' ],
                'condition'  => [ 'show_date' => 'show' ],
                'selectors'  => [
                    '{{WRAPPER}} .news-box-items .content span' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
                ],
            ]
        );

        $this->add_control(
            'date_padding',
            [
                'label'      => __( 'Padding', 'pubzi-core' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%', 'em' ],
                'condition'  => [ 'show_date' => 'show' ],
                'selectors'  => [
                    '{{WRAPPER}} .news-box-items .content span' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
                ],
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name'      => 'date_typography',
                'label'     => __( 'Typography', 'pubzi-core' ),
                'selector'  => '{{WRAPPER}} .news-box-items .content span',
                'condition' => [ 'show_date' => 'show' ],
            ]
        );

        $this->add_control(
            'date_color',
            [
                'label'     => __( 'Color', 'pubzi-core' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'condition' => [ 'show_date' => 'show' ],
                'selectors' => [
                    '{{WRAPPER}} .news-box-items .content span' => 'color: {{VALUE}} !important',
                ],
            ]
        );

        $this->end_controls_section();

        // ===== End Tab - 6: Date Settings =====



    }

    /**
     * Render Elementor widget output on the frontend.
     * Written in PHP and used to generate the final HTML.
     *
     * @since 1.0.0
     * @access protected
     */
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $rand_numb = rand(333, 999999999);
        //query settings
        $total_posts = $settings['total'];
        $category = $settings['category'];
        $order = $settings['order'];
        $orderby = $settings['orderby'];
        $offset = $settings['offset'];
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

        //other settings
        $pagination = $settings['pagination'] ? false : true;
        $pagination_alignment = $settings['pagination_alignment'];

        //setup query       

        $args = array(
            'post_type' => 'post',
            'posts_per_page' => $total_posts,
            'order' => $order,
            'orderby' => $orderby,
            'paged' => $paged, // Use paged instead of offset
            'post_status' => 'publish',
            'ignore_sticky_posts' => 1,
        );
        
        if (!empty($category)) {
            $args['tax_query'] = array(
                array(
                    'taxonomy' => 'category',
                    'field' => 'term_id',
                    'terms' => $category
                )
            );
        }
        
        $post_data = new \WP_Query($args);
        
        $delay = 0.2; 
        $count = 0;

        ?>

        
        <?php  if ( 'style1' === $settings['style'] ) : ?>        

        <div class="row">
            <?php while ($post_data->have_posts()):$post_data->the_post(); 
                $img_id = get_post_thumbnail_id(get_the_ID()) ? get_post_thumbnail_id(get_the_ID()) : false;
                $img_url_val = $img_id ? wp_get_attachment_image_src($img_id, 'pubzi_grid_blog_12', false) : '';
                $img_url = is_array($img_url_val) && !empty($img_url_val) ? $img_url_val[0] : '';
                $img_alt = get_post_meta($img_id, '_wp_attachment_image_alt', true);

                $count++;
            ?> 
            <div class="<?php echo esc_attr($settings['blog_grid']);?> wow fadeInUp" data-wow-delay="<?php echo esc_attr($delay); ?>s">
                <div class="news-box-items">

                    <?php if ( $count % 2 == 1 ) : ?>
                        <div class="thumb">
                            <?php if(!empty($settings['image_thumb_display'])) : ?>
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                            <?php endif; ?>
                        </div>
                        <div class="content">
                            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                            <?php if(!empty($settings['thumb_date'])) : ?>
                            <span class="gt-date">
                                <i class="fa-solid fa-calendar-days"></i> <?php echo get_the_date('j F Y'); ?>
                            </span>
                            <?php endif; ?>
                        </div>

                    <?php else : ?>
                        <div class="content">
                            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                            <?php if(!empty($settings['thumb_date'])) : ?>
                            <span class="gt-date">
                                <i class="fa-solid fa-calendar-days"></i> <?php echo get_the_date('j F Y'); ?>
                            </span>
                            <?php endif; ?>
                        </div>
                        <div class="thumb style-2">
                            <?php if(!empty($settings['image_thumb_display'])) : ?>
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                            <?php endif; ?>
                        </div>
                    <?php endif; ?>

                </div>
            </div>        

        <?php
            endwhile;
            wp_reset_query();
        ?>

        <?php if (!$pagination) { ?>
            <div class="col-lg-12">
                <div class="blog-pagination text-<?php echo esc_attr($pagination_alignment) ?>">
                    
                        <?php pubzi()->post_pagination($post_data); ?>

                </div>
            </div>
        <?php } ?>   

        </div>          


        <?php  elseif ( 'style2' === $settings['style'] ) : ?>

            <div class="news-left-items">
                <div class="row g-4">
                     <?php while ($post_data->have_posts()):$post_data->the_post(); 
                        $img_id = get_post_thumbnail_id(get_the_ID()) ? get_post_thumbnail_id(get_the_ID()) : false;
                        $img_url_val = $img_id ? wp_get_attachment_image_src($img_id, 'pubzi_grid_blog_12', false) : '';
                        $img_url = is_array($img_url_val) && !empty($img_url_val) ? $img_url_val[0] : '';
                        $img_alt = get_post_meta($img_id, '_wp_attachment_image_alt', true);

                        $count++;
                    ?> 
                    
                    <div class="<?php echo esc_attr($settings['blog_grid']);?> wow fadeInUp" data-wow-delay=".3s">

                        <?php if ( $count % 2 == 1 ) : ?>
                        <div class="news-box-items mt-0">
                            <div class="content">
                                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                <?php if(!empty($settings['thumb_date'])) : ?>
                                <span class="gt-date">
                                    <i class="fa-solid fa-calendar-days"></i> <?php echo get_the_date('j F Y'); ?>
                                </span>
                                <?php endif; ?>
                            </div>
                            <div class="thumb style-2">
                            <?php if(!empty($settings['image_thumb_display'])) : ?>
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                            <?php endif; ?>
                            </div>
                        </div>

                        <?php else : ?>
                        <div class="news-box-items mt-0">
                            <div class="thumb">
                            <?php if(!empty($settings['image_thumb_display'])) : ?>
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                            <?php endif; ?>
                            </div>
                            <div class="content">
                                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                               <?php if(!empty($settings['thumb_date'])) : ?>
                                <span class="gt-date">
                                    <i class="fa-solid fa-calendar-days"></i> <?php echo get_the_date('j F Y'); ?>
                                </span>
                                <?php endif; ?>
                            </div>
                        </div>
                        <?php endif; ?>

                    </div>
                
                <?php
                    endwhile;
                    wp_reset_query();
                ?>

                <?php if (!$pagination) { ?>
                    <div class="col-lg-12">
                        <div class="blog-pagination text-<?php echo esc_attr($pagination_alignment) ?>">
                            
                                <?php pubzi()->post_pagination($post_data); ?>

                        </div>
                    </div>
                <?php } ?>   

                </div>
            </div>

         <?php  elseif ( 'style3' === $settings['style'] ) : ?>

             <div class="row g-4">

                <?php while ($post_data->have_posts()):$post_data->the_post(); 
                    $img_id = get_post_thumbnail_id(get_the_ID()) ? get_post_thumbnail_id(get_the_ID()) : false;
                    $img_url_val = $img_id ? wp_get_attachment_image_src($img_id, 'pubzi_grid_blog_12', false) : '';
                    $img_url = is_array($img_url_val) && !empty($img_url_val) ? $img_url_val[0] : '';
                    $img_alt = get_post_meta($img_id, '_wp_attachment_image_alt', true);
                ?> 

                <div class="<?php echo esc_attr($settings['blog_grid']);?> wow fadeInUp" data-wow-delay=".3s">
                    <div class="gt-news-card-item mt-0">
                        <?php if(!empty($settings['image_thumb_display'])) : ?>
                        <div class="gt-news-image">                            
                            <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">                            
                        </div>
                        <?php endif; ?>

                        <div class="gt-news-content">
                            <ul class="gt-list">
                                <?php if(!empty($settings['thumb_date'])) : ?>
                                <li>
                                    <i class="fa-regular fa-calendar"></i>
                                    <?php echo get_the_date('j F Y'); ?>
                                </li>
                                <?php endif; ?>
                            </ul>
                            <h4>
                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            </h4>
                            <p><?php echo esc_html( wp_trim_words( wp_strip_all_tags( get_the_content() ), $settings['word_limit'], $settings['more_text'] ) ); ?></p>
                            <a href="<?php the_permalink(); ?>" class="icon"><i class="fa-solid fa-arrow-right"></i></a>
                        </div>
                    </div>
                </div>

                <?php
                    endwhile;
                    wp_reset_query();
                ?>

                <?php if (!$pagination) { ?>
                    <div class="col-lg-12">
                        <div class="blog-pagination text-<?php echo esc_attr($pagination_alignment) ?>">
                            
                                <?php pubzi()->post_pagination($post_data); ?>

                        </div>
                    </div>
                <?php } ?>  

            </div>

        <?php  elseif ( 'style4' === $settings['style'] ) : ?>

        <div class="swiper news-slider">
            <div class="swiper-wrapper">

                <?php while ($post_data->have_posts()):$post_data->the_post(); 
                    $img_id = get_post_thumbnail_id(get_the_ID()) ? get_post_thumbnail_id(get_the_ID()) : false;
                    $img_url_val = $img_id ? wp_get_attachment_image_src($img_id, 'pubzi_grid_blog_12', false) : '';
                    $img_url = is_array($img_url_val) && !empty($img_url_val) ? $img_url_val[0] : '';
                    $img_alt = get_post_meta($img_id, '_wp_attachment_image_alt', true);

                    $count++;
                ?> 

                <?php if ( $count % 2 == 1 ) : ?>
                <div class="swiper-slide">
                    <div class="news-box-items">
                        <div class="thumb">
                            <?php if(!empty($settings['image_thumb_display'])) : ?>
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                            <?php endif; ?>
                        </div>
                        <div class="content">
                            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                            <?php if(!empty($settings['thumb_date'])) : ?>
                            <span class="gt-date">
                                <i class="fa-solid fa-calendar-days"></i> <?php echo get_the_date('j F Y'); ?>
                            </span>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                 <?php else : ?>
                <div class="swiper-slide">
                    <div class="news-box-items">
                        <div class="content">
                            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                            <?php if(!empty($settings['thumb_date'])) : ?>
                            <span class="gt-date">
                                <i class="fa-solid fa-calendar-days"></i> <?php echo get_the_date('j F Y'); ?>
                            </span>
                            <?php endif; ?>
                        </div>
                        <div class="thumb style-2">
                            <?php if(!empty($settings['image_thumb_display'])) : ?>
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                                <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img_alt ); ?>">
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <?php endif; ?>

               <?php
                    endwhile;
                    wp_reset_query();
                ?>

            </div>
        </div>

        <?php endif ;?>	

        <?php
    }
}

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