<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;  }
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Border;
trait Sifency_Button_Controls {
	protected function add_sifency_button_controls( $args = array() ) {
		$this->start_controls_section(
			'section_content_button',
			array( 'label' => esc_html__( 'Button', 'sifency-addons' ) )
		);
		$this->add_control(
			'button_style_type',
			array(
				'label'        => esc_html__( 'Button Style', 'sifency-addons' ),
				'type'         => \Elementor\Controls_Manager::SELECT,
				'default'      => 'primary',
				'options'      => array(
					'primary'   => esc_html__( 'Primary', 'sifency-addons' ),
					'secondary' => esc_html__( 'Secondary (Light)', 'sifency-addons' ),
					'outline'   => esc_html__( 'Outline', 'sifency-addons' ),
					'flip_text' => esc_html__( 'Flip Text', 'sifency-addons' ),
					'circle'    => esc_html__( 'Circle', 'sifency-addons' ),
					'ghost'     => esc_html__( 'Ghost (Minimal)', 'sifency-addons' ),
					'icon-only' => esc_html__( 'Icon Only', 'sifency-addons' ),
				),
				'prefix_class' => 'sifency-button-style--',
				'render_type'  => 'template',
			)
		);
		$this->add_control(
			'button_text',
			array(
				'label'   => 'Text',
				'type'    => Controls_Manager::TEXT,
				'default' => 'Click Here',
				'dynamic' => array( 'active' => true ),
			)
		);
		$this->add_control(
			'button_link',
			array(
				'label'   => 'Link',
				'type'    => Controls_Manager::URL,
				'default' => array( 'url' => '#' ),
				'dynamic' => array( 'active' => true ),
			)
		);
		$this->add_control(
			'button_icon',
			array(
				'label'     => 'Icon',
				'type'      => Controls_Manager::ICONS,
				'separator' => 'before',
				'default'   => array(
					'value'   => 'icon-right',
					'library' => 'sifency-icons',
				),
			)
		);
		$this->add_control(
			'icon_position',
			array(
				'label'        => 'Icon Position',
				'type'         => Controls_Manager::SELECT,
				'default'      => 'after',
				'options'      => array(
					'before' => 'Before Text',
					'after'  => 'After Text',
				),
				'prefix_class' => 'sifency-button-icon--',
				'condition'    => array( 'button_icon[value]!' => '' ),
			)
		);
		$this->add_responsive_control(
			'icon_spacing',
			array(
				'label'     => 'Icon Spacing',
				'type'      => Controls_Manager::SLIDER,
				'range'     => array( 'px' => array( 'max' => 50 ) ),
				'selectors' => array(
					'{{WRAPPER}}.sifency-button-icon--after .sifency-icon-style' => 'margin-left: {{SIZE}}{{UNIT}};',
					'{{WRAPPER}}.sifency-button-icon--before .sifency-icon-style' => 'margin-right: {{SIZE}}{{UNIT}};',
				),
				'condition' => array( 'button_icon[value]!' => '' ),
			)
		);
		$this->add_responsive_control(
			'align',
			array(
				'label'        => 'Alignment',
				'type'         => Controls_Manager::CHOOSE,
				'options'      => array(
					'left'    => array( 'icon' => 'eicon-text-align-left' ),
					'center'  => array( 'icon' => 'eicon-text-align-center' ),
					'right'   => array( 'icon' => 'eicon-text-align-right' ),
					'justify' => array( 'icon' => 'eicon-text-align-justify' ),
				),
				'prefix_class' => 'elementor-align%s-',
				'default'      => '',
			)
		);

		$this->add_control(
			'enable_underline_anim',
			array(
				'label'        => esc_html__( 'Underline Animation', 'sifency-addons' ),
				'type'         => \Elementor\Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Yes', 'sifency-addons' ),
				'label_off'    => esc_html__( 'No', 'sifency-addons' ),
				'return_value' => 'yes',
				'default'      => '',
				'prefix_class' => 'sifency-anim-line-',
			)
		);
		$this->add_control(
			'button_effect',
			array(
				'label'   => esc_html__( 'Hover Effect', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'default',
				'options' => array(
					'default'    => 'Default',
					'fade'       => 'Fade',
					'wipe-top'   => 'Wipe Top',
					'wipe-right' => 'Wipe Right',
					'scramble'   => 'Text Scramble',
				),
			)
		);
		$this->end_controls_section();
	}

	protected function add_sifency_circle_button_style_controls() {

		$condition = array( 'button_style_type' => 'circle' );
		$selector  = '{{WRAPPER}} .sifency-button.sifency-circle-btn';

		$this->start_controls_section(
			'section_circle_button_style',
			array(
				'label'     => esc_html__( 'Circle Button Style', 'sifency-addons' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => $condition,
			)
		);
		$this->add_responsive_control(
			'circle_size',
			array(
				'label'      => esc_html__( 'Size (Width/Height)', 'sifency-addons' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', 'em', 'rem' ),
				'range'      => array(
					'px' => array(
						'min' => 50,
						'max' => 300,
					),
				),
				'default'    => array(
					'unit' => 'px',
					'size' => 150,
				),
				'selectors'  => array(
					$selector => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
				),
				'condition'  => $condition,
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'      => 'circle_typography',
				'selector'  => "$selector, $selector span",
				'condition' => $condition,
			)
		);
		$this->start_controls_tabs( 'tabs_circle_button_style' );

		$this->start_controls_tab(
			'tab_circle_normal',
			array(
				'label'     => esc_html__( 'Normal', 'sifency-addons' ),
				'condition' => $condition,
			)
		);
		$this->add_control(
			'circle_text_color',
			array(
				'label'     => esc_html__( 'Text / Icon Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					"$selector"      => 'color: {{VALUE}};',
					"$selector span" => 'color: {{VALUE}};',
					"$selector i"    => 'color: {{VALUE}};',
					"$selector svg"  => 'fill: {{VALUE}};',
				),
				'condition' => $condition,
			)
		);
		$this->add_control(
			'circle_bg_color',
			array(
				'label'     => esc_html__( 'Background Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => 'transparent',
				'selectors' => array(
					$selector => 'background-color: {{VALUE}};',
				),
				'condition' => $condition,
			)
		);
		$this->add_control(
			'circle_border_color',
			array(
				'label'     => esc_html__( 'Border Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					$selector => 'border-color: {{VALUE}};',
				),
				'condition' => $condition,
			)
		);

		$this->end_controls_tab();

		$this->start_controls_tab(
			'tab_circle_hover',
			array(
				'label'     => esc_html__( 'Hover', 'sifency-addons' ),
				'condition' => $condition,
			)
		);
		$this->add_control(
			'circle_hover_text_color',
			array(
				'label'     => esc_html__( 'Text / Icon Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					"$selector:hover"      => 'color: {{VALUE}};',
					"$selector:hover span" => 'color: {{VALUE}};',
					"$selector:hover i"    => 'color: {{VALUE}};',
					"$selector:hover svg"  => 'fill: {{VALUE}};',
				),
				'condition' => $condition,
			)
		);

		// The Slide Effect Color (Targeting ::before)
		$this->add_control(
			'circle_hover_fill_color',
			array(
				'label'     => esc_html__( 'Sliding Fill Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					"$selector::before" => 'background-color: {{VALUE}};',
					"$selector:hover"   => 'border-color: {{VALUE}};',
				),
				'condition' => $condition,
			)
		);
		$this->add_control(
			'circle_hover_border_color',
			array(
				'label'     => esc_html__( 'Border Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					"$selector:hover" => 'border-color: {{VALUE}};',
				),
				'condition' => $condition,
			)
		);

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

		// --- BORDER SETTINGS ---
		$this->add_control(
			'circle_border_width',
			array(
				'label'      => esc_html__( 'Border Width', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px' ),
				'default'    => array(
					'top'    => 1,
					'right'  => 1,
					'bottom' => 1,
					'left'   => 1,
					'unit'   => 'px',
				),
				'separator'  => 'before',
				'selectors'  => array(
					$selector => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}; border-style: solid;',
				),
				'condition'  => $condition,
			)
		);
		$this->add_responsive_control(
			'circle_border_radius',
			array(
				'label'      => esc_html__( 'Border Radius', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'default'    => array(
					'top'      => 50,
					'right'    => 50,
					'bottom'   => 50,
					'left'     => 50,
					'unit'     => '%',
					'isLinked' => true,
				),
				'separator'  => 'before',
				'selectors'  => array(
					$selector => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
				'condition'  => $condition,
			)
		);
		$this->add_control(
			'circle_transition',
			array(
				'label'     => esc_html__( 'Transition Duration (s)', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min'  => 0.1,
						'max'  => 2,
						'step' => 0.1,
					),
				),
				'default'   => array( 'size' => 0.3 ),
				'selectors' => array(
					"$selector::before"       => 'transition: left {{SIZE}}s ease-in-out;',
					"$selector:hover::before" => 'transition: left {{SIZE}}s ease-in-out;',
				),
				'condition' => $condition,
			)
		);
		$this->end_controls_section();
	}

}
