<?php

namespace Gigneo\Elementor\Widgets;

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

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

/**
 * Gigneo Elementor Search_Bar Widget
 *
 * @since 0.0.1
 */
class Search_Bar extends Widget_Base {


	/**
	 * Get widget unique name.
	 *
	 * @return string
	 */
	public function get_name() {
		return 'gigneo-search-bar';
	}

	/**
	 * Get widget title.
	 *
	 * This is the name displayed in the Elementor panel.
	 *
	 * @return string
	 */
	public function get_title() {
		return esc_html__( 'Search Bar', 'gigneo' );
	}

	/**
	 * Get widget icon.
	 *
	 * Define the icon that will appear in the Elementor panel.
	 *
	 * @return string
	 */
	public function get_icon() {
		return 'eicon-search gn-label';
	}

	/**
	 * Get widget categories.
	 *
	 * Defines the category under which the widget will be listed.
	 *
	 * @return array
	 */
	public function get_categories() {
		return array( 'gigneo-widgets' );
	}

	/**
	 * Get widget keywords.
	 *
	 * Helps users find the widget in Elementor search.
	 *
	 * @return array
	 */
	public function get_keywords() {
		return array( 'search', 'bar' );
	}

	/**
	 * Register widget controls.
	 *
	 * Adds controls/fields to the Elementor editor for this widget.
	 */
	protected function register_controls() {
		$this->start_controls_section(
			'section_general',
			array(
				'label' => esc_html__( 'General', 'gigneo' ),
			)
		);

		$this->add_control(
			'layout',
			array(
				'type'    => Controls_Manager::SELECT,
				'label'   => esc_html__( 'Layout', 'gigneo' ),
				'options' => array(
					'1' => esc_html__( 'Style 1', 'gigneo' ),
					'2' => esc_html__( 'Style 2', 'gigneo' ),
				),
				'default' => '1',
			)
		);

		$this->add_control(
			'search_placeholder',
			array(
				'type'        => Controls_Manager::TEXT,
				'label'       => esc_html__( 'Search placeholder', 'gigneo' ),
				'default'     => esc_html__( 'What are you looking for?', 'gigneo' ),
				'label_block' => true,
			)
		);

		$platform_type           = gigneo_platform_type();
		$employer_profile_access = gigneo_employer_profile_access();

		$search_types = array(
			'services'    => esc_html__( 'Services', 'gigneo' ),
			'jobs'        => esc_html__( 'Jobs', 'gigneo' ),
			'freelancers' => gigneo_freelancer_plural(),
			'employers'   => gigneo_employer_plural(),
		);

		if ( 'jobs' === $platform_type ) {
			unset( $search_types['service'] );
		}

		if ( 'service' === $platform_type ) {
			unset( $search_types['job'] );
		}

		if ( 'public' !== $employer_profile_access ) {
			unset( $search_types['employer'] );
		}

		$this->add_control(
			'search_types',
			array(
				'type'        => Controls_Manager::SELECT2,
				'label'       => esc_html__( 'Search types', 'gigneo' ),
				'options'     => $search_types,
				'default'     => array_keys( $search_types ),
				'multiple'    => true,
				'label_block' => true,
			)
		);

		$this->add_control(
			'search_button_icon',
			array(
				'label'                  => esc_html__( 'Button icon', 'gigneo' ),
				'type'                   => Controls_Manager::ICONS,
				'label_block'            => false,
				'skin'                   => 'inline'
			)
		);

		$this->add_control(
			'search_button_text',
			array(
				'type'        => Controls_Manager::TEXT,
				'label'       => esc_html__( 'Button text', 'gigneo' ),
				'default'     => esc_html__( 'Search', 'gigneo' ),
				'label_block' => true,
			)
		);

		$this->end_controls_section();

        $this->start_controls_section(
            'section_general_style',
            array(
                'label'     => esc_html__( 'General', 'gigneo' ),
                'tab'       => Controls_Manager::TAB_STYLE,
            )
        );

        $this->add_control(
            'general_background_color',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper' => 'background-color: {{VALUE}};',
                ),
            )
        );

        $this->add_responsive_control(
            'general_space_between',
            array(
                'label'      => esc_html__( 'Space Between', 'gigneo' ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => array( 'px', '%', 'em' ),
                'range'      => array(
                    'px' => array(
                        'min' => 0,
                        'max' => 30,
                    ),
                ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-bar-layout-1 .gn-search-types' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            array(
                'name'     => 'general_border',
                'selector' => '{{WRAPPER}} .gn-ele-search-bar-wrapper',
            )
        );

        $this->add_responsive_control(
            'general_border_radius',
            array(
                'label'      => esc_html__( 'Border Radius', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', '%' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'general_padding',
            array(
                'label'      => esc_html__( 'Padding', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'general_margin',
            array(
                'label'      => esc_html__( 'Margin', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'section_search_types',
            array(
                'label'     => esc_html__( 'Search Types', 'gigneo' ),
                'tab'       => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'layout' => '1',
                ],
            )
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            array(
                'name'     => 'search_types_typography',
                'label'    => esc_html__( 'Typography', 'gigneo' ),
                'selector' => '{{WRAPPER}} .gn-search-types .gn-search-type > label',
            )
        );

        $this->add_control(
            'search_types_alignment',
            [
                'label' => __( 'Alignment', 'gigneo' ),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'options' => [
                    'flex-start' => [
                        'title' => __( 'Left', 'gigneo' ),
                        'icon'  => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => __( 'Center', 'gigneo' ),
                        'icon'  => 'eicon-text-align-center',
                    ],
                    'flex-end' => [
                        'title' => __( 'Right', 'gigneo' ),
                        'icon'  => 'eicon-text-align-right',
                    ],
                ],
                'default' => 'left',
                'toggle' => true,
                'selectors' => [
                    '{{WRAPPER}} .gn-search-types' => 'justify-content: {{VALUE}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'search_types_space_between',
            array(
                'label'      => esc_html__( 'Space Between', 'gigneo' ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => array( 'px', '%', 'em' ),
                'range'      => array(
                    'px' => array(
                        'min' => 0,
                        'max' => 30,
                    ),
                ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-types' => 'gap: {{SIZE}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'search_types_spacing',
            array(
                'label'      => esc_html__( 'Spacing', 'gigneo' ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => array( 'px', '%', 'em' ),
                'range'      => array(
                    'px' => array(
                        'min' => 0,
                        'max' => 30,
                    ),
                ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-types .gn-search-type > label' => 'gap: {{SIZE}}{{UNIT}};',
                ),
            )
        );

        $this->start_controls_tabs( 'search_types_style_tabs' );

        $this->start_controls_tab(
            'search_types_normal',
            array( 'label' => esc_html__( 'Normal', 'gigneo' ) )
        );

        $this->add_control(
            'search_types_text_color',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-types .gn-search-type > label' => 'color: {{VALUE}};',
                ),
            )
        );

        $this->add_control(
            'search_types_background',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-types .gn-search-type > label' => 'background-color: {{VALUE}};',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            array(
                'name'     => 'search_types_box_shadow',
                'selector' => '{{WRAPPER}} .gn-search-types .gn-search-type > label',
            )
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'search_types_hover',
            array( 'label' => esc_html__( 'Hover', 'gigneo' ) )
        );

        $this->add_control(
            'search_types_text_color_hover',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-type:not(:has(input:checked)) > label:hover' => 'color: {{VALUE}};',
                ),
            )
        );

        $this->add_control(
            'search_types_background_hover',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-type:not(:has(input:checked)) > label:hover' => 'background-color: {{VALUE}};',
                ),
            )
        );

        $this->add_control(
            'search_types_border_hover',
            array(
                'label'     => esc_html__( 'Border Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-type:not(:has(input:checked)) > label:hover' => 'border-color: {{VALUE}};',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            array(
                'name'     => 'search_types_box_shadow_hover',
                'selector' => '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-type:not(:has(input:checked)) > label:hover',
            )
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'search_types_active',
            array( 'label' => esc_html__( 'Active', 'gigneo' ) )
        );

        $this->add_control(
            'search_types_text_color_active',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-type:has(input:checked) > label' => 'color: {{VALUE}};',
                ),
            )
        );

        $this->add_control(
            'search_types_background_active',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-type:has(input:checked) > label' => 'background-color: {{VALUE}};',
                ),
            )
        );

        $this->add_control(
            'search_types_border_color_active',
            array(
                'label'     => __( 'Border Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-type:has(input:checked) > label' => 'border-color: {{VALUE}};',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            array(
                'name'     => 'search_types_box_shadow_active',
                'selector' => '{{WRAPPER}} .gn-search-type:has(input:checked) > label',
            )
        );

        $this->end_controls_tab();

        $this->end_controls_tabs();

        $this->add_group_control(
            Group_Control_Border::get_type(),
            array(
                'name'      => 'search_types_border',
                'separator' => 'before',
                'selector'  => '{{WRAPPER}} .gn-search-types .gn-search-type > label',
            )
        );

        $this->add_responsive_control(
            'search_types_border_radius',
            array(
                'label'      => esc_html__( 'Border Radius', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', '%' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-types .gn-search-type > label' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'search_types_padding',
            array(
                'label'      => esc_html__( 'Padding', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-types .gn-search-type > label' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'search_types_margin',
            array(
                'label'      => esc_html__( 'Margin', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-types .gn-search-type > label' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'section_search_bar',
            array(
                'label'     => esc_html__( 'Search Bar', 'gigneo' ),
                'tab'       => Controls_Manager::TAB_STYLE,
            )
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            array(
                'name'     => 'search_bar_typo',
                'selector' => '{{WRAPPER}} .gn-search-bar .gn-search-input',
            )
        );

        $this->start_controls_tabs(
            'search_bar_input_style_tabs'
        );

        $this->start_controls_tab(
            'search_bar_input_normal_tab',
            array(
                'label' => esc_html__( 'Normal', 'gigneo' ),
            )
        );

        $this->add_control(
            'search_bar_input_text_color',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-bar .gn-search-input' => 'color: {{VALUE}}',
                ),
            )
        );

        $this->add_control(
            'search_bar_bg_color',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array( '{{WRAPPER}} .gn-search-bar' => 'background-color: {{VALUE}};' ),
            )
        );

        $this->add_control(
            'search_bar_input_placeholder_color',
            array(
                'label'     => esc_html__( 'Placeholder Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-bar .gn-search-input::placeholder' => 'color: {{VALUE}}',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            array(
                'name'     => 'search_bar_input_box_shadow',
                'selector' => '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-bar',
            )
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'search_bar_input_hover_tab',
            array(
                'label' => esc_html__( 'Hover', 'gigneo' ),
            )
        );

        $this->add_control(
            'search_bar_input_text_hover_color',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-bar:hover .gn-search-input' => 'color: {{VALUE}}',
                ),
            )
        );

        $this->add_control(
            'search_bar_bg_color_hover',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array( '{{WRAPPER}} .gn-search-bar:hover' => 'background-color: {{VALUE}};' ),
            )
        );

        $this->add_control(
            'search_bar_input_placeholder_hover_color',
            array(
                'label'     => esc_html__( 'Placeholder Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-bar:hover .gn-search-input::placeholder' => 'color: {{VALUE}}',
                ),
            )
        );

        $this->add_control(
            'search_bar_input_border_hover_color',
            array(
                'label'     => esc_html__( 'Border Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-bar:hover' => 'border-color: {{VALUE}}',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            array(
                'name'     => 'search_bar_input_box_shadow_hover',
                'selector' => '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-bar:hover',
            )
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'search_bar_input_style_focus_tab',
            array(
                'label' => esc_html__( 'Focus', 'gigneo' ),
            )
        );

        $this->add_control(
            'search_bar_input_text_focus_color',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-bar .gn-search-input:focus' => 'color: {{VALUE}}',
                ),
            )
        );

        $this->add_control(
            'search_bar_bg_color_focus',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array( '{{WRAPPER}} .gn-search-bar:has(.gn-search-input:focus), .gn-search-bar:focus' => 'background-color: {{VALUE}};' ),
            )
        );

        $this->add_control(
            'search_bar_input_placeholder_focus_color',
            array(
                'label'     => esc_html__( 'Placeholder Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-bar:has(.gn-search-input:focus) .gn-search-input::placeholder' => 'color: {{VALUE}}',
                ),
            )
        );

        $this->add_control(
            'search_bar_input_border_focus_color',
            array(
                'label'     => esc_html__( 'Border Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-bar:has(.gn-search-input:focus)' => 'border-color: {{VALUE}}',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            array(
                'name'     => 'search_bar_input_box_shadow_focus',
                'selector' => '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-bar:has(.gn-search-input:focus)',
            )
        );

        $this->end_controls_tab();

        $this->end_controls_tabs();

        $this->add_group_control(
            Group_Control_Border::get_type(),
            array(
                'name'     => 'search_bar_input_border',
                'selector' => '{{WRAPPER}} .gn-search-bar',
                'separator' => 'before',
            )
        );

        $this->add_responsive_control(
            'search_bar_input_border_radius',
            array(
                'label'      => esc_html__( 'Border Radius', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', '%', 'em', 'rem', 'custom' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-bar' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'search_bar_padding',
            array(
                'label'      => esc_html__( 'Padding', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-bar' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'search_bar_margin',
            array(
                'label'      => esc_html__( 'Margin', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', '%', 'em', 'rem', 'vw', 'custom' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-bar' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}',
                ),
            )
        );

        $this->add_control(
            'select_heading',
            array(
                'label'     => esc_html__( 'Select', 'gigneo' ),
                'type'      => Controls_Manager::HEADING,
                'separator' => 'before',
                'condition' => [
                    'layout' => '2',
                ],
            )
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            array(
                'name'     => 'select_typography',
                'condition' => [
                    'layout' => '2',
                ],
                'selector' => '{{WRAPPER}} .gn-search-types .gn-select2-dropdown.select2-container--default .select2-selection--single .select2-selection__rendered',
            )
        );

        $this->add_control(
            'select_color',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-search-types .gn-select2-dropdown.select2-container--default .select2-selection--single .select2-selection__rendered, .gn-ele-search-bar-wrapper.gn-search-bar-layout-2 .gn-select:before' => 'color: {{VALUE}};',
                ),
            )
        );

        $this->add_responsive_control(
            'select_icon_size',
            array(
                'label'     => esc_html__( 'Icon Size', 'gigneo' ),
                'type'      => Controls_Manager::SLIDER,
                'range'     => array(
                    'px' => array(
                        'min' => 6,
                        'max' => 300,
                    ),
                ),
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-types .gn-select:before' => 'font-size: {{SIZE}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'select_padding',
            array(
                'label'      => esc_html__( 'Padding', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'condition' => [
                    'layout' => '2',
                ],
                'selectors'  => array(
                    '.gn-search-types .gn-select2-dropdown.select2-container--default .select2-selection--single .select2-selection__rendered' =>
                        'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'select_margin',
            array(
                'label'      => esc_html__( 'Margin', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'condition' => [
                    'layout' => '2',
                ],
                'selectors'  => array(
                    '.gn-search-types .gn-select2-dropdown.select2-container--default .select2-selection--single .select2-selection__rendered' =>
                        'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_control(
            'select_dropdown_heading',
            array(
                'label'     => esc_html__( 'Select Dropdown', 'gigneo' ),
                'type'      => Controls_Manager::HEADING,
                'separator' => 'before',
                'condition' => [
                    'layout' => '2',
                ],
            )
        );

        $this->add_control(
            'select_dropdown_background',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-select2-dropdown .gn-search-type-select-dropdown.select2-dropdown .select2-results, .gn-select2-dropdown.select2-container .gn-search-type-select-dropdown.select2-dropdown' => 'background-color: {{VALUE}}',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            array(
                'name'     => 'select_dropdown_shadow',
                'selector' => '.gn-select2-dropdown .gn-search-type-select-dropdown.select2-dropdown .select2-results',
            )
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            array(
                'name'     => 'select_dropdown_border',
                'condition' => [
                    'layout' => '2',
                ],
                'selector' => '.gn-select2-dropdown .gn-search-type-select-dropdown.select2-dropdown .select2-results',
            )
        );

        $this->add_responsive_control(
            'select_dropdown_border_radius',
            array(
                'label'      => esc_html__( 'Border Radius', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'condition' => [
                    'layout' => '2',
                ],
                'size_units' => array( 'px', '%', 'em', 'rem', 'custom' ),
                'selectors'  => array(
                    '.gn-select2-dropdown .gn-search-type-select-dropdown.select2-dropdown .select2-results, .gn-select2-dropdown.select2-container .gn-search-type-select-dropdown.select2-dropdown' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
                ),
            )
        );

        $this->add_responsive_control(
            'select_dropdown_padding',
            array(
                'label'      => esc_html__( 'Padding', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'condition' => [
                    'layout' => '2',
                ],
                'size_units' => array( 'px', '%', 'em', 'rem', 'vw', 'custom' ),
                'selectors'  => array(
                    '.gn-select2-dropdown .gn-search-type-select-dropdown.select2-dropdown .select2-results' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}',
                ),
            )
        );

        $this->add_responsive_control(
            'select_dropdown_margin',
            array(
                'label'      => esc_html__( 'Margin', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'condition' => [
                    'layout' => '2',
                ],
                'size_units' => array( 'px', '%', 'em', 'rem', 'vw', 'custom' ),
                'selectors'  => array(
                    '.gn-select2-dropdown .gn-search-type-select-dropdown.select2-dropdown .select2-results' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}',
                ),
            )
        );

        $this->add_control(
            'dropdown_option_heading',
            array(
                'label'     => esc_html__( 'Dropdown Options', 'gigneo' ),
                'type'      => Controls_Manager::HEADING,
                'separator' => 'before',
                'condition' => [
                    'layout' => '2',
                ],
            )
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            array(
                'name'     => 'dropdown_option_typography',
                'condition' => [
                    'layout' => '2',
                ],
                'selector' => '.gn-select2-dropdown .gn-search-type-select-dropdown .select2-results__option',
            )
        );

        $this->add_responsive_control(
            'dropdown_option_option_spacing',
            array(
                'label'      => esc_html__( 'Space Between', 'gigneo' ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => array( 'px', 'em' ),
                'range'      => array(
                    'px' => array(
                        'min' => 0,
                        'max' => 50,
                    ),
                    'em' => array(
                        'min' => 0,
                        'max' => 5,
                    ),
                ),
                'condition' => [
                    'layout' => '2',
                ],
                'selectors'  => array(
                    '.gn-select2-dropdown .gn-search-type-select-dropdown .select2-results__option + .select2-results__option' =>
                        'margin-top: {{SIZE}}{{UNIT}};',
                ),
            )
        );

        $this->start_controls_tabs( 'dropdown_option_tabs' );

        $this->start_controls_tab(
            'dropdown_option_normal',
            array( 'label' => esc_html__( 'Normal', 'gigneo' ),
                'condition' => [
                    'layout' => '2',
                ],
            )
        );

        $this->add_control(
            'dropdown_option_color',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-select2-dropdown .gn-search-type-select-dropdown .select2-results__option' => 'color: {{VALUE}};',
                ),
            )
        );

        $this->add_control(
            'dropdown_option_background_color',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-select2-dropdown .gn-search-type-select-dropdown .select2-results__option' => 'background-color: {{VALUE}};',
                ),
            )
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'dropdown_option_hover',
            array( 'label' => esc_html__( 'Hover', 'gigneo' ),
                'condition' => [
                    'layout' => '2',
                ],
            )
        );

        $this->add_control(
            'dropdown_option_text_color_hover',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-select2-dropdown.select2-container--default .gn-search-type-select-dropdown .select2-results__option--highlighted[aria-selected]' => 'color: {{VALUE}};',
                ),
            )
        );

        $this->add_control(
            'dropdown_option_background_color_hover',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-select2-dropdown.select2-container--default .gn-search-type-select-dropdown .select2-results__option--highlighted[aria-selected]' => 'background-color: {{VALUE}};',
                ),
            )
        );

        $this->add_control(
            'dropdown_option_border_color_hover',
            array(
                'label'     => esc_html__( 'Border Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-select2-dropdown.select2-container--default .gn-search-type-select-dropdown .select2-results__option--highlighted[aria-selected]' => 'border-color: {{VALUE}};',
                ),
            )
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'dropdown_option_active',
            array( 'label' => esc_html__( 'Active', 'gigneo' ),
                'condition' => [
                    'layout' => '2',
                ],
            )
        );

        $this->add_control(
            'dropdown_option_color_active',
            array(
                'label'     => esc_html__( 'Text Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-select2-dropdown.select2-container--default .gn-search-type-select-dropdown .select2-results__option[aria-selected=true]' => 'color: {{VALUE}}; opacity: 1;',
                ),
            )
        );

        $this->add_control(
            'dropdown_option_background_color_active',
            array(
                'label'     => esc_html__( 'Background Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-select2-dropdown.select2-container--default .gn-search-type-select-dropdown .select2-results__option[aria-selected=true]' => 'background-color: {{VALUE}};',
                ),
            )
        );

        $this->add_control(
            'dropdown_option_border_color_active',
            array(
                'label'     => esc_html__( 'Border Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'condition' => [
                    'layout' => '2',
                ],
                'selectors' => array(
                    '.gn-select2-dropdown.select2-container--default .gn-search-type-select-dropdown .select2-results__option[aria-selected=true]' => 'border-color: {{VALUE}};',
                ),
            )
        );

        $this->end_controls_tab();

        $this->end_controls_tabs();

        $this->add_group_control(
            Group_Control_Border::get_type(),
            array(
                'name'      => 'dropdown_option_border',
                'separator' => 'before',
                'condition' => [
                    'layout' => '2',
                ],
                'selector'  => '.gn-select2-dropdown .gn-search-type-select-dropdown .select2-results__option',
            )
        );

        $this->add_responsive_control(
            'dropdown_option_border_radius',
            array(
                'label'      => esc_html__( 'Border Radius', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', '%' ),
                'condition' => [
                    'layout' => '2',
                ],
                'selectors'  => array(
                    '.gn-select2-dropdown .gn-search-type-select-dropdown .select2-results__option' =>
                        'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'dropdown_option_padding',
            array(
                'label'      => esc_html__( 'Padding', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'condition' => [
                    'layout' => '2',
                ],
                'selectors'  => array(
                    '.gn-select2-dropdown .gn-search-type-select-dropdown .select2-results__option' =>
                        'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_control(
            'button_heading',
            array(
                'label'     => esc_html__( 'Button', 'gigneo' ),
                'type'      => Controls_Manager::HEADING,
                'separator' => 'before',
            )
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            array(
                'name'     => 'button_typography',
                'label'    => esc_html__( 'Typography', 'gigneo' ),
                'selector' => '{{WRAPPER}} .gn-search-button',
            )
        );

        $this->add_responsive_control(
            'button_icon_size',
            array(
                'label'     => esc_html__( 'Icon Size', 'gigneo' ),
                'type'      => Controls_Manager::SLIDER,
                'range'     => array(
                    'px' => array(
                        'min' => 6,
                        'max' => 30,
                    ),
                ),
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-button svg' => 'height: {{SIZE}}{{UNIT}}; width: {{SIZE}}{{UNIT}};',
                    '{{WRAPPER}} .gn-search-button i' => 'font-size: {{SIZE}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'button_icon_position',
            array(
                'label'     => esc_html__( 'Icon Position', 'gigneo' ),
                'type'      => Controls_Manager::CHOOSE,
                'default'   => 'left',
                'options'   => array(
                    'row' => array(
                        'title' => esc_html__( 'Left', 'gigneo' ),
                        'icon'  => 'eicon-h-align-left',
                    ),
                    'row-reverse' => array(
                        'title' => esc_html__( 'Right', 'gigneo' ),
                        'icon'  => 'eicon-h-align-right',
                    ),
                ),
                'selectors' => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-bar .gn-search-button' => 'flex-direction: {{VALUE}};',
                ),
            )
        );

        $this->add_responsive_control(
            'button_space_between',
            array(
                'label'      => esc_html__( 'Space Between', 'gigneo' ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => array( 'px', '%', 'em' ),
                'range'      => array(
                    'px' => array(
                        'min' => 0,
                        'max' => 20,
                    ),
                ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-ele-search-bar-wrapper .gn-search-bar .gn-search-button' => 'gap: {{SIZE}}{{UNIT}};',
                ),
            )
        );

        $this->start_controls_tabs( 'btn_tabs' );

        $this->start_controls_tab(
            'btn_normal',
            array( 'label' => esc_html__( 'Normal', 'gigneo' ) )
        );

        $this->add_control(
            'btn_text_color',
            array(
                'label' => esc_html__( 'Text Color', 'gigneo' ),
                'type'  => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-button' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .gn-search-button svg path' => 'fill: {{VALUE}};',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'btn_background',
                'label' => esc_html__( 'Background', 'gigneo' ),
                'types' => [ 'classic', 'gradient' ],
                'selector' => '{{WRAPPER}} .gn-search-button',
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            array(
                'name'     => 'btn_shadow',
                'selector' => '{{WRAPPER}} .gn-search-button',
            )
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'btn_hover',
            array( 'label' => esc_html__( 'Hover', 'gigneo' ) )
        );

        $this->add_control(
            'btn_text_color_hover',
            array(
                'label' => esc_html__( 'Text Color', 'gigneo' ),
                'type'  => Controls_Manager::COLOR,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-button:hover' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .gn-search-button:hover svg path' => 'fill: {{VALUE}};',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'btn_background_hover',
                'label' => esc_html__( 'Background', 'gigneo' ),
                'types' => [ 'classic', 'gradient' ],
                'selector' => '{{WRAPPER}} .gn-search-button:hover',
            ]
        );

        $this->add_control(
            'btn_border_color_hover',
            array(
                'label'     => esc_html__( 'Border Color', 'gigneo' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => array(
                    '.gn-search-button:hover' => 'border-color: {{VALUE}};',
                ),
            )
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            array(
                'name'     => 'btn_shadow_hover',
                'selector' => '{{WRAPPER}} .gn-search-button:hover',
            )
        );

        $this->end_controls_tab();

        $this->end_controls_tabs();

        $this->add_group_control(
            Group_Control_Border::get_type(),
            array(
                'name'      => 'btn_border',
                'separator' => 'before',
                'selector'  => '{{WRAPPER}} .gn-search-button',
            )
        );

        $this->add_responsive_control(
            'btn_radius',
            array(
                'label'     => esc_html__( 'Border Radius', 'gigneo' ),
                'type'      => Controls_Manager::DIMENSIONS,
                'selectors' => array(
                    '{{WRAPPER}} .gn-search-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'btn_padding',
            array(
                'label'      => esc_html__( 'Padding', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->add_responsive_control(
            'btn_margin',
            array(
                'label'      => esc_html__( 'Margin', 'gigneo' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => array( 'px', 'em', '%' ),
                'selectors'  => array(
                    '{{WRAPPER}} .gn-search-button' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ),
            )
        );

        $this->end_controls_section();
	}

	/**
	 * Render widget output on the frontend.
	 *
	 * Uses a template file to separate PHP/HTML from logic.
	 */
	protected function render() {
		// Include the frontend template for the widget.
		require gigneo_get_template( 'elementor/widgets/search-bar' );
	}
}
