<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;  }
use Elementor\Controls_Manager;
use Elementor\Repeater;
use \Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Border;
use \Elementor\Group_Control_Box_Shadow;
trait Sifency_Search_Controls {

	/**
	 *
	 * @param array $args Optional customization.
	 */
	protected function add_sifency_search_controls( $args = array() ) {
		$this->start_controls_section(
			'section_content',
			array( 'label' => esc_html__( 'Search Form', 'sifency-addons' ) )
		);
		$this->add_control(
			'placeholder_text',
			array(
				'label'   => 'Placeholder',
				'type'    => Controls_Manager::TEXT,
				'default' => 'Search...',
			)
		);
		$this->add_control(
			'button_type',
			array(
				'label'   => 'Button Type',
				'type'    => Controls_Manager::SELECT,
				'default' => 'icon',
				'options' => array(
					'icon' => 'Icon',
					'text' => 'Text',
				),
			)
		);
		$this->add_control(
			'button_text',
			array(
				'label'     => 'Button Text',
				'type'      => Controls_Manager::TEXT,
				'default'   => 'Search',
				'condition' => array( 'button_type' => 'text' ),
			)
		);
		$this->add_control(
			'search_icon',
			array(
				'label'     => 'Search Icon',
				'type'      => Controls_Manager::ICONS,
				'default'   => array(
					'value'   => 'icon-search-1',
					'library' => 'sifency-icons',
				),
				'condition' => array( 'button_type' => 'icon' ),
			)
		);
		$this->end_controls_section();
		$this->start_controls_section(
			'section_layout',
			array(
				'label' => esc_html__( 'Layout', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);
		$this->add_responsive_control(
			'form_width',
			array(
				'label'      => esc_html__( 'Form Width', 'sifency-addons' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%' ),
				'range'      => array(
					'px' => array(
						'min' => 100,
						'max' => 2000,
					),
					'%'  => array(
						'min' => 10,
						'max' => 100,
					),
				),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-search-form' => 'width: {{SIZE}}{{UNIT}};',
				),
			)
		);
		$this->add_responsive_control(
			'form_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(
					'{{WRAPPER}} .sifency-search-form-wrap' => 'text-align: {{VALUE}};',
				),
			)
		);
		$this->add_responsive_control(
			'form_margin',
			array(
				'label'      => esc_html__( 'Form Margin', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-search-form' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->end_controls_section();
		$this->start_controls_section(
			'section_style_form',
			array(
				'label' => esc_html__( 'Form', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_responsive_control(
			'form_height',
			array(
				'label'     => 'Height',
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 30,
						'max' => 200,
					),
				),
				'selectors' => array( '{{WRAPPER}} .sifency-search-form' => 'height: {{SIZE}}px;' ),
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'form_border',
				'selector' => '{{WRAPPER}} .sifency-search-form',
			)
		);
		$this->add_control(
			'form_border_radius',
			array(
				'label'     => 'Border Radius',
				'type'      => Controls_Manager::SLIDER,
				'selectors' => array( '{{WRAPPER}} .sifency-search-form' => 'border-radius: {{SIZE}}px;' ),
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'form_box_shadow',
				'selector' => '{{WRAPPER}} .sifency-search-form',
			)
		);
		$this->add_control(
			'form_bg',
			array(
				'label'     => esc_html__( 'Background', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-search-form' => 'background-color: {{VALUE}};',
				),
			)
		);
		$this->add_control(
			'form_transition',
			array(
				'label'     => esc_html__( 'Transition Duration (ms)', 'sifency-addons' ),
				'type'      => Controls_Manager::NUMBER,
				'default'   => 300,
				'min'       => 0,
				'selectors' => array(
					'{{WRAPPER}} .sifency-search-form, {{WRAPPER}} .sifency-search-field, {{WRAPPER}} .sifency-search-submit' => 'transition: all {{VALUE}}ms ease;',
				),
			)
		);
		$this->end_controls_section();
		$this->start_controls_section(
			'section_style_input',
			array(
				'label' => esc_html__( 'Input Field', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'input_typography',
				'selector' => '{{WRAPPER}} .sifency-search-field',
			)
		);
		$this->add_control(
			'input_color',
			array(
				'label'     => 'Text Color',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-field' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'input_bg_color',
			array(
				'label'     => 'Background',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-field' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_responsive_control(
			'input_padding',
			array(
				'label'      => 'Padding',
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-search-field' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_responsive_control(
			'input_width',
			array(
				'label'      => 'Input Width (when inline)',
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%' ),
				'range'      => array(
					'px' => array(
						'min' => 50,
						'max' => 2000,
					),
					'%'  => array(
						'min' => 10,
						'max' => 100,
					),
				),
				'selectors'  => array( '{{WRAPPER}} .sifency-search-field' => 'width: {{SIZE}}{{UNIT}};' ),
			)
		);
		$this->add_control(
			'placeholder_color',
			array(
				'label'     => 'Placeholder Color',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-field::placeholder' => 'color: {{VALUE}};' ),
			)
		);
		$this->start_controls_tabs( 'input_state_tabs' );
		$this->start_controls_tab( 'input_state_normal', array( 'label' => 'Normal' ) );
		$this->add_control(
			'input_border_color',
			array(
				'label'     => 'Border Color',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-field' => 'border-color: {{VALUE}};' ),
			)
		);
		$this->end_controls_tab();
		$this->start_controls_tab( 'input_state_focus', array( 'label' => 'Focus' ) );
		$this->add_control(
			'input_focus_border_color',
			array(
				'label'     => 'Focus Border Color',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-field:focus' => 'border-color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'input_focus_box_shadow',
			array(
				'label'       => 'Focus Shadow',
				'type'        => Controls_Manager::TEXT,
				'description' => 'CSS box-shadow value',
				'selectors'   => array( '{{WRAPPER}} .sifency-search-field:focus' => 'box-shadow: {{VALUE}};' ),
			)
		);
		$this->end_controls_tab();
		$this->end_controls_tabs();
		$this->end_controls_section();
		$this->start_controls_section(
			'section_style_icon',
			array(
				'label' => esc_html__( 'Icon', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_responsive_control(
			'icon_size',
			array(
				'label'     => 'Icon Size',
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 8,
						'max' => 80,
					),
				),
				'selectors' => array( '{{WRAPPER}} .sifency-search-submit i' => 'font-size: {{SIZE}}px;' ),
				'condition' => array( 'button_type' => 'icon' ),
			)
		);
		$this->add_control(
			'icon_color',
			array(
				'label'     => 'Icon Color',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-submit i' => 'color: {{VALUE}};' ),
				'condition' => array( 'button_type' => 'icon' ),
			)
		);
		$this->add_control(
			'icon_spacing',
			array(
				'label'     => 'Icon Spacing',
				'type'      => Controls_Manager::SLIDER,
				'selectors' => array( '{{WRAPPER}} .sifency-search-submit i' => 'margin-left: {{SIZE}}px; margin-right: {{SIZE}}px;' ),
				'condition' => array( 'button_type' => 'icon' ),
			)
		);
		$this->end_controls_section();
		$this->start_controls_section(
			'section_style_button',
			array(
				'label' => esc_html__( 'Button', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'      => 'button_typography',
				'selector'  => '{{WRAPPER}} .sifency-search-submit',
				'condition' => array( 'button_type' => 'text' ),
			)
		);
		$this->add_responsive_control(
			'button_custom_padding',
			array(
				'label'      => esc_html__( 'Button Padding', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-search-submit' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
				'condition'  => array( 'button_size' => 'custom' ),
			)
		);
		$this->add_responsive_control(
			'button_roundness',
			array(
				'label'     => 'Border Radius',
				'type'      => Controls_Manager::SLIDER,
				'selectors' => array( '{{WRAPPER}} .sifency-search-submit' => 'border-radius: {{SIZE}}px;' ),
			)
		);
		$this->start_controls_tabs( 'button_colors' );
		$this->start_controls_tab( 'button_normal', array( 'label' => 'Normal' ) );
		$this->add_control(
			'button_color',
			array(
				'label'     => 'Color',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-submit' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'button_bg_color',
			array(
				'label'     => 'Background',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-submit' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'button_border',
				'selector' => '{{WRAPPER}} .sifency-search-submit',
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'button_box_shadow',
				'selector' => '{{WRAPPER}} .sifency-search-submit',
			)
		);
		$this->end_controls_tab();
		$this->start_controls_tab( 'button_hover', array( 'label' => 'Hover' ) );
		$this->add_control(
			'button_hover_color',
			array(
				'label'     => 'Color',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-submit:hover' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'button_hover_bg_color',
			array(
				'label'     => 'Background',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-search-submit:hover' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'button_hover_transform',
			array(
				'label'     => 'Hover Transform (e.g. translateY(-2px))',
				'type'      => Controls_Manager::TEXT,
				'selectors' => array( '{{WRAPPER}} .sifency-search-submit:hover' => 'transform: {{VALUE}};' ),
			)
		);
		$this->end_controls_tab();
		$this->end_controls_tabs();
		$this->end_controls_section();
		$this->start_controls_section(
			'section_advanced_accessibility',
			array(
				'label' => esc_html__( 'Accessibility & Attributes', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);
		$this->add_control(
			'aria_label',
			array(
				'label'       => esc_html__( 'Button aria-label', 'sifency-addons' ),
				'type'        => Controls_Manager::TEXT,
				'description' => 'Used for icon-only buttons to improve accessibility.',
			)
		);
		$this->add_control(
			'input_autocomplete',
			array(
				'label'   => esc_html__( 'Input autocomplete', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					''    => 'Default',
					'on'  => 'On',
					'off' => 'Off',
				),
				'default' => '',
			)
		);
		$this->end_controls_section();
	}
}
