<?php

namespace Calio\Widgets;

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

use \Elementor\Controls_Manager;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Image_Size;
use \Elementor\Group_Control_Typography;

class PostTimelineWidget extends BaseWidget
{
	protected $page_id;

    public function get_name()
    {
        return 'calio-post-timeline';
    }

    public function get_title()
    {
        return __('Post Timeline', 'calio-addon');
    }

    public function get_icon()
    {
        return 'eicon-time-line';
    }

    public function get_categories(): array
    {
        return parent::get_categories();
    }

    public function get_keywords(): array
    {
        return [
            'post',
            'posts',
            'timeline',
            'post timeline',
            'blog posts',
            'calio',
            'blogger',
        ];
    }

    public function get_style_depends(): array
    {
        return $this->resolve_widget_style_depends('calio-widget-post-timeline');
    }

    public function get_script_depends(): array
    {
        return $this->resolve_widget_script_depends('calio-widget-post-timeline');
    }

    protected function register_controls()
    {
        $this->register_query_controls();
        $this->register_layout_controls();

        $this->start_controls_section(
            'section_post_timeline_links',
            [
                'label' => __('Links', 'calio-addon'),
            ]
        );

        $this->add_control(
            'timeline_link_nofollow',
            [
                'label' => __('No Follow', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Yes', 'calio-addon'),
                'label_off' => __('No', 'calio-addon'),
                'return_value' => 'true',
            ]
        );

        $this->add_control(
            'timeline_link_target_blank',
            [
                'label' => __('Target Blank', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Yes', 'calio-addon'),
                'label_off' => __('No', 'calio-addon'),
                'return_value' => 'true',
            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'eael_section_post_timeline_style',
            [
                'label' => __('Timeline Style', 'calio-addon'),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control(
            'eael_timeline_display_overlay',
            [
                'label'        => __('Show Overlay', 'calio-addon'),
                'type'         => Controls_Manager::SWITCHER,
                'label_on'     => __('Show', 'calio-addon'),
                'label_off'    => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default'      => 'yes',
                'selectors'    => [
                    '{{WRAPPER}} .eael-timeline-post-image' => 'opacity: .6',
                ],
	            'condition'=> [
	            	'eael_dynamic_template_Layout!' => 'card',
	            ]
            ]
        );

        $this->add_control(
            'eael_timeline_overlay_color',
            [
                'label'       => __('Overlay Color', 'calio-addon'),
                'type'        => Controls_Manager::COLOR,
                'description' => __('Leave blank or Clear to use default gradient overlay', 'calio-addon'),
                'default'     => 'linear-gradient(45deg, #3f3f46 0%, #05abe0 100%) repeat scroll 0 0 rgba(0, 0, 0, 0)',
                'selectors'   => [
                    '{{WRAPPER}} .eael-timeline-post-inner' => 'background: {{VALUE}}',
                ],
                'condition'   => [
                    'eael_timeline_display_overlay' => 'yes',
                    'eael_dynamic_template_Layout!' => 'card',
                ],
            ]
        );


        $this->add_control(
            'eael_timeline_bg_color',
            [
                'label'       => __('Background Color', 'calio-addon'),
                'type'        => Controls_Manager::COLOR,
				'default'	  => '#0f172a',
                'selectors'   => [
                    '{{WRAPPER}} .eael-timeline-post-inner' => 'background: {{VALUE}}',
                ],
                'condition'   => [
                    'eael_dynamic_template_Layout' => 'card',
                ],
            ]
        );

	    $this->add_responsive_control(
		    'eael_post_grid_spacing',
		    [
			    'label' => esc_html__('Padding', 'calio-addon'),
			    'type' => Controls_Manager::DIMENSIONS,
			    'size_units' => ['px', '%', 'em'],
			    'selectors' => [
				    '{{WRAPPER}} .eael-timeline-post-inner' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout' => 'card',
			    ],
		    ]
	    );

	    $this->add_control(
		    'eael_post_timeline_border_radius',
		    [
			    'label' => esc_html__('Border Radius', 'calio-addon'),
			    'type' => Controls_Manager::DIMENSIONS,
			    'selectors' => [
				    '{{WRAPPER}} .eael-timeline-post-inner' => 'border-radius: {{TOP}}px {{RIGHT}}px {{BOTTOM}}px {{LEFT}}px;',
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout' => 'card',
			    ],
		    ]
	    );

	    $this->add_group_control(
		    Group_Control_Box_Shadow::get_type(),
		    [
			    'name' => 'eael_post_timeline_box_shadow',
			    'selector' => '{{WRAPPER}} .eael-timeline-post-inner',
			    'condition'   => [
				    'eael_dynamic_template_Layout' => 'card',
			    ],
		    ]
	    );

	    $this->add_control(
		    'eael_post_timeline_content_heading',
		    [
			    'label' => esc_html__('Content', 'calio-addon'),
			    'type' => Controls_Manager::HEADING,
			    'condition'   => [
				    'eael_dynamic_template_Layout' => 'card',
			    ],
			    'separator' => 'before',
		    ]
	    );

	    $this->add_responsive_control(
		    'eael_post_timeline_content_spacing',
		    [
			    'label' => esc_html__('Spacing', 'calio-addon'),
			    'type' => Controls_Manager::DIMENSIONS,
			    'size_units' => ['px', '%', 'em'],
			    'selectors' => [
				    '{{WRAPPER}} .eael-timeline-content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout' => 'card',
			    ],
		    ]
	    );

	    $this->add_control(
		    'eael_post_timeline_image_heading',
		    [
			    'label' => esc_html__('Image', 'calio-addon'),
			    'type' => Controls_Manager::HEADING,
			    'separator' => 'before',
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

	    $this->add_responsive_control(
		    'eael_timeline_image_height',
		    [
			    'label' => esc_html__('Height', 'calio-addon'),
			    'type' => Controls_Manager::SLIDER,
			    'range' => [
				    'px' => [
					    'max' => 500,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .eael-timeline-post-image' => 'height: {{SIZE}}PX;',
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

	    $this->add_control(
		    'eael_timeline_img_border_radius',
		    [
			    'label' => esc_html__('Border Radius', 'calio-addon'),
			    'type' => Controls_Manager::DIMENSIONS,
			    'size_units' => ['px', '%'],
			    'selectors' => [
				    '{{WRAPPER}} .eael-timeline-post-image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

        $this->end_controls_section();

        $this->start_controls_section(
            'eael_section_typography',
            [
                'label' => __('Typography', 'calio-addon'),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control(
            'eael_timeline_title_style',
            [
                'label'     => __('Title', 'calio-addon'),
                'type'      => Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );

        $this->add_control(
            'eael_timeline_title_color',
            [
                'label'     => __('Color', 'calio-addon'),
                'type'      => Controls_Manager::COLOR,
                'default'   => '#fff',
                'selectors' => [
                    '{{WRAPPER}} .eael-timeline-post-title .eael-timeline-post-title-text' => 'color: {{VALUE}};',
                ],

            ]
        );

        $this->add_responsive_control(
            'eael_timeline_title_alignment',
            [
                'label'     => __('Alignment', 'calio-addon'),
                'type'      => Controls_Manager::CHOOSE,
                'options'   => [
                    'left'   => [
                        'title' => __('Left', 'calio-addon'),
                        'icon'  => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => __('Center', 'calio-addon'),
                        'icon'  => 'eicon-text-align-center',
                    ],
                    'right'  => [
                        'title' => __('Right', 'calio-addon'),
                        'icon'  => 'eicon-text-align-right',
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .eael-timeline-post-title .eael-timeline-post-title-text' => 'text-align: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'     => 'eael_timeline_title_typography',
                'label'    => __('Typography', 'calio-addon'),
                'global' => [
                    'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
                ],
                'selector' => '{{WRAPPER}} .eael-timeline-post-title .eael-timeline-post-title-text',
            ]
        );

        $this->add_control(
            'eael_timeline_excerpt_style',
            [
                'label'     => __('Excerpt', 'calio-addon'),
                'type'      => Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );

        $this->add_control(
            'eael_timeline_excerpt_color',
            [
                'label'     => __('Color', 'calio-addon'),
                'type'      => Controls_Manager::COLOR,
                'default'   => '#ffffff',
                'selectors' => [
                    '{{WRAPPER}} .eael-timeline-post-excerpt p' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_excerpt_alignment',
            [
                'label'     => __('Alignment', 'calio-addon'),
                'type'      => Controls_Manager::CHOOSE,
                'options'   => [
                    'left'    => [
                        'title' => __('Left', 'calio-addon'),
                        'icon'  => 'eicon-text-align-left',
                    ],
                    'center'  => [
                        'title' => __('Center', 'calio-addon'),
                        'icon'  => 'eicon-text-align-center',
                    ],
                    'right'   => [
                        'title' => __('Right', 'calio-addon'),
                        'icon'  => 'eicon-text-align-right',
                    ],
                    'justify' => [
                        'title' => __('Justified', 'calio-addon'),
                        'icon'  => 'eicon-text-align-justify',
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .eael-timeline-post-excerpt p' => 'text-align: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'     => 'eael_timeline_excerpt_typography',
                'label'    => __('Typography', 'calio-addon'),
                'global' => [
                    'default' => Global_Typography::TYPOGRAPHY_TEXT,
                ],
                'selector' => '{{WRAPPER}} .eael-timeline-post-excerpt p',
            ]
        );

        $this->end_controls_section();

		// Start Arrow Styling

		$this->start_controls_section(
		    'eael_section_arrow',
		    [
			    'label' => __('Arrow', 'calio-addon'),
			    'tab'   => Controls_Manager::TAB_STYLE,
		    ]
	    );

        $this->add_control(
            'eael_timeline_border_color',
            [
                'label'     => __('Border & Arrow Color', 'calio-addon'),
                'type'      => Controls_Manager::COLOR,
                'default'   => '#dbe7ff',
                'selectors' => [
                    '{{WRAPPER}} .eael-timeline-post-inner'                                          => 'border-color: {{VALUE}};',
                    '{{WRAPPER}} .eael-timeline-post-inner::after'                                   => 'border-left-color: {{VALUE}};',
                    '{{WRAPPER}} .eael-timeline-post:nth-child(2n) .eael-timeline-post-inner::after' => 'border-right-color: {{VALUE}};',
                ],
                'condition'   => [
	                'eael_dynamic_template_Layout' => 'default',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_arrow_color',
            [
                'label'     => __('Arrow / Border Color', 'calio-addon'),
                'type'      => Controls_Manager::COLOR,
				'default'	=> '#2563eb',
                'selectors' => [
                    '{{WRAPPER}} .eael-post-timeline.timeline-layout-card .eael-timeline-post-inner' => 'border-color: {{VALUE}}; --calio-card-connector-color: {{VALUE}};',
                ],
                'condition'   => [
	                'eael_dynamic_template_Layout!' => 'default',
                ],
            ]
        );

		$this->add_responsive_control(
		    'eael_timeline_arrow_size',
		    [
			    'label' => esc_html__('Arrow Head Size', 'calio-addon'),
			    'type' => Controls_Manager::SLIDER,
			    'range' => [
				    'px' => [
					    'min' => 6,
					    'max' => 40,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .eael-post-timeline.timeline-layout-card' => '--calio-card-connector-head: {{SIZE}}px;',
			    ],

			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

		$this->add_responsive_control(
		    'eael_timeline_arrow_line_length',
		    [
			    'label' => esc_html__('Connector Length', 'calio-addon'),
			    'type' => Controls_Manager::SLIDER,
			    'range' => [
				    'px' => [
					    'min' => 8,
					    'max' => 64,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .eael-post-timeline.timeline-layout-card' => '--calio-card-connector-line: {{SIZE}}px;',
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

		$this->add_responsive_control(
		    'eael_timeline_arrow_thickness',
		    [
			    'label' => esc_html__('Connector Thickness', 'calio-addon'),
			    'type' => Controls_Manager::SLIDER,
			    'range' => [
				    'px' => [
					    'min' => 1,
					    'max' => 10,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .eael-post-timeline.timeline-layout-card' => '--calio-card-connector-thickness: {{SIZE}}px;',
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

		$this->add_control(
		    'eael_timeline_connector_style',
		    [
			    'label' => __('Connector Style', 'calio-addon'),
			    'type' => Controls_Manager::CHOOSE,
			    'options' => [
				    'solid' => [
					    'title' => __('Solid', 'calio-addon'),
					    'icon' => 'eicon-minus',
				    ],
				    'dashed' => [
					    'title' => __('Dashed', 'calio-addon'),
					    'icon' => 'eicon-ellipsis-h',
				    ],
				    'glow' => [
					    'title' => __('Glow', 'calio-addon'),
					    'icon' => 'eicon-lightbox',
				    ],
			    ],
			    'default' => 'solid',
			    'toggle' => false,
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

	    $this->add_control(
		    'eael_timeline_arrow_alignment',
		    [
			    'label'     => __('Alignment', 'calio-addon'),
			    'type'      => Controls_Manager::CHOOSE,
			    'options'   => [
				    'top'       => [
					    'title' => __( 'Top', 'calio-addon' ),
					    'icon'  => 'eicon-v-align-top',
				    ],
				    'middle'    => [
					    'title' => __( 'Middle', 'calio-addon' ),
					    'icon'  => 'eicon-v-align-middle',
				    ],
				    'bottom'    => [
					    'title' => __( 'Bottom', 'calio-addon' ),
					    'icon'  => 'eicon-v-align-bottom',
				    ],
			    ],
			    'default' => 'top',
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

		$this->add_responsive_control(
		    'eael_timeline_connector_offset',
		    [
			    'label' => esc_html__('Connector Offset', 'calio-addon'),
			    'type' => Controls_Manager::SLIDER,
			    'size_units' => ['px'],
			    'range' => [
				    'px' => [
					    'min' => -80,
					    'max' => 80,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .eael-post-timeline.timeline-layout-card' => '--calio-card-anchor-shift: {{SIZE}}px;',
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

		$this->add_control(
		    'eael_timeline_arrow_hover_effect',
		    [
			    'label' => __('Arrow Hover Effect', 'calio-addon'),
			    'type' => Controls_Manager::SELECT,
			    'default' => 'slide',
			    'options' => [
				    'none' => __('None', 'calio-addon'),
				    'slide' => __('Slide', 'calio-addon'),
				    'pulse' => __('Pulse', 'calio-addon'),
				    'glow' => __('Glow', 'calio-addon'),
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
			    ],
		    ]
	    );

		$this->add_responsive_control(
		    'eael_timeline_arrow_hover_distance',
		    [
			    'label' => esc_html__('Hover Distance', 'calio-addon'),
			    'type' => Controls_Manager::SLIDER,
			    'size_units' => ['px'],
			    'range' => [
				    'px' => [
					    'min' => 0,
					    'max' => 24,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .eael-post-timeline.timeline-layout-card' => '--calio-card-hover-shift-distance: {{SIZE}}px;',
			    ],
			    'condition'   => [
				    'eael_dynamic_template_Layout!' => 'default',
				    'eael_timeline_arrow_hover_effect!' => 'none',
			    ],
		    ]
	    );

        $this->end_controls_section();

        // Start Time Styling

		$this->start_controls_section(
		    'eael_section_time',
		    [
			    'label' => __('Time', 'calio-addon'),
			    'tab'   => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'timeline_date_display_mode' => 'bubble',
                ],
		    ]
	    );

	    $this->add_control(
		    'eael_timeline_date_background_color',
		    [
			    'label'     => __('Date Background Color', 'calio-addon'),
			    'type'      => Controls_Manager::COLOR,
			    'default'   => 'rgba(0, 0, 0, 0.7)',
			    'selectors' => [
				    '{{WRAPPER}} .eael-timeline-post time'         => 'background-color: {{VALUE}};',
				    '{{WRAPPER}} .eael-timeline-post time::before' => 'border-bottom-color: {{VALUE}};',
			    ],

		    ]
	    );

	    $this->add_control(
		    'eael_timeline_date_color',
		    [
			    'label'     => __('Date Text Color', 'calio-addon'),
			    'type'      => Controls_Manager::COLOR,
			    'default'   => '#fff',
			    'selectors' => [
				    '{{WRAPPER}} .eael-timeline-post time' => 'color: {{VALUE}};',
			    ],

		    ]
	    );

	    $this->add_group_control(
		    Group_Control_Typography::get_type(),
		    [
			    'name'     => 'eael_timeline_time_typography',
			    'label'    => __('Typography', 'calio-addon'),
			    'selector' => '{{WRAPPER}} time',
		    ]
	    );

	    $this->add_control(
		    'eael_timeline_time_padding',
		    [
			    'label' => esc_html__('Padding', 'calio-addon'),
			    'type' => Controls_Manager::DIMENSIONS,
			    'size_units' => ['px', '%'],
			    'selectors' => [
				    '{{WRAPPER}} time' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
			    ],
		    ]
	    );

	    $this->add_control(
		    'eael_timeline_time_border_radius',
		    [
			    'label' => esc_html__('Border Radius', 'calio-addon'),
			    'type' => Controls_Manager::DIMENSIONS,
			    'size_units' => ['px', '%'],
			    'selectors' => [
				    '{{WRAPPER}} time' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
			    ],
		    ]
	    );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'eael_timeline_time_border',
                'selector' => '{{WRAPPER}} .eael-timeline-post time',
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'eael_timeline_time_shadow',
                'selector' => '{{WRAPPER}} .eael-timeline-post time',
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_time_min_width',
            [
                'label' => esc_html__('Minimum Width', 'calio-addon'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 240,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .eael-timeline-post time' => 'min-width: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_time_offset_x',
            [
                'label' => esc_html__('Horizontal Offset', 'calio-addon'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range' => [
                    'px' => [
                        'min' => -80,
                        'max' => 80,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-widget' => '--calio-timeline-date-offset-x: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_time_offset_y',
            [
                'label' => esc_html__('Vertical Offset', 'calio-addon'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range' => [
                    'px' => [
                        'min' => -80,
                        'max' => 80,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-widget' => '--calio-timeline-date-offset-y: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'eael_section_meta_style',
            [
                'label' => __('Meta', 'calio-addon'),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control(
            'eael_timeline_meta_color',
            [
                'label' => __('Text Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_meta_item_bg',
            [
                'label' => __('Item Background', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta__item' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_meta_term_bg',
            [
                'label' => __('Category Background', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta__item.is-term' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'eael_timeline_meta_typography',
                'selector' => '{{WRAPPER}} .calio-post-timeline-meta',
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_meta_gap',
            [
                'label' => __('Item Gap', 'calio-addon'),
                'type' => Controls_Manager::SLIDER,
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 30,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta' => '--calio-timeline-meta-gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_meta_item_color',
            [
                'label' => __('Item Text Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta__item' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_meta_item_border_color',
            [
                'label' => __('Item Border Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta__item' => 'border-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_meta_term_color',
            [
                'label' => __('Taxonomy Text Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta__item.is-term' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_meta_term_border_color',
            [
                'label' => __('Taxonomy Border Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta__item.is-term' => 'border-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_meta_item_padding',
            [
                'label' => __('Item Padding', 'calio-addon'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta__item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_meta_item_radius',
            [
                'label' => __('Item Radius', 'calio-addon'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta__item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_meta_spacing',
            [
                'label' => __('Row Spacing', 'calio-addon'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 40,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-meta' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                    '{{WRAPPER}} .calio-post-timeline-meta[data-position="after_excerpt"]' => 'margin-top: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_section();

	    $this->start_controls_section(
		    'eael_section_line',
		    [
			    'label' => __('Line & Bullet', 'calio-addon'),
			    'tab'   => Controls_Manager::TAB_STYLE,
		    ]
	    );

	    $this->add_control(
		    'eael_section_post_timeline_line_heading',
		    [
			    'label'      => __('Line', 'calio-addon'),
			    'type'       => Controls_Manager::HEADING,
			    'separator' => 'before',
		    ]
	    );

	    $this->add_control(
		    'eael_section_post_timeline_line_size',
		    [
			    'label'      => __('Line Width', 'calio-addon'),
			    'type'       => Controls_Manager::SLIDER,
			    'size_units' => ['px', '%'],
			    'range'      => [
				    'px' => [
					    'min'  => 0,
					    'max'  => 20,
					    'step' => 1,
				    ],
			    ],
			    'selectors'  => [
				    '{{WRAPPER}} .calio-post-timeline-widget' => '--calio-timeline-line-width: {{SIZE}}{{UNIT}};',
			    ],
		    ]
	    );
	    $this->add_control(
		    'eael_section_post_timeline_line_position_from_right',
		    [
			    'label'      => __('Line Position From Right', 'calio-addon'),
			    'type'       => Controls_Manager::SLIDER,
			    'size_units' => ['px'],
			    'range'      => [
				    'px' => [
					    'min'  => 0,
					    'max'  => 20,
					    'step' => 1,
				    ],
			    ],
			    'selectors'  => [
				    '{{WRAPPER}} .eael-timeline-post:after' => 'right: -{{SIZE}}{{UNIT}};',
			    ],
			    'condition'=> [
				    'eael_dynamic_template_Layout!' => 'card',
			    ]
		    ]
	    );

	    $this->add_control(
		    'eael_section_post_timeline_bullet_size',
		    [
			    'label'      => __('Bullet Size', 'calio-addon'),
			    'type'       => Controls_Manager::SLIDER,
			    'size_units' => ['px', '%'],
			    'range'      => [
				    'px' => [
					    'min'  => 0,
					    'max'  => 100,
					    'step' => 1,
				    ],
			    ],
			    'selectors'  => [
				    '{{WRAPPER}} .eael-timeline-bullet' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
			    ],
		    ]
	    );
	    $this->add_control(
		    'eael_section_post_timeline_bullet_position_from_left',
		    [
			    'label'      => __('Left-sided Bullet Positon', 'calio-addon'),
			    'type'       => Controls_Manager::SLIDER,
			    'size_units' => ['px'],
			    'range'      => [
				    'px' => [
					    'min'  => 0,
					    'max'  => 50,
					    'step' => 1,
				    ],
			    ],
			    'selectors'  => [
				    '{{WRAPPER}} .eael-timeline-bullet' => 'right: -{{SIZE}}{{UNIT}};',
			    ],
			    'condition'=> [
				    'eael_dynamic_template_Layout!' => 'card',
			    ]
		    ]
	    );
	    $this->add_control(
		    'eael_section_post_timeline_bullet_position_from_right',
		    [
			    'label'      => __('Right-sided Bullet Position', 'calio-addon'),
			    'type'       => Controls_Manager::SLIDER,
			    'size_units' => ['px'],
			    'range'      => [
				    'px' => [
					    'min'  => 0,
					    'max'  => 50,
					    'step' => 1,
				    ],
			    ],
			    'selectors'  => [
				    '{{WRAPPER}} .eael-timeline-post:nth-child(2n) .eael-timeline-bullet' => 'left: -{{SIZE}}{{UNIT}};',
			    ],
			    'condition'=> [
				    'eael_dynamic_template_Layout!' => 'card',
			    ]
		    ]
	    );

	    $this->add_control(
		    'eael_timeline_bullet_color',
		    [
			    'label'     => __('Timeline Bullet Color', 'calio-addon'),
			    'type'      => Controls_Manager::COLOR,
			    'default'   => '#2563eb',
			    'selectors' => [
				    '{{WRAPPER}} .eael-timeline-bullet' => 'background-color: {{VALUE}};',
			    ],

		    ]
	    );

	    $this->add_control(
		    'eael_timeline_bullet_border_color',
		    [
			    'label'     => __('Timeline Bullet Border Color', 'calio-addon'),
			    'type'      => Controls_Manager::COLOR,
			    'default'   => '#fff',
			    'selectors' => [
				    '{{WRAPPER}} .eael-timeline-bullet' => 'border-color: {{VALUE}};',
			    ],

		    ]
	    );

		$this->add_control(
		    'eael_timeline_bullet_effect',
		    [
			    'label' => __('Bullet Effect', 'calio-addon'),
			    'type' => Controls_Manager::SELECT,
			    'default' => 'none',
			    'options' => [
				    'none' => __('None', 'calio-addon'),
				    'glow' => __('Glow', 'calio-addon'),
				    'pulse' => __('Pulse', 'calio-addon'),
				    'blink' => __('Blink', 'calio-addon'),
				    'ripple' => __('Ripple', 'calio-addon'),
			    ],
		    ]
	    );

		$this->add_control(
		    'eael_timeline_bullet_effect_color',
		    [
			    'label' => __('Bullet Effect Color', 'calio-addon'),
			    'type' => Controls_Manager::COLOR,
			    'default' => 'rgba(37, 99, 235, 0.45)',
			    'selectors' => [
				    '{{WRAPPER}} .calio-post-timeline-widget' => '--calio-bullet-effect-color: {{VALUE}};',
			    ],
			    'condition' => [
				    'eael_timeline_bullet_effect!' => 'none',
			    ],
		    ]
	    );

		$this->add_responsive_control(
		    'eael_timeline_bullet_effect_size',
		    [
			    'label' => esc_html__('Bullet Effect Size', 'calio-addon'),
			    'type' => Controls_Manager::SLIDER,
			    'size_units' => ['px'],
			    'range' => [
				    'px' => [
					    'min' => 4,
					    'max' => 40,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .calio-post-timeline-widget' => '--calio-bullet-effect-size: {{SIZE}}px;',
			    ],
			    'condition' => [
				    'eael_timeline_bullet_effect!' => 'none',
			    ],
		    ]
	    );

		$this->add_responsive_control(
		    'eael_timeline_bullet_effect_speed',
		    [
			    'label' => esc_html__('Bullet Effect Speed', 'calio-addon'),
			    'type' => Controls_Manager::SLIDER,
			    'size_units' => ['s'],
			    'range' => [
				    's' => [
					    'min' => 0.4,
					    'max' => 4,
					    'step' => 0.1,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .calio-post-timeline-widget' => '--calio-bullet-effect-speed: {{SIZE}}s;',
			    ],
			    'condition' => [
				    'eael_timeline_bullet_effect!' => 'none',
			    ],
		    ]
	    );

	    $this->add_control(
		    'eael_timeline_vertical_line_color',
		    [
			    'label'     => __('Timeline Vertical Line Color', 'calio-addon'),
			    'type'      => Controls_Manager::COLOR,
			    'default'   => 'rgba(37, 99, 235, .18)',
			    'selectors' => [
				    '{{WRAPPER}} .calio-post-timeline-widget' => '--calio-timeline-line: {{VALUE}};',
			    ],

		    ]
	    );

        $this->end_controls_section();

        $this->register_badge_style_controls();
        $this->register_read_more_style_controls();
        $this->register_load_more_button_style_controls();
    }

    private function register_query_controls(): void
    {
        $postTypes = PostTimelineHelper::get_post_types();
        $postTypes['by_id'] = __('Manual Selection', 'calio-addon');
        $postTypes['source_dynamic'] = __('Dynamic', 'calio-addon');
        $taxonomies = get_taxonomies([], 'objects');

        $this->start_controls_section(
            'eael_section_post__filters',
            [
                'label' => __('Query', 'calio-addon'),
            ]
        );

        $this->add_control(
            'post_type',
            [
                'label' => __('Source', 'calio-addon'),
                'type' => Controls_Manager::SELECT,
                'options' => $postTypes,
                'default' => 'post',
            ]
        );

        $this->add_control(
            'eael_global_dynamic_source_warning_text',
            [
                'type' => Controls_Manager::RAW_HTML,
                'raw' => __('This option works dynamically on archive and search contexts.', 'calio-addon'),
                'content_classes' => 'eael-warning',
                'condition' => [
                    'post_type' => 'source_dynamic',
                ],
            ]
        );

        $this->add_control(
            'posts_ids',
            [
                'label' => __('Search & Select', 'calio-addon'),
                'type' => Controls_Manager::SELECT2,
                'options' => PostTimelineHelper::get_post_list(),
                'label_block' => true,
                'multiple' => true,
                'description' => __('Pick specific posts and optionally keep their manual order.', 'calio-addon'),
                'condition' => [
                    'post_type' => 'by_id',
                ],
            ]
        );

        $this->add_control(
            'by_id_order_mode',
            [
                'label' => __('Manual Selection Order', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'manual' => [
                        'title' => __('Keep Selected Order', 'calio-addon'),
                        'icon' => 'eicon-editor-list-ul',
                    ],
                    'query' => [
                        'title' => __('Use Query Sorting', 'calio-addon'),
                        'icon' => 'eicon-sort-amount-up',
                    ],
                ],
                'default' => 'manual',
                'toggle' => false,
                'condition' => [
                    'post_type' => 'by_id',
                ],
            ]
        );

        $this->add_control(
            'authors',
            [
                'label' => __('Author', 'calio-addon'),
                'label_block' => true,
                'type' => Controls_Manager::SELECT2,
                'multiple' => true,
                'default' => [],
                'options' => PostTimelineHelper::get_authors_list(),
                'condition' => [
                    'post_type!' => ['by_id', 'source_dynamic'],
                ],
            ]
        );

        foreach ($taxonomies as $taxonomy => $object) {
            if (empty($object->object_type)) {
                continue;
            }

            $eligibleTypes = array_values(array_intersect((array) $object->object_type, array_keys($postTypes)));
            if (empty($eligibleTypes)) {
                continue;
            }

            $this->add_control(
                $taxonomy . '_ids',
                [
                    'label' => $object->label,
                    'type' => Controls_Manager::SELECT2,
                    'label_block' => true,
                    'multiple' => true,
                    'options' => PostTimelineHelper::get_terms_list($taxonomy),
                    'condition' => [
                        'post_type' => $eligibleTypes,
                    ],
                ]
            );
        }

        $this->add_control(
            'tax_query_relation',
            [
                'label' => esc_html__('Taxonomy Query Relation', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'AND' => [
                        'title' => esc_html__('AND', 'calio-addon'),
                        'text' => 'AND',
                    ],
                    'OR' => [
                        'title' => esc_html__('OR', 'calio-addon'),
                        'text' => 'OR',
                    ],
                ],
                'default' => 'AND',
                'toggle' => false,
                'condition' => [
                    'post_type!' => ['by_id', 'source_dynamic', 'page'],
                ],
            ]
        );

        $this->add_control(
            'post__not_in',
            [
                'label' => __('Exclude', 'calio-addon'),
                'type' => Controls_Manager::SELECT2,
                'label_block' => true,
                'multiple' => true,
                'options' => PostTimelineHelper::get_post_list(),
                'description' => __('Hide specific posts from the result set without changing the source type.', 'calio-addon'),
                'condition' => [
                    'post_type!' => ['by_id', 'source_dynamic'],
                ],
            ]
        );

        $this->add_control(
            'ignore_sticky_posts',
            [
                'label' => __('Ignore Sticky Posts', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Yes', 'calio-addon'),
                'label_off' => esc_html__('No', 'calio-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [
                    'post_type!' => ['by_id', 'source_dynamic'],
                ],
            ]
        );

        $this->add_control(
            'posts_per_page',
            [
                'label' => __('Posts Per Page', 'calio-addon'),
                'type' => Controls_Manager::NUMBER,
                'default' => 4,
                'min' => 1,
                'description' => __('Controls the first visible batch and the Ajax batch size for Load More.', 'calio-addon'),
            ]
        );

        $this->add_control(
            'offset',
            [
                'label' => __('Offset', 'calio-addon'),
                'type' => Controls_Manager::NUMBER,
                'default' => 0,
                'condition' => [
                    'orderby!' => 'rand',
                ],
            ]
        );

        $this->add_control(
            'orderby',
            [
                'label' => __('Order By', 'calio-addon'),
                'type' => Controls_Manager::SELECT,
                'options' => PostTimelineHelper::get_post_orderby_options(),
                'default' => 'date',
            ]
        );

        $this->add_control(
            'meta_key',
            [
                'label' => __('Meta Key', 'calio-addon'),
                'type' => Controls_Manager::TEXT,
                'placeholder' => __('_event_start_date', 'calio-addon'),
                'description' => __('Enter the custom field key to sort by, for example `_event_start_date` or `custom_price`.', 'calio-addon'),
                'condition' => [
                    'orderby' => 'meta_value',
                ],
            ]
        );

        $this->add_control(
            'meta_sort_notice',
            [
                'type' => Controls_Manager::RAW_HTML,
                'raw' => __('Custom field sorting works best when the field stores one consistent value type across all posts.', 'calio-addon'),
                'content_classes' => 'elementor-descriptor',
                'condition' => [
                    'orderby' => 'meta_value',
                ],
            ]
        );

        $this->add_control(
            'meta_type',
            [
                'label' => __('Meta Value Type', 'calio-addon'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'CHAR' => __('Character', 'calio-addon'),
                    'NUMERIC' => __('Numeric', 'calio-addon'),
                    'DATE' => __('Date', 'calio-addon'),
                    'DATETIME' => __('DateTime', 'calio-addon'),
                ],
                'default' => 'CHAR',
                'description' => __('Choose the stored field type so WordPress can sort text, numbers, dates, and datetimes correctly.', 'calio-addon'),
                'condition' => [
                    'orderby' => 'meta_value',
                ],
            ]
        );

        $this->add_control(
            'order',
            [
                'label' => __('Order', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'asc' => [
                        'title' => esc_html__('Ascending', 'calio-addon'),
                        'icon' => 'fas fa-sort-amount-up-alt',
                    ],
                    'desc' => [
                        'title' => esc_html__('Descending', 'calio-addon'),
                        'icon' => 'fas fa-sort-amount-down',
                    ],
                ],
                'default' => 'desc',
                'toggle' => false,
            ]
        );

        $this->end_controls_section();
    }

    private function register_layout_controls(): void
    {
        $layoutChoices = $this->get_layout_choices();

        $this->start_controls_section(
            'eael_section_post_timeline_layout',
            [
                'label' => __('Layout Settings', 'calio-addon'),
            ]
        );

        $this->add_control(
            'eael_dynamic_template_Layout',
            [
                'label' => esc_html__('Template Layout', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => $layoutChoices,
                'default' => 'default',
                'label_block' => true,
                'toggle' => false,
                'image_choose' => true,
            ]
        );

        $this->add_control(
            'layout_preview_default',
            [
                'type' => Controls_Manager::RAW_HTML,
                'raw' => $this->get_layout_preview_markup('default', __('Default Layout', 'calio-addon')),
                'content_classes' => 'elementor-descriptor',
                'condition' => [
                    'eael_dynamic_template_Layout' => 'default',
                ],
            ]
        );

        $this->add_control(
            'layout_preview_card',
            [
                'type' => Controls_Manager::RAW_HTML,
                'raw' => $this->get_layout_preview_markup('card', __('Card Layout', 'calio-addon')),
                'content_classes' => 'elementor-descriptor',
                'condition' => [
                    'eael_dynamic_template_Layout' => 'card',
                ],
            ]
        );

        $this->add_control(
            'show_load_more',
            [
                'label' => esc_html__('Load More', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'no' => [
                        'title' => esc_html__('Disable', 'calio-addon'),
                        'icon' => 'eicon-ban',
                    ],
                    'yes' => [
                        'title' => esc_html__('Button', 'calio-addon'),
                        'icon' => 'eicon-button',
                    ],
                    'infinity' => [
                        'title' => esc_html__('Infinity Scroll', 'calio-addon'),
                        'icon' => 'eicon-image-box',
                    ],
                ],
                'default' => 'no',
                'separator' => 'before',
                'toggle' => false,
            ]
        );

        $this->add_control(
            'load_more_infinityscroll_offset',
            [
                'label' => esc_html__('Scroll Offset (px)', 'calio-addon'),
                'type' => Controls_Manager::NUMBER,
                'default' => -200,
                'description' => esc_html__('Set when the next items should load before the viewport ends.', 'calio-addon'),
                'condition' => [
                    'show_load_more' => 'infinity',
                ],
            ]
        );

        $this->add_control(
            'show_load_more_text',
            [
                'label' => esc_html__('Label Text', 'calio-addon'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Load More', 'calio-addon'),
                'condition' => [
                    'show_load_more' => ['yes', '1', 'true', 'infinity'],
                ],
            ]
        );

        $this->add_control(
            'load_more_loading_text',
            [
                'label' => esc_html__('Loading Text', 'calio-addon'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Loading Posts...', 'calio-addon'),
                'condition' => [
                    'show_load_more' => ['yes', '1', 'true', 'infinity'],
                ],
            ]
        );

        $this->add_control(
            'load_more_secondary_text',
            [
                'label' => esc_html__('Secondary Text', 'calio-addon'),
                'type' => Controls_Manager::TEXT,
                'placeholder' => esc_html__('Adds a small helper line under the label.', 'calio-addon'),
                'condition' => [
                    'show_load_more' => ['yes', '1', 'true', 'infinity'],
                ],
            ]
        );

        $this->add_control(
            'load_more_button_preset',
            [
                'label' => esc_html__('Button Preset', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'solid' => [
                        'title' => esc_html__('Solid', 'calio-addon'),
                        'icon' => 'eicon-button',
                    ],
                    'soft' => [
                        'title' => esc_html__('Soft', 'calio-addon'),
                        'icon' => 'eicon-lightbox',
                    ],
                    'outline' => [
                        'title' => esc_html__('Outline', 'calio-addon'),
                        'icon' => 'eicon-divider-shape',
                    ],
                    'glass' => [
                        'title' => esc_html__('Glass', 'calio-addon'),
                        'icon' => 'eicon-gallery-grid',
                    ],
                ],
                'default' => 'solid',
                'toggle' => false,
                'condition' => [
                    'show_load_more' => ['yes', '1', 'true', 'infinity'],
                ],
            ]
        );

        $this->add_control(
            'load_more_button_size',
            [
                'label' => esc_html__('Button Size', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'sm' => [
                        'title' => esc_html__('Small', 'calio-addon'),
                        'icon' => 'eicon-editor-list-ul',
                    ],
                    'md' => [
                        'title' => esc_html__('Medium', 'calio-addon'),
                        'icon' => 'eicon-ellipsis-h',
                    ],
                    'lg' => [
                        'title' => esc_html__('Large', 'calio-addon'),
                        'icon' => 'eicon-editor-list-ol',
                    ],
                ],
                'default' => 'md',
                'toggle' => false,
                'condition' => [
                    'show_load_more' => ['yes', '1', 'true', 'infinity'],
                ],
            ]
        );

        $this->add_control(
            'load_more_button_width',
            [
                'label' => esc_html__('Button Width', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'auto' => [
                        'title' => esc_html__('Auto', 'calio-addon'),
                        'icon' => 'eicon-h-align-left',
                    ],
                    'full' => [
                        'title' => esc_html__('Full Width', 'calio-addon'),
                        'icon' => 'eicon-h-align-stretch',
                    ],
                ],
                'default' => 'auto',
                'toggle' => false,
                'condition' => [
                    'show_load_more' => ['yes', '1', 'true', 'infinity'],
                ],
            ]
        );

        $this->add_control(
            'load_more_icon',
            [
                'label' => esc_html__('Button Icon', 'calio-addon'),
                'type' => Controls_Manager::ICONS,
                'default' => [
                    'value' => 'fas fa-arrow-down',
                    'library' => 'fa-solid',
                ],
                'skin' => 'inline',
                'condition' => [
                    'show_load_more' => ['yes', '1', 'true', 'infinity'],
                ],
            ]
        );

        $this->add_control(
            'load_more_icon_position',
            [
                'label' => esc_html__('Icon Position', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Before', 'calio-addon'),
                        'icon' => 'eicon-h-align-left',
                    ],
                    'right' => [
                        'title' => esc_html__('After', 'calio-addon'),
                        'icon' => 'eicon-h-align-right',
                    ],
                ],
                'default' => 'left',
                'toggle' => false,
                'condition' => [
                    'show_load_more' => ['yes', '1', 'true', 'infinity'],
                ],
            ]
        );

        $this->add_control(
            'eael_show_image',
            [
                'label' => __('Show Image', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->add_group_control(
            Group_Control_Image_Size::get_type(),
            [
                'name' => 'image',
                // Elementor image-size control option, not a WP_Query exclusion parameter.
                // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
                'exclude' => ['custom'],
                'default' => 'medium',
                'condition' => [
                    'eael_show_image' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'eael_show_fallback_img_all',
            [
                'label' => __('Fallback Image', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => '',
                'condition' => [
                    'eael_show_image' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'eael_post_carousel_fallback_img_all',
            [
                'label' => __('Image', 'calio-addon'),
                'type' => Controls_Manager::MEDIA,
                'condition' => [
                    'eael_show_fallback_img_all' => 'yes',
                    'eael_show_image' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'eael_show_title',
            [
                'label' => __('Show Title', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->add_control(
            'title_tag',
            [
                'label' => __('Title Tag', 'calio-addon'),
                'label_block' => true,
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'h1' => ['title' => esc_html__('H1', 'calio-addon'), 'icon' => 'eicon-editor-h1'],
                    'h2' => ['title' => esc_html__('H2', 'calio-addon'), 'icon' => 'eicon-editor-h2'],
                    'h3' => ['title' => esc_html__('H3', 'calio-addon'), 'icon' => 'eicon-editor-h3'],
                    'h4' => ['title' => esc_html__('H4', 'calio-addon'), 'icon' => 'eicon-editor-h4'],
                    'h5' => ['title' => esc_html__('H5', 'calio-addon'), 'icon' => 'eicon-editor-h5'],
                    'h6' => ['title' => esc_html__('H6', 'calio-addon'), 'icon' => 'eicon-editor-h6'],
                    'div' => ['title' => esc_html__('Div', 'calio-addon'), 'text' => 'div'],
                    'span' => ['title' => esc_html__('Span', 'calio-addon'), 'text' => 'span'],
                    'p' => ['title' => esc_html__('P', 'calio-addon'), 'text' => 'P'],
                ],
                'default' => 'h2',
                'toggle' => false,
                'condition' => [
                    'eael_show_title' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'eael_show_excerpt',
            [
                'label' => __('Show Excerpt', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->add_control(
            'eael_excerpt_length',
            [
                'label' => __('Excerpt Words', 'calio-addon'),
                'type' => Controls_Manager::NUMBER,
                'default' => 10,
                'condition' => [
                    'eael_show_excerpt' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'excerpt_expanison_indicator',
            [
                'label' => esc_html__('Expansion Indicator', 'calio-addon'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('...', 'calio-addon'),
                'condition' => [
                    'eael_show_excerpt' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'timeline_date_display_mode',
            [
                'label' => __('Date Display', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'bubble' => [
                        'title' => __('Bubble', 'calio-addon'),
                        'icon' => 'eicon-clock-o',
                    ],
                    'inline' => [
                        'title' => __('Inline Meta', 'calio-addon'),
                        'icon' => 'eicon-post-info',
                    ],
                    'hide' => [
                        'title' => __('Hide', 'calio-addon'),
                        'icon' => 'eicon-ban',
                    ],
                ],
                'default' => 'bubble',
                'separator' => 'before',
                'toggle' => false,
            ]
        );

        $this->add_control(
            'timeline_date_source',
            [
                'label' => __('Date Source', 'calio-addon'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'published' => __('Published Date', 'calio-addon'),
                    'modified' => __('Modified Date', 'calio-addon'),
                ],
                'default' => 'published',
                'condition' => [
                    'timeline_date_display_mode!' => 'hide',
                ],
            ]
        );

        $this->add_control(
            'timeline_date_format_mode',
            [
                'label' => __('Date Format', 'calio-addon'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'default' => __('WordPress Default', 'calio-addon'),
                    'relative' => __('Relative Time', 'calio-addon'),
                    'custom' => __('Custom Format', 'calio-addon'),
                ],
                'default' => 'default',
                'condition' => [
                    'timeline_date_display_mode!' => 'hide',
                ],
            ]
        );

        $this->add_control(
            'timeline_custom_date_format',
            [
                'label' => __('Custom Date Format', 'calio-addon'),
                'type' => Controls_Manager::TEXT,
                'placeholder' => 'M j, Y',
                'description' => __('Uses standard WordPress/PHP date format tokens.', 'calio-addon'),
                'condition' => [
                    'timeline_date_display_mode!' => 'hide',
                    'timeline_date_format_mode' => 'custom',
                ],
            ]
        );

        $this->add_control(
            'timeline_date_reveal',
            [
                'label' => __('Date Bubble Visibility', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'hover' => [
                        'title' => __('On Hover', 'calio-addon'),
                        'icon' => 'eicon-preview-medium',
                    ],
                    'always' => [
                        'title' => __('Always', 'calio-addon'),
                        'icon' => 'eicon-eye',
                    ],
                ],
                'default' => 'hover',
                'toggle' => false,
                'condition' => [
                    'timeline_date_display_mode' => 'bubble',
                ],
            ]
        );

        $this->add_control(
            'eael_show_meta',
            [
                'label' => __('Show Meta', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
                'separator' => 'before',
            ]
        );

        $this->add_control(
            'meta_position',
            [
                'label' => __('Meta Position', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'before_title' => [
                        'title' => __('Above Title', 'calio-addon'),
                        'icon' => 'eicon-v-align-top',
                    ],
                    'after_excerpt' => [
                        'title' => __('Below Excerpt', 'calio-addon'),
                        'icon' => 'eicon-v-align-bottom',
                    ],
                ],
                'default' => 'before_title',
                'toggle' => false,
                'condition' => [
                    'eael_show_meta' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'eael_show_author',
            [
                'label' => __('Show Author', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [
                    'eael_show_meta' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'eael_show_categories',
            [
                'label' => __('Show Categories', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [
                    'eael_show_meta' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'eael_show_comments',
            [
                'label' => __('Show Comments', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => '',
                'condition' => [
                    'eael_show_meta' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'taxonomy_skin',
            [
                'label' => __('Taxonomy Skin', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'soft' => [
                        'title' => __('Soft', 'calio-addon'),
                        'icon' => 'eicon-lightbox',
                    ],
                    'solid' => [
                        'title' => __('Solid', 'calio-addon'),
                        'icon' => 'eicon-button',
                    ],
                    'outline' => [
                        'title' => __('Outline', 'calio-addon'),
                        'icon' => 'eicon-divider-shape',
                    ],
                    'underline' => [
                        'title' => __('Underline', 'calio-addon'),
                        'icon' => 'eicon-underline',
                    ],
                ],
                'default' => 'soft',
                'toggle' => false,
                'condition' => [
                    'eael_show_meta' => 'yes',
                    'eael_show_categories' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'show_badge',
            [
                'label' => __('Show Badge', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => '',
                'separator' => 'before',
            ]
        );

        $this->add_control(
            'badge_source',
            [
                'label' => __('Badge Source', 'calio-addon'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'taxonomy' => __('Primary Taxonomy', 'calio-addon'),
                    'post_type' => __('Post Type', 'calio-addon'),
                    'custom' => __('Custom Text', 'calio-addon'),
                ],
                'default' => 'taxonomy',
                'condition' => [
                    'show_badge' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'badge_custom_text',
            [
                'label' => __('Badge Text', 'calio-addon'),
                'type' => Controls_Manager::TEXT,
                'placeholder' => __('Featured', 'calio-addon'),
                'condition' => [
                    'show_badge' => 'yes',
                    'badge_source' => 'custom',
                ],
            ]
        );

        $this->add_control(
            'badge_skin',
            [
                'label' => __('Badge Preset', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'soft' => [
                        'title' => __('Soft', 'calio-addon'),
                        'icon' => 'eicon-lightbox',
                    ],
                    'solid' => [
                        'title' => __('Solid', 'calio-addon'),
                        'icon' => 'eicon-button',
                    ],
                    'outline' => [
                        'title' => __('Outline', 'calio-addon'),
                        'icon' => 'eicon-divider-shape',
                    ],
                    'glass' => [
                        'title' => __('Glass', 'calio-addon'),
                        'icon' => 'eicon-gallery-grid',
                    ],
                ],
                'default' => 'soft',
                'toggle' => false,
                'condition' => [
                    'show_badge' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'show_read_more',
            [
                'label' => __('Show Read More', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => '',
                'separator' => 'before',
            ]
        );

        $this->add_control(
            'read_more_text',
            [
                'label' => __('Read More Text', 'calio-addon'),
                'type' => Controls_Manager::TEXT,
                'default' => __('Read More', 'calio-addon'),
                'condition' => [
                    'show_read_more' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'read_more_skin',
            [
                'label' => __('Read More Style', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'link' => [
                        'title' => __('Link', 'calio-addon'),
                        'icon' => 'eicon-editor-link',
                    ],
                    'soft' => [
                        'title' => __('Soft', 'calio-addon'),
                        'icon' => 'eicon-lightbox',
                    ],
                    'solid' => [
                        'title' => __('Solid', 'calio-addon'),
                        'icon' => 'eicon-button',
                    ],
                    'outline' => [
                        'title' => __('Outline', 'calio-addon'),
                        'icon' => 'eicon-divider-shape',
                    ],
                ],
                'default' => 'link',
                'toggle' => false,
                'condition' => [
                    'show_read_more' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'read_more_show_arrow',
            [
                'label' => __('Show Read More Arrow', 'calio-addon'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'calio-addon'),
                'label_off' => __('Hide', 'calio-addon'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [
                    'show_read_more' => 'yes',
                ],
            ]
        );

        $this->end_controls_section();
    }

    private function register_load_more_button_style_controls(): void
    {
        $this->start_controls_section(
            'eael_section_load_more_btn',
            [
                'label' => __('Load More', 'calio-addon'),
                'tab' => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'show_load_more' => ['yes', '1', 'true', 'infinity'],
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_post_grid_load_more_btn_padding',
            [
                'label' => esc_html__('Padding', 'calio-addon'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', '%'],
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_post_grid_load_more_btn_margin',
            [
                'label' => esc_html__('Margin', 'calio-addon'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', '%'],
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'eael_post_grid_load_more_btn_typography',
                'selector' => '{{WRAPPER}} .eael-load-more-button .calio-load-more-button__label',
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'eael_post_grid_load_more_btn_subtext_typography',
                'selector' => '{{WRAPPER}} .eael-load-more-button .calio-load-more-button__subtext',
            ]
        );

        $this->add_control(
            'eael_post_grid_load_more_btn_subtext_color',
            [
                'label' => esc_html__('Secondary Text Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button .calio-load-more-button__subtext' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_post_grid_load_more_btn_icon_size',
            [
                'label' => esc_html__('Icon Size', 'calio-addon'),
                'type' => Controls_Manager::SLIDER,
                'range' => [
                    'px' => [
                        'min' => 8,
                        'max' => 40,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button' => '--calio-load-more-icon-size: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_post_grid_load_more_btn_icon_gap',
            [
                'label' => esc_html__('Icon Gap', 'calio-addon'),
                'type' => Controls_Manager::SLIDER,
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 40,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button' => '--calio-load-more-gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->start_controls_tabs('eael_post_grid_load_more_btn_tabs');

        $this->start_controls_tab(
            'eael_post_grid_load_more_btn_normal',
            ['label' => esc_html__('Normal', 'calio-addon')]
        );

        $this->add_control(
            'eael_post_grid_load_more_btn_normal_text_color',
            [
                'label' => esc_html__('Text Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'default' => '#ffffff',
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_cta_btn_normal_bg_color',
            [
                'label' => esc_html__('Background Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'default' => '#2563eb',
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'eael_post_grid_load_more_btn_normal_border',
                'label' => esc_html__('Border', 'calio-addon'),
                'selector' => '{{WRAPPER}} .eael-load-more-button',
            ]
        );

        $this->add_control(
            'eael_post_grid_load_more_btn_border_radius',
            [
                'label' => esc_html__('Border Radius', 'calio-addon'),
                'type' => Controls_Manager::SLIDER,
                'range' => [
                    'px' => [
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button' => 'border-radius: {{SIZE}}px;',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'eael_post_grid_load_more_btn_shadow',
                'selector' => '{{WRAPPER}} .eael-load-more-button',
                'separator' => 'before',
            ]
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'eael_post_grid_load_more_btn_hover',
            ['label' => esc_html__('Hover', 'calio-addon')]
        );

        $this->add_control(
            'eael_post_grid_load_more_btn_hover_text_color',
            [
                'label' => esc_html__('Text Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'default' => '#ffffff',
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button:hover' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_post_grid_load_more_btn_hover_bg_color',
            [
                'label' => esc_html__('Background Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'default' => '#1d4ed8',
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button:hover' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_post_grid_load_more_btn_hover_border_color',
            [
                'label' => esc_html__('Border Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button:hover' => 'border-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'eael_post_grid_load_more_btn_hover_shadow',
                'selector' => '{{WRAPPER}} .eael-load-more-button:hover',
                'separator' => 'before',
            ]
        );

        $this->end_controls_tab();
        $this->end_controls_tabs();

        $this->add_responsive_control(
            'eael_post_grid_loadmore_button_alignment',
            [
                'label' => __('Button Alignment', 'calio-addon'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'flex-start' => [
                        'title' => __('Left', 'calio-addon'),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => __('Center', 'calio-addon'),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'flex-end' => [
                        'title' => __('Right', 'calio-addon'),
                        'icon' => 'eicon-text-align-right',
                    ],
                ],
                'default' => 'center',
                'selectors' => [
                    '{{WRAPPER}} .eael-load-more-button-wrap' => 'justify-content: {{VALUE}};',
                ],
            ]
        );

        $this->end_controls_section();
    }

    private function register_badge_style_controls(): void
    {
        $this->start_controls_section(
            'eael_section_post_timeline_badge_style',
            [
                'label' => __('Badge', 'calio-addon'),
                'tab' => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'show_badge' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_badge_text_color',
            [
                'label' => __('Text Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-badge' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_badge_bg_color',
            [
                'label' => __('Background', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-badge' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_badge_border_color',
            [
                'label' => __('Border Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-badge' => 'border-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'eael_timeline_badge_typography',
                'selector' => '{{WRAPPER}} .calio-post-timeline-badge',
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_badge_padding',
            [
                'label' => __('Padding', 'calio-addon'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-badge' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_badge_radius',
            [
                'label' => __('Border Radius', 'calio-addon'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-badge' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_section();
    }

    private function register_read_more_style_controls(): void
    {
        $this->start_controls_section(
            'eael_section_post_timeline_read_more_style',
            [
                'label' => __('Read More', 'calio-addon'),
                'tab' => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'show_read_more' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_read_more_text_color',
            [
                'label' => __('Text Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-read-more' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_read_more_bg_color',
            [
                'label' => __('Background', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-read-more' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_read_more_border_color',
            [
                'label' => __('Border Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-read-more' => 'border-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_read_more_hover_color',
            [
                'label' => __('Hover Text Color', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .eael-timeline-post-link:hover .calio-post-timeline-read-more' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'eael_timeline_read_more_hover_bg_color',
            [
                'label' => __('Hover Background', 'calio-addon'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .eael-timeline-post-link:hover .calio-post-timeline-read-more' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'eael_timeline_read_more_typography',
                'selector' => '{{WRAPPER}} .calio-post-timeline-read-more',
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_read_more_padding',
            [
                'label' => __('Padding', 'calio-addon'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-read-more' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_read_more_radius',
            [
                'label' => __('Border Radius', 'calio-addon'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-read-more' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'eael_timeline_read_more_gap',
            [
                'label' => __('Icon Gap', 'calio-addon'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 24,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .calio-post-timeline-read-more' => '--calio-timeline-read-more-gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_section();
    }

    public function get_template_list_for_dropdown(bool $sort = false): array
    {
        $options = [];

        foreach ($this->get_template_map() as $key => $template) {
            $options[$key] = $template['label'];
        }

        if ($sort) {
            ksort($options);
        }

        return $options;
    }

    public function get_template($filename)
    {
        $templates = $this->get_template_map();
        return $templates[$filename]['path'] ?? false;
    }

    public function get_filename_only($path)
    {
        return basename((string) $path);
    }

    protected function get_temp_dir_name($filename)
    {
        return !empty($filename) ? 'free' : 'free';
    }

    private function get_template_map(): array
    {
        $templates = [];
        $directory = $this->get_template_dir();

        if (!is_dir($directory)) {
            return $templates;
        }

        foreach ((array) glob($directory . DIRECTORY_SEPARATOR . '*.php') as $path) {
            $slug = sanitize_title((string) pathinfo($path, PATHINFO_FILENAME));
            $label = ucwords(str_replace(['-', '_'], ' ', $slug));
            $templates[$slug] = [
                'label' => $label,
                'path' => $path,
            ];
        }

        return $templates;
    }

    private function get_template_dir(): string
    {
        return CALIO_PATH . 'src/Templates/Post-Timeline';
    }

    private function get_layout_choices(): array
    {
        $baseUrl = CALIO_URL . 'assets/admin/images/layout-previews/';

        return [
            'default' => [
                'title' => esc_html__('Default', 'calio-addon'),
                'icon' => 'eicon-posts-group',
                'image' => $baseUrl . 'post-timeline-default.png',
            ],
            'card' => [
                'title' => esc_html__('Card', 'calio-addon'),
                'icon' => 'eicon-gallery-grid',
                'image' => $baseUrl . 'post-timeline-card.png',
            ],
        ];
    }

    private function get_layout_preview_markup(string $layout, string $label): string
    {
        $imageUrl = CALIO_URL . 'assets/admin/images/layout-previews/post-timeline-' . sanitize_title($layout) . '.png';

        return '<div style="display:grid;gap:10px;padding:12px;border:1px solid rgba(148,163,184,.24);border-radius:16px;background:linear-gradient(180deg,#fff 0%,#f8fbff 100%);">'
            . '<strong style="font-size:12px;letter-spacing:.04em;text-transform:uppercase;color:#475569;">' . esc_html($label) . '</strong>'
            . '<img src="' . esc_url($imageUrl) . '" alt="' . esc_attr($label) . '" style="display:block;width:100%;height:auto;border-radius:12px;border:1px solid rgba(226,232,240,.92);" />'
            . '<span style="font-size:12px;color:#64748b;">' . esc_html__('Preview updates with the selected timeline structure.', 'calio-addon') . '</span>'
            . '</div>';
    }

    private function normalize_load_mode($value): string
    {
        $value = strtolower(trim((string) $value));

        if ($value === 'infinity') {
            return 'infinity';
        }

        if (in_array($value, ['yes', '1', 'true'], true)) {
            return 'yes';
        }

        return 'no';
    }

    public static function get_template_file(string $layout): ?string
    {
        $layout = sanitize_title($layout);
        $path = CALIO_PATH . 'src/Templates/Post-Timeline/' . $layout . '.php';

        return is_readable($path) ? $path : null;
    }

    public static function render_items_html(\WP_Query $query, array $settings, string $template, int $initialVisibleLimit = 0): string
    {
        if (!is_readable($template)) {
            return '';
        }

        ob_start();

        if ($query->have_posts()) {
            $index = 0;
            while ($query->have_posts()) {
                $query->the_post();
                $GLOBALS['calio_post_timeline_hidden'] = $initialVisibleLimit > 0 && ($index >= $initialVisibleLimit);
                $GLOBALS['calio_post_timeline_index'] = $index;
                include $template;
                $index++;
            }
        }

        unset($GLOBALS['calio_post_timeline_hidden'], $GLOBALS['calio_post_timeline_index']);

        return (string) ob_get_clean();
    }

    private function get_current_page_id(): int
    {
        if (class_exists('\Elementor\Plugin')) {
            $document = \Elementor\Plugin::$instance->documents->get_current();
            if ($document && method_exists($document, 'get_main_id')) {
                return (int) $document->get_main_id();
            }
        }

        $pageId = get_the_ID();
        if ($pageId) {
            return (int) $pageId;
        }

        return (int) get_queried_object_id();
    }

    private function render_load_more_button(array $settings, string $mode, string $paginationMode, int $pageId, int $maxPage): void
    {
        $label = trim((string) ($settings['show_load_more_text'] ?? __('Load More', 'calio-addon')));
        $loadingLabel = trim((string) ($settings['load_more_loading_text'] ?? __('Loading Posts...', 'calio-addon')));
        $secondaryText = trim((string) ($settings['load_more_secondary_text'] ?? ''));
        $preset = sanitize_html_class((string) ($settings['load_more_button_preset'] ?? 'solid'));
        $size = sanitize_html_class((string) ($settings['load_more_button_size'] ?? 'md'));
        $width = sanitize_html_class((string) ($settings['load_more_button_width'] ?? 'auto'));
        $iconPosition = (($settings['load_more_icon_position'] ?? 'left') === 'right') ? 'right' : 'left';
        $wrapClasses = ['eael-load-more-button-wrap', 'calio-post-timeline-load-more-wrap'];
        if ($mode === 'infinity') {
            $wrapClasses[] = 'eael-infinity-scroll';
        }

        $buttonClasses = [
            'eael-load-more-button',
            'calio-load-more-button--preset-' . $preset,
            'calio-load-more-button--size-' . $size,
            'calio-load-more-button--icon-' . $iconPosition,
        ];
        if ($width === 'full') {
            $buttonClasses[] = 'is-full-width';
        }
        if ($secondaryText !== '') {
            $buttonClasses[] = 'has-subtext';
        }

        $iconHtml = '';
        if (!empty($settings['load_more_icon']['value'])) {
            $iconHtml = $this->get_icon_markup($settings['load_more_icon'], ['class' => 'calio-load-more-button__icon-svg']);
            if ($iconHtml !== '') {
                $buttonClasses[] = 'has-icon';
            }
        }

        $buttonAttributes = [
            'class' => implode(' ', $buttonClasses),
            'type' => 'button',
            'data-widget-id' => $this->get_id(),
            'data-page-id' => $pageId,
            'data-page' => '1',
            'data-max-page' => (string) max(1, $maxPage),
            'data-ajax-url' => admin_url('admin-ajax.php'),
            'data-ajax-nonce' => wp_create_nonce('calio_post_timeline_load_more'),
            'data-pagination-mode' => $paginationMode,
            'data-default-label' => $label !== '' ? $label : __('Load More', 'calio-addon'),
            'data-loading-label' => $loadingLabel !== '' ? $loadingLabel : __('Loading Posts...', 'calio-addon'),
        ];

        echo '<div class="' . esc_attr(implode(' ', $wrapClasses)) . '" data-mode="' . esc_attr($mode) . '" data-offset="' . esc_attr((string) ($settings['load_more_infinityscroll_offset'] ?? -200)) . '" data-pagination-mode="' . esc_attr($paginationMode) . '">';
        echo '<button';
        foreach ($buttonAttributes as $attribute => $value) {
            echo ' ' . esc_attr($attribute) . '="' . esc_attr((string) $value) . '"';
        }
        echo '>';
        echo '<span class="eael-btn-loader button__loader" aria-hidden="true"></span>';
        echo '<span class="calio-load-more-button__inner">';
        if ($iconHtml !== '' && $iconPosition === 'left') {
            echo '<span class="calio-load-more-button__icon" aria-hidden="true">' . wp_kses_post($iconHtml) . '</span>';
        }
        echo '<span class="calio-load-more-button__content">';
        echo '<span class="eael_load_more_text calio-load-more-button__label">' . esc_html($label !== '' ? $label : __('Load More', 'calio-addon')) . '</span>';
        if ($secondaryText !== '') {
            echo '<span class="calio-load-more-button__subtext">' . esc_html($secondaryText) . '</span>';
        }
        echo '</span>';
        if ($iconHtml !== '' && $iconPosition === 'right') {
            echo '<span class="calio-load-more-button__icon" aria-hidden="true">' . wp_kses_post($iconHtml) . '</span>';
        }
        echo '</span>';
        echo '</button>';
        echo '</div>';
    }

    protected function render()
    {
        $settings = PostTimelineHelper::fix_old_query($this->get_settings_for_display());
        $args = PostTimelineHelper::get_query_args($settings);
        $args = PostTimelineHelper::get_dynamic_args($settings, $args);

        $settings['expanison_indicator'] = $settings['excerpt_expanison_indicator'] ?? '...';

        $layout = sanitize_html_class((string) ($settings['eael_dynamic_template_Layout'] ?? 'default'));
        $arrowAlignment = sanitize_html_class((string) ($settings['eael_timeline_arrow_alignment'] ?? 'top'));
        $requestedPerPage = max(1, min(100, (int) ($settings['posts_per_page'] ?? 4)));
        $loadMode = $this->normalize_load_mode($settings['show_load_more'] ?? 'no');
        $paginationMode = 'none';

        if ($loadMode !== 'no') {
            $paginationMode = (($settings['post_type'] ?? '') === 'source_dynamic') ? 'reveal' : 'ajax';
        }

        if ($paginationMode === 'reveal') {
            $args['posts_per_page'] = -1;
        } else {
            $args['posts_per_page'] = $requestedPerPage;
        }

        $template = self::get_template_file($layout);
        if (!is_string($template) || !is_readable($template)) {
            echo '<p class="no-posts-found">' . esc_html__('No layout found!', 'calio-addon') . '</p>';
            return;
        }

        $this->add_render_attribute(
            'eael_post_timeline_wrapper',
            [
                'id' => 'eael-post-timeline-' . $this->get_id(),
                'class' => [
                    'eael-post-timeline',
                    'calio-post-timeline-widget',
                    'timeline-layout-' . $layout,
                    'eael-post-timeline-arrow-' . $arrowAlignment,
                    'calio-post-timeline-date-' . sanitize_html_class((string) ($settings['timeline_date_reveal'] ?? 'hover')),
                    'calio-post-timeline-connector-' . sanitize_html_class((string) ($settings['eael_timeline_connector_style'] ?? 'solid')),
                    'calio-post-timeline-arrow-hover-' . sanitize_html_class((string) ($settings['eael_timeline_arrow_hover_effect'] ?? 'slide')),
                    'calio-post-timeline-bullet-effect-' . sanitize_html_class((string) ($settings['eael_timeline_bullet_effect'] ?? 'none')),
                ],
                'data-load-mode' => $loadMode,
                'data-pagination-mode' => $paginationMode,
                'data-posts-per-page' => (string) $requestedPerPage,
                'data-infinity-offset' => (string) ($settings['load_more_infinityscroll_offset'] ?? -200),
            ]
        );

        $this->add_render_attribute(
            'eael_post_timeline',
            [
                'class' => [
                    'eael-post-timeline',
                    'eael-post-appender',
                    'eael-post-appender-' . $this->get_id(),
                    'timeline-layout-' . $layout,
                    'eael-post-timeline-arrow-' . $arrowAlignment,
                    'calio-post-timeline-connector-' . sanitize_html_class((string) ($settings['eael_timeline_connector_style'] ?? 'solid')),
                    'calio-post-timeline-arrow-hover-' . sanitize_html_class((string) ($settings['eael_timeline_arrow_hover_effect'] ?? 'slide')),
                    'calio-post-timeline-bullet-effect-' . sanitize_html_class((string) ($settings['eael_timeline_bullet_effect'] ?? 'none')),
                ],
            ]
        );

        $query = new \WP_Query($args);
        $foundPosts = (int) $query->found_posts;
        $maxPage = (int) $query->max_num_pages;
        $pageId = $this->get_current_page_id();

        $this->add_render_attribute('eael_post_timeline_wrapper', 'data-total-items', (string) $foundPosts);

        echo '<div ';
        $this->print_render_attribute_string('eael_post_timeline_wrapper');
        echo '>';

        echo '<div ';
        $this->print_render_attribute_string('eael_post_timeline');
        echo '>';

        if ($query->have_posts()) {
            echo wp_kses(
                self::render_items_html(
                    $query,
                    $settings,
                    $template,
                    $paginationMode === 'reveal' ? $requestedPerPage : 0
                ),
                PostTimelineHelper::eael_allowed_tags()
            );
        } else {
            echo '<p class="no-posts-found">' . esc_html__('No posts found!', 'calio-addon') . '</p>';
        }

        echo '</div>';

        if ($paginationMode === 'reveal' && $foundPosts > $requestedPerPage) {
            $this->render_load_more_button($settings, $loadMode, $paginationMode, $pageId, (int) ceil($foundPosts / $requestedPerPage));
        }

        if ($paginationMode === 'ajax' && $loadMode !== 'no' && $maxPage > 1) {
            $this->render_load_more_button($settings, $loadMode, $paginationMode, $pageId, $maxPage);
        }

        echo '</div>';

        wp_reset_postdata();
    }
}
