<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Utils;
use Sifency\Traits\Sifency_Addons_Help_Controls;
use Sifency\Traits\Sifency_Addons_Master_Typography;
use Sifency\Traits\Sifency_Addons_Query_Arg_Controls;
use Sifency\Traits\Sifency_Addons_Image_Style_Controls;
use Sifency\Traits\Sifency_Addons_Item_Style_Controls;
use Sifency\Traits\Sifency_Addons_Animation_Controls;
use Sifency\Traits\Sifency_Addons_Animation_Manager;
use Sifency\Classes\Sifency_Addons_Widget_Base;

class Sifency_Multi_Directional_Columns extends Sifency_Addons_Widget_Base {
	use Sifency_Addons_Master_Typography;
	use Sifency_Addons_Query_Arg_Controls;
	use Sifency_Addons_Image_Style_Controls;
	use Sifency_Addons_Item_Style_Controls;
	use Sifency_Addons_Animation_Controls;
	use Sifency_Addons_Help_Controls;

	public function __construct( $data = array(), $args = null ) {
		parent::__construct( $data, $args );
		$this->wg_config = array(
			'name'           => 'sifency-multi-scroll',
			'title'          => 'Sifency Multi-Scroll Columns',
			'icon'           => 'eicon-scroll',
			'category'       => array( 'sifency-creative-widgets' ),
			'script_depends' => array( 'sifency-multi-scroll-script' ),
			'style_depends'  => array( 'sifency-sun-style' ),
		);
	}

	protected function register_controls() {

		/*
		 ================================================================
		 *  CONTENT TAB
		 * ============================================================== */
		$this->start_controls_section(
			'section_content',
			array(
				'label' => __( 'Gallery Items', 'sifency-addons' ),
			)
		);

		$this->add_control(
			'data_source',
			array(
				'label'   => __( 'Data Source', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'manual',
				'options' => array(
					'manual' => __( 'Manual', 'sifency-addons' ),
					'post'   => __( 'Post Query', 'sifency-addons' ),
				),
			)
		);

		$repeater = new Repeater();

		$repeater->add_control(
			'image',
			array(
				'label'   => __( 'Image', 'sifency-addons' ),
				'type'    => Controls_Manager::MEDIA,
				'default' => array( 'url' => Utils::get_placeholder_image_src() ),
			)
		);

		$repeater->add_control(
			'title',
			array(
				'label'   => __( 'Title', 'sifency-addons' ),
				'type'    => Controls_Manager::TEXT,
				'default' => __( 'Project Name', 'sifency-addons' ),
			)
		);

		$repeater->add_control(
			'category',
			array(
				'label'   => __( 'Category', 'sifency-addons' ),
				'type'    => Controls_Manager::TEXT,
				'default' => __( 'Art Direction', 'sifency-addons' ),
			)
		);

		$repeater->add_control(
			'excerpt',
			array(
				'label'   => __( 'Excerpt', 'sifency-addons' ),
				'type'    => Controls_Manager::TEXTAREA,
				'default' => __( 'Project description goes here.', 'sifency-addons' ),
			)
		);

		$repeater->add_control(
			'link',
			array(
				'label' => __( 'Link', 'sifency-addons' ),
				'type'  => Controls_Manager::URL,
			)
		);

		$this->add_control(
			'items',
			array(
				'label'       => __( 'Items', 'sifency-addons' ),
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
				'condition'   => array( 'data_source' => 'manual' ),
			)
		);

		$this->add_control(
			'show_excerpt',
			array(
				'label'        => __( 'Show Excerpt', 'sifency-addons' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => __( 'Show', 'sifency-addons' ),
				'label_off'    => __( 'Hide', 'sifency-addons' ),
				'return_value' => 'yes',
				'default'      => 'no',
			)
		);

		$this->add_control(
			'excerpt_length',
			array(
				'label'     => __( 'Excerpt Length', 'sifency-addons' ),
				'type'      => Controls_Manager::NUMBER,
				'default'   => 15,
				'condition' => array( 'show_excerpt' => 'yes' ),
			)
		);

		$this->add_control(
			'max_categories',
			array(
				'label'   => __( 'Max Categories to Show', 'sifency-addons' ),
				'type'    => Controls_Manager::NUMBER,
				'default' => 1,
				'min'     => 1,
			)
		);

		$this->add_responsive_control(
			'columns_count',
			array(
				'label'          => __( 'Columns', 'sifency-addons' ),
				'type'           => Controls_Manager::SELECT,
				'default'        => '4',
				'tablet_default' => '2',
				'mobile_default' => '1',
				'options'        => array(
					'1' => '1',
					'2' => '2',
					'3' => '3',
					'4' => '4',
					'5' => '5',
				),
				'separator'      => 'before',
			)
		);

		$this->end_controls_section();
		$this->add_sifency_arg_controls(
			array(
				'condition' => array( 'data_source' => 'post' ),
			)
		);

		/*
		 ================================================================
		 *  STYLE TAB
		 * ============================================================== */
		$this->start_controls_section(
			'section_style',
			array(
				'label' => __( 'Layout & Style', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);

		/* ── Pin duration ─────────────────────────────────────────────── */
		$this->add_responsive_control(
			'sticky_height',
			array(
				'label'     => __( 'Viewport Height (Sticky Container)', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'vh' => array(
						'min'  => 20,
						'max'  => 100,
						'step' => 1,
					),
				),
				'default'   => array(
					'size' => 100,
					'unit' => 'vh',
				),
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-sticky' => 'height: {{SIZE}}{{UNIT}};' ),
			)
		);

		$this->add_control(
			'sticky_valign',
			array(
				'label'     => __( 'Vertical Alignment', 'sifency-addons' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'flex-start' => array(
						'title' => 'Top',
						'icon'  => 'eicon-v-align-top',
					),
					'center'     => array(
						'title' => 'Middle',
						'icon'  => 'eicon-v-align-middle',
					),
					'flex-end'   => array(
						'title' => 'Bottom',
						'icon'  => 'eicon-v-align-bottom',
					),
				),
				'default'   => 'flex-start',
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-track' => 'align-items: {{VALUE}};' ),
				'condition' => array( 'sticky_height[size]!' => 100 ),
			)
		);

		$this->add_control(
			'pin_duration',
			array(
				'label'       => __( 'Scroll Length / Duration (vh)', 'sifency-addons' ),
				'type'        => Controls_Manager::SLIDER,
				'range'       => array(
					'vh' => array(
						'min'  => 100,
						'max'  => 2000,
						'step' => 10,
					),
				),
				'default'     => array(
					'size' => 300,
					'unit' => 'vh',
				),
				'description' => __( 'How long the widget stays pinned. 300vh = 3x screen heights of scrolling. Increase this to see more items before they repeat.', 'sifency-addons' ),
				'selectors'   => array( '{{WRAPPER}} .sifency-scroll-track' => 'height: {{SIZE}}{{UNIT}};' ),
			)
		);

		/* ── Gaps ─────────────────────────────────────────────────────── */
		$this->add_responsive_control(
			'column_gap',
			array(
				'label'     => __( 'Column Gap', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 0,
						'max' => 120,
					),
				),
				'default'   => array(
					'size' => 30,
					'unit' => 'px',
				),
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-wrapper' => 'column-gap: {{SIZE}}{{UNIT}};' ),
				'separator' => 'before',
			)
		);

		$this->add_responsive_control(
			'item_spacing',
			array(
				'label'     => __( 'Vertical Item Spacing', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 0,
						'max' => 120,
					),
				),
				'default'   => array(
					'size' => 30,
					'unit' => 'px',
				),
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-col-part' => 'gap: {{SIZE}}{{UNIT}};' ),
			)
		);

		/* ── Image aspect ratio ───────────────────────────────────────── */
		$this->add_control(
			'item_aspect_ratio',
			array(
				'label'     => __( 'Image Aspect Ratio', 'sifency-addons' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => '4/5',
				'options'   => array(
					'3/4'  => __( 'Portrait (3:4)', 'sifency-addons' ),
					'4/5'  => __( 'Portrait Tall (4:5)', 'sifency-addons' ),
					'1/1'  => __( 'Square (1:1)', 'sifency-addons' ),
					'5/4'  => __( 'Landscape (5:4)', 'sifency-addons' ),
					'4/3'  => __( 'Landscape Wide (4:3)', 'sifency-addons' ),
					'16/9' => __( 'Cinema (16:9)', 'sifency-addons' ),
				),
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-image-wrap' => 'aspect-ratio: {{VALUE}};' ),
				'separator' => 'before',
			)
		);

		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'item_shadow',
				'selector' => '{{WRAPPER}} .sifency-scroll-item',
			)
		);

		/* ── Hover overlay ────────────────────────────────────────────── */
		$this->add_control(
			'overlay_color',
			array(
				'label'     => __( 'Overlay Color (Hover)', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => 'rgba(0,0,0,0.2)', /* Less dark for premium feel */
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-overlay' => 'background-color: {{VALUE}};' ),
				'separator' => 'before',
			)
		);

		/* ── Title ────────────────────────────────────────────────────── */
		$this->add_control(
			'title_color',
			array(
				'label'     => __( 'Title Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-title' => 'color: {{VALUE}};' ),
				'separator' => 'before',
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'title_typography',
				'selector' => '{{WRAPPER}} .sifency-scroll-title',
			)
		);

		/* ── Category ─────────────────────────────────────────────────── */
		$this->add_control(
			'category_color',
			array(
				'label'     => __( 'Category Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-category' => 'color: {{VALUE}};' ),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'category_typography',
				'selector' => '{{WRAPPER}} .sifency-scroll-category',
			)
		);

		$this->add_control(
			'excerpt_color',
			array(
				'label'     => __( 'Excerpt Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-excerpt' => 'color: {{VALUE}};' ),
				'condition' => array( 'show_excerpt' => 'yes' ),
				'separator' => 'before',
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'      => 'excerpt_typography',
				'selector'  => '{{WRAPPER}} .sifency-scroll-excerpt',
				'condition' => array( 'show_excerpt' => 'yes' ),
			)
		);

		$this->add_responsive_control(
			'item_text_align',
			array(
				'label'     => __( 'Alignment', 'sifency-addons' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'left'   => array(
						'title' => 'Left',
						'icon'  => 'eicon-text-align-left',
					),
					'center' => array(
						'title' => 'Center',
						'icon'  => 'eicon-text-align-center',
					),
					'right'  => array(
						'title' => 'Right',
						'icon'  => 'eicon-text-align-right',
					),
				),
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-content' => 'text-align: {{VALUE}};' ),
			)
		);

		$this->end_controls_section();

		/*
		 ================================================================
		 *  BACKGROUND TEXT TAB
		 * ============================================================== */
		$this->start_controls_section(
			'section_bg_text',
			array(
				'label' => __( 'Background Text', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

		$this->add_control(
			'enable_bg_text',
			array(
				'label'        => __( 'Enable Background Text', 'sifency-addons' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => __( 'Yes', 'sifency-addons' ),
				'label_off'    => __( 'No', 'sifency-addons' ),
				'return_value' => 'yes',
				'default'      => 'no',
			)
		);

		$this->add_control(
			'bg_text',
			array(
				'label'     => __( 'Background Text', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXT,
				'default'   => 'PROJECTS',
				'condition' => array( 'enable_bg_text' => 'yes' ),
			)
		);

		$this->add_control(
			'bg_text_layering',
			array(
				'label'     => __( 'Text Layering', 'sifency-addons' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => '0',
				'options'   => array(
					'0'  => __( 'Behind Items', 'sifency-addons' ),
					'10' => __( 'In Front of Items', 'sifency-addons' ),
				),
				'selectors' => array(
					'{{WRAPPER}} .sifency-scroll-bg-text' => 'z-index: {{VALUE}};',
				),
				'condition' => array( 'enable_bg_text' => 'yes' ),
			)
		);

		$this->add_control(
			'start_from_bottom',
			array(
				'label'        => __( 'Columns Enter From Bottom', 'sifency-addons' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => __( 'Yes', 'sifency-addons' ),
				'label_off'    => __( 'No', 'sifency-addons' ),
				'return_value' => 'yes',
				'default'      => 'no',
				'description'  => __( 'Pushes initial columns down by 100vh so they scroll up to reveal the background text initially.', 'sifency-addons' ),
			)
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'section_style_bg_text',
			array(
				'label'     => __( 'Background Text Style', 'sifency-addons' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array( 'enable_bg_text' => 'yes' ),
			)
		);

		$this->add_control(
			'bg_text_color',
			array(
				'label'     => __( 'Text Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-bg-text' => 'color: {{VALUE}};' ),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'bg_text_typography',
				'selector' => '{{WRAPPER}} .sifency-scroll-bg-text',
			)
		);

		$this->add_control(
			'bg_text_blend',
			array(
				'label'     => __( 'Mix Blend Mode', 'sifency-addons' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => 'normal',
				'options'   => array(
					'normal'     => 'Normal',
					'multiply'   => 'Multiply',
					'screen'     => 'Screen',
					'overlay'    => 'Overlay',
					'difference' => 'Difference',
				),
				'selectors' => array( '{{WRAPPER}} .sifency-scroll-bg-text' => 'mix-blend-mode: {{VALUE}};' ),
			)
		);

		$this->end_controls_section();

		/*
		 ================================================================
		 *  ADVANCED / ANIMATION TAB
		 * ============================================================== */
		$this->start_controls_section(
			'section_animation',
			array(
				'label' => __( 'Scroll Behavior', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

		$this->add_control(
			'infinite_loop',
			array(
				'label'        => __( 'Infinite Repeat on Scroll', 'sifency-addons' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => __( 'Yes', 'sifency-addons' ),
				'label_off'    => __( 'No', 'sifency-addons' ),
				'return_value' => 'yes',
				'default'      => 'yes',
				'description'  => __( 'Items repeat seamlessly as you scroll. Recommended for most use-cases.', 'sifency-addons' ),
			)
		);

		$this->add_control(
			'scroll_speed',
			array(
				'label'       => __( 'Scroll Speed', 'sifency-addons' ),
				'type'        => Controls_Manager::SLIDER,
				'range'       => array(
					'px' => array(
						'min'  => 0.2,
						'max'  => 6,
						'step' => 0.1,
					),
				),
				'default'     => array( 'size' => 1.5 ),
				'description' => __( 'How fast the columns move relative to page scroll. Applies equally to ALL directions.', 'sifency-addons' ),
			)
		);

		/* ── Direction pattern ─────────────────────────────────────────── */
		$this->add_control(
			'direction_pattern',
			array(
				'label'     => __( 'Direction Pattern', 'sifency-addons' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => 'alt_up_down',
				'separator' => 'before',
				'options'   => array(
					'alt_up_down' => __( 'Alternating  ↑ ↓ ↑ ↓  (recommended)', 'sifency-addons' ),
					'alt_down_up' => __( 'Alternating  ↓ ↑ ↓ ↑  (flipped)', 'sifency-addons' ),
					'all_up'      => __( 'All Up  ↑ ↑ ↑', 'sifency-addons' ),
					'all_down'    => __( 'All Down  ↓ ↓ ↓', 'sifency-addons' ),
				),
			)
		);

		/* ── Stagger offset ────────────────────────────────────────────── */
		$this->add_control(
			'stagger_offset',
			array(
				'label'       => __( 'Reverse-Column Stagger Offset (%)', 'sifency-addons' ),
				'type'        => Controls_Manager::SLIDER,
				'range'       => array(
					'px' => array(
						'min'  => 0,
						'max'  => 100,
						'step' => 5,
					),
				),
				'default'     => array( 'size' => 50 ),
				'description' => __( 'Shifts the starting frame of down-scrolling columns so columns look staggered at page load. 0 = aligned, 50 = half-cycle offset.', 'sifency-addons' ),
			)
		);

		$this->end_controls_section();
		$this->add_sifency_addons_item_style_controls(
			array(
				'prefix'   => 'item_style',
				'label'    => 'Item Wrapper',
				'selector' => '.sifency-scroll-item',
			)
		);

		$this->add_sifency_addons_master_typography_controls(
			array(
				'prefix'   => 'title_style',
				'label'    => 'Title Style',
				'selector' => '.sifency-scroll-title',
			)
		);

		$this->add_sifency_addons_master_typography_controls(
			array(
				'prefix'   => 'category_style',
				'label'    => 'Category Style',
				'selector' => '.sifency-scroll-category',
			)
		);

		$this->add_sifency_addons_master_typography_controls(
			array(
				'prefix'    => 'excerpt_style',
				'label'     => 'Excerpt Style',
				'selector'  => '.sifency-scroll-excerpt',
				'condition' => array( 'show_excerpt' => 'yes' ),
			)
		);

		$this->add_sifency_addons_image_style_controls(
			array(
				'prefix'   => 'image_style',
				'label'    => 'Image Style',
				'selector' => '.sifency-scroll-image-wrap img',
			)
		);

		$this->add_Sifency_Addons_Animation_Controls();
	}

	protected function render_dom( array $context ) {
		$settings          = $this->get_settings_for_display();
		$animation_manager = new Sifency_Addons_Animation_Manager( $settings );

		$cols_desktop = max( 1, (int) ( $settings['columns_count'] ?? 3 ) );
		$items        = array();
		$data_source  = $settings['data_source'] ?? 'manual';

		if ( 'manual' === $data_source ) {
			$items = $settings['items'] ?? array();
		} else {
			$query_args = $this->get_sifency_addons_query_args();
			if ( ! empty( $query_args ) ) {
				$query = new \WP_Query( $query_args );
				if ( $query->have_posts() ) {
					while ( $query->have_posts() ) {
						$query->the_post();

						// Handle categories
						$categories = get_the_category();
						$cat_list   = array();
						if ( ! empty( $categories ) ) {
							$max_cat = (int) ( $settings['max_categories'] ?? 1 );
							$count   = 0;
							foreach ( $categories as $category ) {
								if ( $count >= $max_cat ) {
									break;
								}
								$cat_list[] = $category->name;
								$count++;
							}
						}

						$items[] = array(
							'image'    => array( 'url' => get_the_post_thumbnail_url( get_the_ID(), 'large' ) ),
							'title'    => get_the_title(),
							'excerpt'  => get_the_excerpt(),
							'category' => implode( ', ', $cat_list ),
							'link'     => array( 'url' => get_permalink() ),
						);
					}
					wp_reset_postdata();
				}
			}
		}

		$speed   = (float) ( $settings['scroll_speed']['size'] ?? 1.5 );
		$loop    = $settings['infinite_loop'] ?? 'yes';
		$pattern = $settings['direction_pattern'] ?? 'alt_up_down';
		$stagger = (float) ( $settings['stagger_offset']['size'] ?? 50 ) / 100;

		if ( empty( $items ) ) {
			return;
		}

		/* Distribute items round-robin across columns */
		$col_data = array_fill( 0, $cols_desktop, array() );
		foreach ( $items as $i => $item ) {
			$col_data[ $i % $cols_desktop ][] = $item;
		}

		$start_bottom = $settings['start_from_bottom'] ?? 'no';

		$wrapper_class = 'sifency-scroll-wrapper';
		if ( 'yes' === $start_bottom ) {
			$wrapper_class .= ' sifency-start-from-bottom';
		}

		$track_classes = array( 'sifency-scroll-track' );
		$track_attrs   = $animation_manager->get_wrapper_attributes( $track_classes );

		$this->add_render_attribute(
			'track',
			array(
				'data-speed' => esc_attr( $speed ),
				'data-loop'  => esc_attr( $loop ),
			)
		);
		?>

		<div <?php echo wp_kses_post( $track_attrs ); ?>
		<?php
        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor widget rendering attributes
		echo wp_kses_post( $this->get_render_attribute_string( 'track' ) );
		?>
		>

			<div class="sifency-scroll-sticky">
				
				<?php if ( 'yes' === ( $settings['enable_bg_text'] ?? 'no' ) && ! empty( $settings['bg_text'] ) ) : ?>
					<div class="sifency-scroll-bg-text">
						<?php echo esc_html( $settings['bg_text'] ); ?>
					</div>
				<?php endif; ?>

				<div class="<?php echo esc_attr( $wrapper_class ); ?>">

					<?php
					foreach ( $col_data as $ci => $col_items ) :

						/* ── Determine column direction ───────────────── */
						switch ( $pattern ) {
							case 'all_up':
								$dir = 'normal';
								break;
							case 'all_down':
								$dir = 'reverse';
								break;
							case 'alt_down_up':
								$dir = ( $ci % 2 === 0 ) ? 'reverse' : 'normal';
								break;
							default: /* alt_up_down */
								$dir = ( $ci % 2 === 0 ) ? 'normal' : 'reverse';
								break;
						}

						/* Reverse columns get the stagger offset, normal start at 0 */
						$offset = ( 'reverse' === $dir ) ? $stagger : 0;

						?>
						<div class="sifency-scroll-column"
							 data-direction="<?php echo esc_attr( $dir ); ?>"
							 data-offset="<?php echo esc_attr( $offset ); ?>">

							<div class="sifency-scroll-col-part">
								<?php
								foreach ( $col_items as $item ) :
									$link_url  = ! empty( $item['link']['url'] ) ? $item['link']['url'] : '';
									$tag       = $link_url ? 'a' : 'div';
									$link_attr = '';
									if ( $link_url ) {
										$link_attr  = ' href="' . esc_url( $link_url ) . '"';
										$link_attr .= ! empty( $item['link']['is_external'] ) ? ' target="_blank" rel="noopener noreferrer"' : '';
										$link_attr .= ! empty( $item['link']['nofollow'] ) ? ' rel="nofollow"' : '';
									}

									$item_classes = array( 'sifency-scroll-item' );
									$item_attrs   = $animation_manager->get_item_attributes( $item_classes );
									?>
									<<?php echo tag_escape( $tag ); ?> <?php echo wp_kses_post( $item_attrs ); ?>
									<?php
                                    // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Pre-escaped HTML attributes
									echo wp_kses_post( $link_attr );
									?>
									>

										<div class="sifency-scroll-image-wrap">
											<?php if ( ! empty( $item['image']['url'] ) ) : ?>
												<img src="<?php echo esc_url( $item['image']['url'] ); ?>"
													 alt="<?php echo esc_attr( $item['title'] ); ?>"
													 loading="lazy"
													 decoding="async">
											<?php endif; ?>
										</div>

										<div class="sifency-scroll-overlay">
											<div class="sifency-scroll-content">
												<?php if ( ! empty( $item['title'] ) ) : ?>
													<h3 class="sifency-scroll-title">
														<?php echo esc_html( $item['title'] ); ?>
													</h3>
												<?php endif; ?>
												<?php if ( ! empty( $item['category'] ) ) : ?>
													<span class="sifency-scroll-category">
														<?php echo esc_html( $item['category'] ); ?>
													</span>
												<?php endif; ?>
												<?php if ( 'yes' === $settings['show_excerpt'] && ! empty( $item['excerpt'] ) ) : ?>
													<div class="sifency-scroll-excerpt">
														<?php echo esc_html( wp_trim_words( $item['excerpt'], $settings['excerpt_length'], '...' ) ); ?>
													</div>
												<?php endif; ?>
											</div>
										</div>

									</<?php echo tag_escape( $tag ); ?>>
								<?php endforeach; ?>
							</div>
							<!-- /.sifency-scroll-col-part -->

						</div>
						<!-- /.sifency-scroll-column -->
					<?php endforeach; ?>

				</div><!-- /.sifency-scroll-wrapper -->
			</div><!-- /.sifency-scroll-sticky -->

		</div><!-- /.sifency-scroll-track -->
		<?php
	}
}
