<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
use Elementor\Controls_Manager;

trait Sifency_Addons_Divider_Style_Controls {

	/**
	 * Reusable Divider Style Controls
	 */
	protected function add_sifency_divider_style_controls( $args = array() ) {

		$defaults = array(
			'prefix'    => 'divider_',
			'label'     => esc_html__( 'Divider Style', 'sifency-addons' ),
			'selector'  => '.sifency-divider',
			'condition' => array(),
			'exclude'   => array(),
		);

		$args = wp_parse_args( $args, $defaults );

		$prefix   = $args['prefix'];
		$exclude  = $args['exclude'];
		$base_sel = '{{WRAPPER}} ' . $args['selector'];

		$line_sel = $base_sel . ' .sifency-divider-line';

		$this->start_controls_section(
			$prefix . 'style_section',
			array(
				'label'     => $args['label'],
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => $args['condition'],
			)
		);

		// --- Alignment ---
		if ( ! in_array( 'alignment', $exclude ) ) {
			$this->add_responsive_control(
				$prefix . 'align',
				array(
					'label'     => esc_html__( 'Alignment', 'sifency-addons' ),
					'type'      => Controls_Manager::CHOOSE,
					'options'   => array(
						'left'   => array(
							'title' => esc_html__( 'Left', 'sifency-addons' ),
							'icon'  => 'eicon-text-align-left',
						),
						'center' => array(
							'title' => esc_html__( 'Center', 'sifency-addons' ),
							'icon'  => 'eicon-text-align-center',
						),
						'right'  => array(
							'title' => esc_html__( 'Right', 'sifency-addons' ),
							'icon'  => 'eicon-text-align-right',
						),
					),
					'selectors' => array(
						$base_sel => 'text-align: {{VALUE}}; display: block;',
					),
				)
			);
		}

		// --- Divider Type ---
		if ( ! in_array( 'type', $exclude ) ) {
			$this->add_control(
				$prefix . 'style',
				array(
					'label'     => esc_html__( 'Style', 'sifency-addons' ),
					'type'      => Controls_Manager::SELECT,
					'options'   => array(
						'solid'  => esc_html__( 'Solid', 'sifency-addons' ),
						'double' => esc_html__( 'Double', 'sifency-addons' ),
						'dotted' => esc_html__( 'Dotted', 'sifency-addons' ),
						'dashed' => esc_html__( 'Dashed', 'sifency-addons' ),
						'groove' => esc_html__( 'Groove', 'sifency-addons' ),
					),
					'default'   => 'solid',
					'selectors' => array(
						$line_sel => 'border-top-style: {{VALUE}};',
					),
				)
			);
		}

		// --- Color ---
		if ( ! in_array( 'color', $exclude ) ) {
			$this->add_control(
				$prefix . 'color',
				array(
					'label'     => esc_html__( 'Color', 'sifency-addons' ),
					'type'      => Controls_Manager::COLOR,
					'selectors' => array(
						$line_sel => 'border-top-color: {{VALUE}};',
					),
				)
			);
		}

		// --- Length (Width of the line) ---
		if ( ! in_array( 'width', $exclude ) ) {
			$this->add_responsive_control(
				$prefix . 'width',
				array(
					'label'      => esc_html__( 'Width', 'sifency-addons' ),
					'type'       => Controls_Manager::SLIDER,
					'size_units' => array( '%', 'px' ),
					'range'      => array(
						'%'  => array(
							'min' => 1,
							'max' => 100,
						),
						'px' => array(
							'min' => 1,
							'max' => 1200,
						),
					),
					'selectors'  => array(
						$line_sel => 'width: {{SIZE}}{{UNIT}}; display: inline-block;',
					),
				)
			);
		}

		// --- Weight (Thickness) ---
		if ( ! in_array( 'weight', $exclude ) ) {
			$this->add_responsive_control(
				$prefix . 'weight',
				array(
					'label'     => esc_html__( 'Weight', 'sifency-addons' ),
					'type'      => Controls_Manager::SLIDER,
					'range'     => array(
						'px' => array(
							'min' => 1,
							'max' => 20,
						),
					),
					'selectors' => array(
						$line_sel => 'border-top-width: {{SIZE}}{{UNIT}};',
					),
				)
			);
		}

		// --- Gap (Vertical Spacing) ---
		if ( ! in_array( 'gap', $exclude ) ) {
			$this->add_responsive_control(
				$prefix . 'gap',
				array(
					'label'     => esc_html__( 'Gap', 'sifency-addons' ),
					'type'      => Controls_Manager::SLIDER,
					'range'     => array(
						'px' => array(
							'min' => 0,
							'max' => 100,
						),
					),
					'selectors' => array(
						$base_sel => 'margin-top: {{SIZE}}{{UNIT}}; margin-bottom: {{SIZE}}{{UNIT}};',
					),
				)
			);
		}

		$this->end_controls_section();
	}
}
