<?php
/**
 * A reusable Elementor trait for adding a comprehensive set of SLIDER NAVIGATION ARROW style controls.
 * This trait applies styles to a predefined HTML structure with specific classes.
 *
 * @package Sifency\Traits
 */

namespace Sifency\Traits;

if ( ! defined('ABSPATH') ) {
    exit; // Exit if accessed directly.
}

use Elementor\Controls_Manager;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Typography;

/**
 * Trait Sifency_Slider_Nav_Style_Controls
 */
trait Sifency_Slider_Nav_Style_Controls {

	/**
	 * Adds the complete slider navigation styling control panel.
	 *
	 * @param array $args { Optional. Arguments to customize the controls.
	 *     @type string $prefix A unique prefix for control names.
	 *     @type array $condition Elementor control condition.
	 * }
	 */
	protected function add_sifency_slider_nav_style_controls( $args = [] ) {
		$args = wp_parse_args( $args, [
			'prefix'    => 'nav_',
			'condition' => [],
		] );
		$prefix = $args['prefix'];

		// Define the selectors based on the required HTML structure.
		$selectors = [
			'container'    => '{{WRAPPER}} .sifency-slider-nav-container',
			'arrow_common' => '{{WRAPPER}} .sifency-slider-nav-arrow',
			'arrow_prev'   => '{{WRAPPER}} .sifency-slider-nav-prev',
			'arrow_next'   => '{{WRAPPER}} .sifency-slider-nav-next',
			'icon_common'  => '{{WRAPPER}} .sifency-slider-nav-arrow i, {{WRAPPER}} .sifency-slider-nav-arrow svg',
		];


		$this->start_controls_section(
			$prefix . 'style_section',
			[
				'label'     => esc_html__( 'Slider Navigation', 'sifency-addons' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => $args['condition'],
			]
		);

		// --- General Arrow Styling ---
		$this->add_control(
			$prefix . 'heading_arrows_style',
			[
				'label' => esc_html__( 'Arrow Styling', 'sifency-addons' ),
				'type'  => Controls_Manager::HEADING,
			]
		);

		$this->add_responsive_control(
			$prefix . 'icon_size',
			[
				'label'     => esc_html__( 'Icon Size', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => [ 'px' => [ 'min' => 10, 'max' => 100 ] ],
				'selectors' => [
					$selectors['icon_common'] => 'font-size: {{SIZE}}{{UNIT}};',
					// For SVG icons
					'{{WRAPPER}} .sifency-slider-nav-arrow svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
				],
			]
		);

		$this->add_responsive_control(
			$prefix . 'box_size',
			[
				'label'     => esc_html__( 'Box Size', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => [ 'px' => [ 'min' => 20, 'max' => 200 ] ],
				'selectors' => [
					$selectors['arrow_common'] => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}}; line-height: {{SIZE}}{{UNIT}};',
				],
			]
		);

		// --- Normal & Hover Tabs ---
		$this->start_controls_tabs( $prefix . 'style_tabs' );
		// Normal Tab
		$this->start_controls_tab( $prefix . 'normal_tab', [ 'label' => esc_html__( 'Normal', 'sifency-addons' ) ] );
		$this->add_control( $prefix . 'icon_color', [ 'label' => esc_html__( 'Icon Color', 'sifency-addons' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ $selectors['icon_common'] => 'color: {{VALUE}}; fill: {{VALUE}};' ] ] );
		$this->add_group_control( Group_Control_Background::get_type(), [ 'name' => $prefix . 'background', 'selector' => $selectors['arrow_common'] ] );
		$this->add_group_control( Group_Control_Border::get_type(), [ 'name' => $prefix . 'border', 'selector' => $selectors['arrow_common'] ] );
		$this->add_responsive_control( $prefix . 'border_radius', [ 'label' => esc_html__( 'Border Radius', 'sifency-addons' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%' ], 'selectors' => [ $selectors['arrow_common'] => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ] );
		$this->add_group_control( Group_Control_Box_Shadow::get_type(), [ 'name' => $prefix . 'box_shadow', 'selector' => $selectors['arrow_common'] ] );
		$this->end_controls_tab();

		// Hover Tab
		$this->start_controls_tab( $prefix . 'hover_tab', [ 'label' => esc_html__( 'Hover', 'sifency-addons' ) ] );
		$this->add_control( $prefix . 'hover_icon_color', [ 'label' => esc_html__( 'Icon Color', 'sifency-addons' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ $selectors['arrow_common'] . ':hover i' => 'color: {{VALUE}};', $selectors['arrow_common'] . ':hover svg' => 'fill: {{VALUE}};' ] ] );
		$this->add_group_control( Group_Control_Background::get_type(), [ 'name' => $prefix . 'hover_background', 'selector' => $selectors['arrow_common'] . ':hover' ] );
		$this->add_control( $prefix . 'hover_border_color', [ 'label' => esc_html__( 'Border Color', 'sifency-addons' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ $selectors['arrow_common'] . ':hover' => 'border-color: {{VALUE}};' ], 'condition' => [ $prefix . 'border_border!' => '' ] ] );
		$this->add_group_control( Group_Control_Box_Shadow::get_type(), [ 'name' => $prefix . 'hover_box_shadow', 'selector' => $selectors['arrow_common'] . ':hover' ] );
		$this->end_controls_tab();
		$this->end_controls_tabs();

		// --- Positioning ---
		$this->add_control(
			$prefix . 'heading_positioning',
			[
				'label'     => esc_html__( 'Positioning', 'sifency-addons' ),
				'type'      => Controls_Manager::HEADING,
				'separator' => 'before',
			]
		);

		// Previous Arrow
		$this->add_control( $prefix . 'heading_prev', [ 'label' => esc_html__( 'Previous Arrow', 'sifency-addons' ), 'type' => Controls_Manager::HEADING ] );
		$this->add_responsive_control( $prefix . 'prev_vertical_pos', [ 'label' => esc_html__( 'Vertical Position', 'sifency-addons' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px', '%' ], 'range' => [ 'px' => [ 'min' => -200, 'max' => 500 ], '%' => [ 'min' => -100, 'max' => 100 ] ], 'default' => [ 'unit' => '%', 'size' => 50 ], 'selectors' => [ $selectors['arrow_prev'] => 'top: {{SIZE}}{{UNIT}};' ] ] );
		$this->add_responsive_control( $prefix . 'prev_horizontal_pos', [ 'label' => esc_html__( 'Horizontal Position', 'sifency-addons' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px', '%' ], 'range' => [ 'px' => [ 'min' => -200, 'max' => 500 ], '%' => [ 'min' => -100, 'max' => 100 ] ], 'selectors' => [ $selectors['arrow_prev'] => 'left: {{SIZE}}{{UNIT}};' ] ] );

		// Next Arrow
		$this->add_control( $prefix . 'heading_next', [ 'label' => esc_html__( 'Next Arrow', 'sifency-addons' ), 'type' => Controls_Manager::HEADING, 'separator' => 'before' ] );
		$this->add_responsive_control( $prefix . 'next_vertical_pos', [ 'label' => esc_html__( 'Vertical Position', 'sifency-addons' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px', '%' ], 'range' => [ 'px' => [ 'min' => -200, 'max' => 500 ], '%' => [ 'min' => -100, 'max' => 100 ] ], 'default' => [ 'unit' => '%', 'size' => 50 ], 'selectors' => [ $selectors['arrow_next'] => 'top: {{SIZE}}{{UNIT}};' ] ] );
		$this->add_responsive_control( $prefix . 'next_horizontal_pos', [ 'label' => esc_html__( 'Horizontal Position', 'sifency-addons' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px', '%' ], 'range' => [ 'px' => [ 'min' => -200, 'max' => 500 ], '%' => [ 'min' => -100, 'max' => 100 ] ], 'selectors' => [ $selectors['arrow_next'] => 'right: {{SIZE}}{{UNIT}};' ] ] );

		// --- Transition ---
		$this->add_control(
			$prefix . 'transition_duration',
			[
				'label'     => esc_html__( 'Transition Duration (s)', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => [ 'px' => [ 'max' => 2, 'step' => 0.1 ] ],
				'default'   => [ 'size' => 0.3 ],
				'separator' => 'before',
				'selectors' => [
					$selectors['arrow_common'] => 'transition: color {{SIZE}}s ease, background {{SIZE}}s ease, border-color {{SIZE}}s ease, box-shadow {{SIZE}}s ease;',
					$selectors['icon_common']  => 'transition: color {{SIZE}}s ease, fill {{SIZE}}s ease;',
				],
			]
		);

		$this->end_controls_section();
	}
}