<?php
namespace Sifency\Traits;
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
trait Sifency_Post_Navigator_Controls {

	protected function add_sifency_post_navigator_controls( $args = [] ) {
		$this->start_controls_section(
			'section_content',
			[ 'label' => esc_html__( 'Labels & Icons', 'sifency-addons' ) ]
		);
		$this->add_control(
			'prev_text',
			[ 'label' => esc_html__('Previous Label', 'sifency-addons'), 'type' => Controls_Manager::TEXT, 'default' => esc_html__('Previous Post', 'sifency-addons') ]
		);
		$this->add_control(
			'prev_icon',
			[ 'label' => esc_html__('Previous Icon', 'sifency-addons'), 'type' => Controls_Manager::ICONS, 'default' => [ 'value' => 'fas fa-arrow-left', 'library' => 'fa-solid' ] ]
		);
		$this->add_control(
			'next_text',
			[ 'label' => esc_html__('Next Label', 'sifency-addons'), 'type' => Controls_Manager::TEXT, 'default' => esc_html__('Next Post', 'sifency-addons'), 'separator' => 'before' ]
		);
		$this->add_control(
			'next_icon',
			[ 'label' => esc_html__('Next Icon', 'sifency-addons'), 'type' => Controls_Manager::ICONS, 'default' => [ 'value' => 'fas fa-arrow-right', 'library' => 'fa-solid' ] ]
		);
        $this->add_control(
			'show_post_title',
			[ 'label' => esc_html__('Show Post Titles', 'sifency-addons'), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__('Show', 'sifency-addons'), 'label_off' => esc_html__('Hide', 'sifency-addons'), 'return_value' => 'yes', 'default' => 'yes', 'separator' => 'before' ]
		);
		$this->end_controls_section();

		// --- Section: Query ---
		$this->start_controls_section(
			'section_query',
			[ 'label' => esc_html__( 'Query', 'sifency-addons' ) ]
		);
		$this->add_control(
			'in_same_term',
			[
				'label' => esc_html__( 'In Same Taxonomy', 'sifency-addons' ),
				'type' => Controls_Manager::SWITCHER,
				'description' => esc_html__( 'Only show posts from the same taxonomy term (e.g., category).', 'sifency-addons' ),
				'default' => 'no',
			]
		);
		$this->add_control(
			'taxonomy',
			[
				'label' => esc_html__( 'Taxonomy', 'sifency-addons' ),
				'type' => Controls_Manager::SELECT,
				'options' => get_taxonomies( [ 'show_in_nav_menus' => true ], 'objects' ),
				'default' => 'category',
				'condition' => [ 'in_same_term' => 'yes' ],
			]
		);
		$this->end_controls_section();

		// --- Section: Style Layout ---
		$this->start_controls_section(
			'section_style_layout',
			[ 'label' => esc_html__('Layout', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
		);
        $this->add_control(
			'layout_justify',
			[
				'label' => esc_html__('Justify', 'sifency-addons'), 'type' => Controls_Manager::CHOOSE,
				'options' => [
					'space-between' => [ 'title' => 'Space Between', 'icon' => 'eicon-justify-space-between-h' ],
					'flex-start' => [ 'title' => 'Start', 'icon' => 'eicon-h-align-left' ],
					'center' => [ 'title' => 'Center', 'icon' => 'eicon-h-align-center' ],
					'flex-end' => [ 'title' => 'End', 'icon' => 'eicon-h-align-right' ],
				],
				'default' => 'space-between',
				'selectors' => [ '{{WRAPPER}} .sifency-post-navigation' => 'justify-content: {{VALUE}};' ],
			]
		);
		$this->add_responsive_control(
			'layout_gap',
			[
				'label' => esc_html__('Gap', 'sifency-addons'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%' ],
				'range' => [ 'px' => [ 'min' => 0, 'max' => 200 ] ],
				'selectors' => [ '{{WRAPPER}} .sifency-post-navigation' => 'gap: {{SIZE}}{{UNIT}};' ],
				'condition' => [ 'layout_justify!' => 'space-between' ],
			]
		);
		$this->end_controls_section();

		// --- Section: Style Box ---
		$this->start_controls_section(
			'section_style_box',
			[ 'label' => esc_html__('Box Style', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
		);
		$this->add_responsive_control('box_padding', [ 'label' => esc_html__('Padding', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => ['px', '%', 'em'], 'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'] ]);
		$this->add_responsive_control('box_border_radius', [ 'label' => esc_html__('Border Radius', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => ['px', '%'], 'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'] ]);
		$this->start_controls_tabs('box_style_tabs');
		$this->start_controls_tab('box_normal', ['label' => esc_html__('Normal', 'sifency-addons')]);
		$this->add_control('box_bg_color', [ 'label' => esc_html__('Background Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link' => 'background-color: {{VALUE}};'] ]);
		$this->add_group_control(Group_Control_Border::get_type(), [ 'name' => 'box_border', 'selector' => '{{WRAPPER}} .sifency-post-navigation__link' ]);
		$this->add_group_control(Group_Control_Box_Shadow::get_type(), [ 'name' => 'box_shadow', 'selector' => '{{WRAPPER}} .sifency-post-navigation__link' ]);
		$this->end_controls_tab();
		$this->start_controls_tab('box_hover', ['label' => esc_html__('Hover', 'sifency-addons')]);
		$this->add_control('box_hover_bg_color', [ 'label' => esc_html__('Background Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link:hover' => 'background-color: {{VALUE}};'] ]);
		$this->add_group_control(Group_Control_Border::get_type(), [ 'name' => 'box_hover_border', 'selector' => '{{WRAPPER}} .sifency-post-navigation__link:hover' ]);
		$this->add_group_control(Group_Control_Box_Shadow::get_type(), [ 'name' => 'box_hover_shadow', 'selector' => '{{WRAPPER}} .sifency-post-navigation__link:hover' ]);
		$this->end_controls_tab();
		$this->end_controls_tabs();
		$this->end_controls_section();

		// --- Section: Style Text ---
		$this->start_controls_section(
			'section_style_text',
			[ 'label' => esc_html__('Labels & Titles', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
		);
		$this->add_control('heading_label', ['type' => Controls_Manager::HEADING, 'label' => esc_html__('Label', 'sifency-addons')]);
		$this->add_group_control(Group_Control_Typography::get_type(), [ 'name' => 'label_typography', 'selector' => '{{WRAPPER}} .sifency-post-navigation__link-label' ]);
		$this->add_control('label_color', [ 'label' => esc_html__('Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link-label' => 'color: {{VALUE}};'] ]);
		$this->add_control('label_hover_color', [ 'label' => esc_html__('Hover Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link:hover .sifency-post-navigation__link-label' => 'color: {{VALUE}};'] ]);
		$this->add_responsive_control('label_spacing', ['label' => esc_html__('Spacing', 'sifency-addons'), 'type' => Controls_Manager::SLIDER, 'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link-label' => 'margin-bottom: {{SIZE}}{{UNIT}};'], 'condition' => ['show_post_title' => 'yes']]);

		$this->add_control('heading_title', ['type' => Controls_Manager::HEADING, 'label' => esc_html__('Post Title', 'sifency-addons'), 'separator' => 'before', 'condition' => ['show_post_title' => 'yes']]);
		$this->add_group_control(Group_Control_Typography::get_type(), [ 'name' => 'title_typography', 'selector' => '{{WRAPPER}} .sifency-post-navigation__link-title', 'condition' => ['show_post_title' => 'yes'] ]);
		$this->add_control('title_color', [ 'label' => esc_html__('Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link-title' => 'color: {{VALUE}};'], 'condition' => ['show_post_title' => 'yes'] ]);
		$this->add_control('title_hover_color', [ 'label' => esc_html__('Hover Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link:hover .sifency-post-navigation__link-title' => 'color: {{VALUE}};'], 'condition' => ['show_post_title' => 'yes'] ]);
		$this->end_controls_section();

		// --- Section: Style Icons ---
		$this->start_controls_section(
			'section_style_icons',
			[ 'label' => esc_html__('Icons', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
		);

		// -- Icon Color & Size --
		$this->add_control(
			'heading_icon_style',
			[
				'type' => Controls_Manager::HEADING,
				'label' => esc_html__('Icon Style', 'sifency-addons'),
			]
		);
		$this->add_responsive_control(
			'icon_size',
			[
				'label' => esc_html__('Size', 'sifency-addons'),
				'type' => Controls_Manager::SLIDER,
				'range' => ['px' => ['min' => 6, 'max' => 100]],
				'selectors' => [
					'{{WRAPPER}} .sifency-post-navigation__arrow' => 'font-size: {{SIZE}}{{UNIT}};',
					'{{WRAPPER}} .sifency-post-navigation__arrow svg' => 'width: {{SIZE}}{{UNIT}}; height: auto;',
				]
			]
		);
		$this->add_responsive_control(
			'icon_spacing',
			[
				'label' => esc_html__('Spacing', 'sifency-addons'),
				'type' => Controls_Manager::SLIDER,
				'selectors' => [
					'{{WRAPPER}} .sifency-post-navigation__prev .sifency-post-navigation__arrow' => 'margin-right: {{SIZE}}{{UNIT}};',
					'{{WRAPPER}} .sifency-post-navigation__next .sifency-post-navigation__arrow' => 'margin-left: {{SIZE}}{{UNIT}};'
				]
			]
		);

		// -- Icon Box Styling --
		$this->add_control(
			'heading_icon_box',
			[
				'type' => Controls_Manager::HEADING,
				'label' => esc_html__('Icon Box', 'sifency-addons'),
				'separator' => 'before',
			]
		);
		$this->add_responsive_control(
			'icon_box_padding',
			[
				'label' => esc_html__('Padding', 'sifency-addons'),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => ['px', 'em', '%'],
				'selectors' => [
					'{{WRAPPER}} .sifency-post-navigation__arrow' => 'display: inline-flex; align-items: center; justify-content: center; padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
				],
			]
		);
		$this->add_responsive_control(
			'icon_box_border_radius',
			[
				'label' => esc_html__('Border Radius', 'sifency-addons'),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%'],
				'selectors' => [
					'{{WRAPPER}} .sifency-post-navigation__arrow' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
				],
			]
		);

		$this->start_controls_tabs('icon_box_style_tabs');
			// -- Normal Tab --
			$this->start_controls_tab(
				'icon_box_normal',
				['label' => esc_html__('Normal', 'sifency-addons')]
			);
			$this->add_control(
				'icon_color',
				[
					'label' => esc_html__('Icon Color', 'sifency-addons'),
					'type' => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .sifency-post-navigation__arrow' => 'color: {{VALUE}};',
						'{{WRAPPER}} .sifency-post-navigation__arrow svg' => 'fill: {{VALUE}};'
					]
				]
			);
			$this->add_control(
				'icon_box_bg_color',
				[
					'label' => esc_html__('Background Color', 'sifency-addons'),
					'type' => Controls_Manager::COLOR,
					'selectors' => ['{{WRAPPER}} .sifency-post-navigation__arrow' => 'background-color: {{VALUE}};']
				]
			);
			$this->add_group_control(
				Group_Control_Border::get_type(),
				[
					'name' => 'icon_box_border',
					'selector' => '{{WRAPPER}} .sifency-post-navigation__arrow'
				]
			);
			$this->add_group_control(
				Group_Control_Box_Shadow::get_type(),
				[
					'name' => 'icon_box_shadow',
					'selector' => '{{WRAPPER}} .sifency-post-navigation__arrow'
				]
			);
			$this->end_controls_tab();

			// -- Hover Tab --
			$this->start_controls_tab(
				'icon_box_hover',
				['label' => esc_html__('Hover', 'sifency-addons')]
			);
			$this->add_control(
				'icon_hover_color',
				[
					'label' => esc_html__('Icon Color', 'sifency-addons'),
					'type' => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .sifency-post-navigation__link:hover .sifency-post-navigation__arrow' => 'color: {{VALUE}};',
						'{{WRAPPER}} .sifency-post-navigation__link:hover .sifency-post-navigation__arrow svg' => 'fill: {{VALUE}};'
					]
				]
			);
			$this->add_control(
				'icon_box_hover_bg_color',
				[
					'label' => esc_html__('Background Color', 'sifency-addons'),
					'type' => Controls_Manager::COLOR,
					'selectors' => ['{{WRAPPER}} .sifency-post-navigation__link:hover .sifency-post-navigation__arrow' => 'background-color: {{VALUE}};']
				]
			);
			$this->add_group_control(
				Group_Control_Border::get_type(),
				[
					'name' => 'icon_box_hover_border',
					'selector' => '{{WRAPPER}} .sifency-post-navigation__link:hover .sifency-post-navigation__arrow'
				]
			);
			$this->add_group_control(
				Group_Control_Box_Shadow::get_type(),
				[
					'name' => 'icon_box_hover_shadow',
					'selector' => '{{WRAPPER}} .sifency-post-navigation__link:hover .sifency-post-navigation__arrow'
				]
			);
			$this->end_controls_tab();
		$this->end_controls_tabs();

		$this->end_controls_section();
    }
}