<?php
/**
 * Elementor Button Widget.
 *
 * Elementor widget that inserts an embbedable content into the page, from any given URL.
 *
 * @since 1.0.5
 */
class Elementor_Button_Widget extends \Elementor\Widget_Base {

	/**
	 * Get widget name.
	 *
	 * Retrieve Button widget name.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'button';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Button widget title.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'Buttons', 'endless-addons' );
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve Button widget icon.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'fa fa-boxes';
	}

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the Button widget belongs to.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'endless-elements' ];
	}

	/**
	 * Register Button widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.0.5
	 * @access protected
	 */
	protected function register_controls() {

		$this->start_controls_section(
			'default_section',
			[    
				'label' => __( 'Settings', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);

		$this->add_control(
			'show_button',
			[
				'label' => __( 'Show/Hide Button Area', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => __( 'Show', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'hide' => [
						'title' => __( 'Hide', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'show',
				'toggle' => true
			]
		);

		$this->add_control(
			'select_button_type',
			[
				'label' => __( 'Select Button Type', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'single' => __( 'Single', 'endless-addons' ),
					'multiple' => __( 'Multiple', 'endless-addons' )
				],
				'default' => 'single'
			]
		);

		$this->add_control(
			'show_button_section',
			[
				'label' => __( 'Show/Hide Button Section', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => __( 'Show', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'hide' => [
						'title' => __( 'Hide', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'show',
				'toggle' => true,
				'condition' => [
                    'select_button_type' => 'multiple'
                ]
			]
		);

		$this->add_control(
			'select_button_style',
			[
				'label' => __( 'Select Button Style', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'style-01' => __( 'Style 01', 'endless-addons' ),
					'style-02' => __( 'Style 02', 'endless-addons' ),
					'style-03' => __( 'Style 03', 'endless-addons' ),
					'style-04' => __( 'Style 04', 'endless-addons' ),
					'style-05' => __( 'Style 05', 'endless-addons' ),
					'style-06' => __( 'Style 06', 'endless-addons' ),
					'style-07' => __( 'Style 07', 'endless-addons' ),
					'style-08' => __( 'Style 08', 'endless-addons' ),
					'style-09' => __( 'Style 09', 'endless-addons' )
				],
				'default' => 'style-01'
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'button_section',
			[
				'label' => __( 'Button Section', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
				'condition' => [
                    'select_button_type' => 'multiple'
                ]
			]
		);

		$this->add_control(
			'section_title',
			[
				'label' => __( 'Section Title', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Title', 'endless-addons' ),
				'default'  => __( 'Design 1', 'endless-addons' )
			]
		);

		$this->add_control(
			'section_subtitle',
			[
				'label' => __( 'Section Subtitle', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Subtitle', 'endless-addons' ),
				'default'  => __( 'Regular Button style', 'endless-addons' )
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'section_background',
				'label' => __( 'Background', 'plugin-domain' ),
				'types' => [ 'classic', 'gradient', 'video' ],
				'selector' => '{{WRAPPER}} .ea-button-area',
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'button_content',
			[
				'label' => __( 'Button Content', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
				'condition' => [
                    'select_button_type' => 'single'
                ]
			]
		);

		$this->add_control(
            'single_btn_alignment',
            [
                'label' => esc_html__('Button Horizontal Alignment', 'endless-addons'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label_block' => true,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'endless-addons'),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'endless-addons'),
                        'icon' => 'fa fa-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'endless-addons'),
                        'icon' => 'fa fa-align-right',
                    ],
                ]
            ]
        );

		$this->add_control(
			'select_button_size',
			[
				'label' => __( 'Select Button Size', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'ex-large' => __( 'Extra Large', 'endless-addons' ),
					'large' => __( 'Large', 'endless-addons' ),
					'normal' => __( 'Normal', 'endless-addons' ),
					'small' => __( 'Small', 'endless-addons' )
				],
				'default' => 'ex-large'
			]
		);

		$this->add_control(
			'btn_icon', 
			[
				'label' => __( 'Button Icon', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::ICONS,
				'input_type' => 'icon',
				'show_label' => true
			]
		);

		$this->add_control(
			'btn_icon_position',
			[
				'label' => __( 'Select Icon Position', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'before' => __( 'Before Text', 'endless-addons' ),
					'after' => __( 'After Text', 'endless-addons' )
				],
				'default' => 'before'
			]
		);

		$this->add_control(
			'btn_icon_size',
			[
				'label' => __( 'Icon Size', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
                'range' => [
                    'px' => [
                        'min' => 20,
                        'max' => 100,
                        'step' => 1,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .ea-default-btn.ea-button-area i' => 'font-size: {{SIZE}}px;'
                ],
			]
		);

		$this->add_control(
			'btn_icon_color',
			[
				'label' => __( 'Icon Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-default-btn.ea-button-area i' => 'color: {{VALUE}}'
                ]
			]
		);

		$this->add_responsive_control(
            'btn_icon_spacing',
            [
                'label'     => esc_html__('Icon Spacing', 'endless-addons'),
                'type'      => \Elementor\Controls_Manager::SLIDER,
                'range'     => [
                    'px' => [
                        'max' => 60,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .ea-default-btn.ea-button-area .icon-before' => 'margin-right: {{SIZE}}px;',
                    '{{WRAPPER}} .ea-default-btn.ea-button-area .icon-after'  => 'margin-left: {{SIZE}}px;'
                ],
            ]
        );

		$this->add_control(
			'button_text_single',
			[
				'label' => __( 'Button Text', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Text', 'endless-addons' ),
				'default' => __( 'Button', 'endless-addons' )
			]
		);

		$this->add_control(
			'button_link_single',
			[
				'label' => __( 'Button Link', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::URL,
				'input_type' => 'url',
				'default' => [
					'url' => '#',
					'is_external' => true,
					'nofollow' => true
				]
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'button_content_active',
			[
				'label' => __( 'Button Content Active', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
				'condition' => [
                    'select_button_type' => 'multiple'
                ]
			]
		);

		$this->add_control(
			'active_section_title',
			[
				'label' => __( 'Section Title', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Title', 'endless-addons' ),
				'default'  => __( 'Button Active', 'endless-addons' )
			]
		);

		$this->add_control(
            'multiple_active_btn_alignment',
            [
                'label' => esc_html__('Button Horizontal Alignment', 'endless-addons'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label_block' => true,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'endless-addons'),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'endless-addons'),
                        'icon' => 'fa fa-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'endless-addons'),
                        'icon' => 'fa fa-align-right',
                    ],
                ]
            ]
        );

        $this->add_control(
			'btn_icon_size1',
			[
				'label' => __( 'Icon Size', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
                'range' => [
                    'px' => [
                        'min' => 20,
                        'max' => 100,
                        'step' => 1,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .ea-button-area .ea-button-card .ea-default-btn1 i' => 'font-size: {{SIZE}}px;'
                ],
			]
		);

		$this->add_control(
			'btn_icon_color1',
			[
				'label' => __( 'Icon Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-button-area .ea-button-card .ea-default-btn1 i' => 'color: {{VALUE}}'
                ]
			]
		);

        $this->add_control(
            'btn_icon_spacing1',
            [
                'label'     => esc_html__('Icon Spacing', 'endless-addons'),
                'type'      => \Elementor\Controls_Manager::SLIDER,
                'range'     => [
                    'px' => [
                        'max' => 60,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .ea-button-card .ea-default-btn1 .icon-before' => 'margin-right: {{SIZE}}px;',
                    '{{WRAPPER}} .ea-button-card .ea-default-btn1 .icon-after'  => 'margin-left: {{SIZE}}px;'
                ],
            ]
        );

		$repeater = new \Elementor\Repeater();

		$repeater->add_control(
			'select_button_size_active',
			[
				'label' => __( 'Select Button Size', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'ex-large' => __( 'Extra Large', 'endless-addons' ),
					'large' => __( 'Large', 'endless-addons' ),
					'normal' => __( 'Normal', 'endless-addons' ),
					'small' => __( 'Small', 'endless-addons' )
				],
				'default' => 'ex-large'
			]
		);

		$repeater->add_control(
			'btn_icon1', 
			[
				'label' => __( 'Button Icon', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::ICONS,
				'input_type' => 'icon',
				'show_label' => true
			]
		);

		$repeater->add_control(
			'btn_icon_position1',
			[
				'label' => __( 'Select Icon Position', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'before' => __( 'Before Text', 'endless-addons' ),
					'after' => __( 'After Text', 'endless-addons' )
				],
				'default' => 'before'
			]
		);

		$repeater->add_control(
			'button_text_active',
			[
				'label' => __( 'Button Text', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Text', 'endless-addons' ),
				'default' => __( 'Button', 'endless-addons' )
			]
		);

		$repeater->add_control(
			'button_link_active',
			[
				'label' => __( 'Button Link', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::URL,
				'input_type' => 'url',
				'default' => [
					'url' => '#',
					'is_external' => true,
					'nofollow' => true
				]
			]
		);

		$this->add_control(
			'single_button_active',
			[
				'label' => __( 'Single Button', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'default' => [
					[
						'list_title' => __( 'Single Button #1', 'endless-addons' ),
						'list_content' => __( 'Single Button Content', 'endless-addons' ),
					],
				
				],
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'button_content_hover',
			[
				'label' => __( 'Button Content Hover', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
				'condition' => [
                    'select_button_type' => 'multiple'
                ]
			]
		);

		$this->add_control(
			'hover_section_title',
			[
				'label' => __( 'Section Title', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Title', 'endless-addons' ),
				'default'  => __( 'Button Hover', 'endless-addons' )
			]
		);

		$this->add_control(
            'multiple_hover_btn_alignment',
            [
                'label' => esc_html__('Button Horizontal Alignment', 'endless-addons'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label_block' => true,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'endless-addons'),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'endless-addons'),
                        'icon' => 'fa fa-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'endless-addons'),
                        'icon' => 'fa fa-align-right',
                    ],
                ]
            ]
        );

        $this->add_control(
			'btn_icon_size2',
			[
				'label' => __( 'Icon Size', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
                'range' => [
                    'px' => [
                        'min' => 20,
                        'max' => 100,
                        'step' => 1,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .ea-button-area .ea-button-card .ea-default-btn2 i' => 'font-size: {{SIZE}}px;'
                ],
			]
		);

		$this->add_control(
			'btn_icon_color2',
			[
				'label' => __( 'Icon Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-button-area .ea-button-card .ea-default-btn2 i' => 'color: {{VALUE}}'
                ]
			]
		);

        $this->add_control(
            'btn_icon_spacing2',
            [
                'label'     => esc_html__('Icon Spacing', 'endless-addons'),
                'type'      => \Elementor\Controls_Manager::SLIDER,
                'range'     => [
                    'px' => [
                        'max' => 60,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .ea-button-card .ea-default-btn2 .icon-before' => 'margin-right: {{SIZE}}px;',
                    '{{WRAPPER}} .ea-button-card .ea-default-btn2 .icon-after'  => 'margin-left: {{SIZE}}px;'
                ],
            ]
        );

		$repeater = new \Elementor\Repeater();

		$repeater->add_control(
			'select_button_size_hover',
			[
				'label' => __( 'Select Button Size', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'ex-large' => __( 'Extra Large', 'endless-addons' ),
					'large' => __( 'Large', 'endless-addons' ),
					'normal' => __( 'Normal', 'endless-addons' ),
					'small' => __( 'Small', 'endless-addons' )
				],
				'default' => 'ex-large'
			]
		);

		$repeater->add_control(
			'btn_icon2', 
			[
				'label' => __( 'Button Icon', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::ICONS,
				'input_type' => 'icon',
				'show_label' => true
			]
		);

		$repeater->add_control(
			'btn_icon_position2',
			[
				'label' => __( 'Select Icon Position', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'before' => __( 'Before Text', 'endless-addons' ),
					'after' => __( 'After Text', 'endless-addons' )
				],
				'default' => 'before'
			]
		);

		$repeater->add_control(
			'button_text_hover',
			[
				'label' => __( 'Button Text', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Text', 'endless-addons' ),
				'default' => __( 'Button', 'endless-addons' )
			]
		);

		$repeater->add_control(
			'button_link_hover',
			[
				'label' => __( 'Button Link', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::URL,
				'input_type' => 'url',
				'default' => [
					'url' => '#',
					'is_external' => true,
					'nofollow' => true
				]
			]
		);

		$this->add_control(
			'single_button_hover',
			[
				'label' => __( 'Single Button', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'default' => [
					[
						'list_title' => __( 'Single Button #1', 'endless-addons' ),
						'list_content' => __( 'Single Button Content', 'endless-addons' ),
					],
				
				],
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'section_style',
			[
				'label' => __( 'Section Style', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
				'condition' => [
                    'select_button_type' => 'multiple'
                ]
			]
		);

		$this->add_control(
			'section_title_color',
			[
				'label' => __( 'Section Title Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-button-area .ea-button-title h2' => 'color: {{VALUE}}'
                ],
                'condition' => [
                    'select_button_type' => 'multiple'
                ]
			]
		);

		$this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'section_title_typography',
                'label' => __( 'Section Title Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-button-area .ea-button-title h2',
                'condition' => [
                    'select_button_type' => 'multiple'
                ]
            ],
        );

        $this->add_control(
			'section_subtitle_color',
			[
				'label' => __( 'Section Subtitle Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-button-area .ea-button-title h3' => 'color: {{VALUE}}'
                ],
                'condition' => [
                    'select_button_type' => 'multiple'
                ]
			]
		);

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'section_subtitle_typography',
                'label' => __( 'Section Subtitle Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-button-area .ea-button-title h3',
                'condition' => [
                    'select_button_type' => 'multiple'
                ]
            ]
        );

        $this->add_control(
			'button_title_color',
			[
				'label' => __( 'Button Side Title Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-button-area ul li h4' => 'color: {{VALUE}}'
                ],
                'condition' => [
                    'select_button_type' => 'multiple'
                ]
			]
		);

		$this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'button_title_typography',
                'label' => __( 'Button Side Title Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-button-area ul li h4',
                'condition' => [
                    'select_button_type' => 'multiple'
                ]
            ],
        );

        $this->end_controls_section();

        $this->start_controls_section(
			'button_style',
			[
				'label' => __( 'Button Style', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE
			]
		);

		$this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'button_text_typography',
                'label' => __( 'Button Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-button-area .ea-default-btn, .ea-default-btn'
            ],
        );

        $this->add_control(
		    'button_animation',
		    [
		        'label' => __('Button Animation', 'endless-addons'),
		        'type' => \Elementor\Controls_Manager::SELECT,
		        'default' => '',
		        'options' => [
		            '' => __('None', 'endless-addons'),
		            'btn-glow-on-hover' => __('Glow On Hover', 'endless-addons'),
		            'btn-pulse-on-hover' => __('Pulse On Hover', 'endless-addons'),
		            'btn-swipe-on-hover' => __('Swipe On Hover', 'endless-addons'),
		            'btn-still-in-view' => __('Still In View', 'endless-addons'),
		            'btn-focus-in-ring' => __('Focus In Ring', 'endless-addons'),
		        ],
		        'frontend_available' => true
		    ]
		);

        $this->add_control(
            'button_padding',
            [
                'label'         => esc_html__( 'Button Padding', 'endless-addons' ),
                'type'          => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units'    => [ 'px', '%', 'em' ],
                'selectors'     => [
                    '{{WRAPPER}} .ea-default-btn' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'button_margin',
            [
                'label'         => esc_html__( 'Button Margin', 'endless-addons' ),
                'type'          => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units'    => [ 'px', '%', 'em' ],
                'selectors'     => [
                    '{{WRAPPER}} .ea-default-btn' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
			'button_height',
			[
				'label' => __( 'Button Height', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 50,
						'max' => 500
					]
				],
				'selectors' => [
					'{{WRAPPER}} .ea-default-btn.ea-button-area, .ea-button-area .ea-default-btn' => 'height: {{SIZE}}{{UNIT}}',
				],
			]
		);

		$this->add_control(
			'button_width',
			[
				'label' => __( 'Button Width', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 50,
						'max' => 500
					]
				],
				'selectors' => [
					'{{WRAPPER}} .ea-default-btn.ea-button-area, .ea-button-area .ea-default-btn' => 'width: {{SIZE}}{{UNIT}}',
				],
			]
		);

		$this->add_control(
			'show_button_border',
			[
				'label' => __( 'Show/Hide Button Border', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => __( 'Show', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'hide' => [
						'title' => __( 'Hide', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'show',
				'toggle' => true,
				'condition' => [
                    'select_button_style' => array('style-03', 'style-04', 'style-07', 'style-09')
                ]
			]
		);

		$this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name'     => 'ea_button_border',
                'selector' => '{{WRAPPER}} .ea-button-area .ea-default-btn',
            ]
        );

		$this->add_control(
			'button_border_color',
			[
				'label' => __( 'Button Border Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-default-btn, .ea-default-btn::before' => 'border-color: {{VALUE}} !important'
                ],
                'condition' => [
                    'show_button_border' => 'show',
                    'select_button_style' => array('style-03', 'style-04', 'style-07', 'style-09')
                ]
			]
		);

		$this->add_control(
            'button_border_radius',
            [
                'label' => __( 'Border Radius', 'endless-addons' ),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'separator' => 'after',
                'selectors' => [
                    '{{WRAPPER}} .ea-default-btn, .ea-default-btn::before' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Box_Shadow::get_type(),
            [
                'name'     => 'button_box_shadow',
                'selector' => '{{WRAPPER}} .ea-button-area .ea-default-btn',
            ]
        );

		$this->end_controls_section();

		$this->start_controls_section(
			'tab_button_color',
			[
				'label' => __( 'Button Color', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE
			]
		);

		$this->add_control(
			'button_bg_color',
			[
				'label' => __( 'Button Background Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-default-btn' => 'background: {{VALUE}}'
                ],
			]
		);

		$this->add_control(
			'button_color',
			[
				'label' => __( 'Button Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-default-btn' => 'color: {{VALUE}}'
                ],
			]
		);

		$this->add_control(
			'button_bg_hover_color',
			[
				'label' => __( 'Button Background Hover Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-default-btn:hover, .btn-swipe-on-hover .ea-default-btn:hover::before' => 'background: {{VALUE}}'
                ],
			]
		);

		$this->add_control(
			'button_hover_color',
			[
				'label' => __( 'Button Hover Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-default-btn:hover, .btn-swipe-on-hover .ea-default-btn:hover' => 'color: {{VALUE}}'
                ],
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'_section_overlay_style',
			[
				'label' => __('Background Overlay', 'endless-addons'),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
				'condition' => [
                    'select_button_type' => 'multiple',
                    'select_button_style' => array('style-01', 'style-03', 'style-05', 'style-07', 'style-09'),
                ]
			]
		);

		$this->start_controls_tabs('_tabs_overlay_style');

		$this->start_controls_tab(
			'_tab_overlay_normal',
			[
				'label' => __('Normal', 'endless-addons'),
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name'     => 'hover_overlay_normal',
				'label' => __('Background', 'endless-addons'),
				'show_label' => true,
				'types' => ['classic', 'gradient'],
				'exclude' => [
					'classic' => 'image'
				],
				'selector' => '{{WRAPPER}} .ea-main-btn-area',
			]
		);

		$this->end_controls_tab();

		$this->start_controls_tab(
			'_tab_overlay_hover',
			[
				'label' => __('Hover', 'endless-addons'),
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name'     => 'hover_overlay_hover',
				'label' => __('Background', 'endless-addons'),
				'show_label' => true,
				'types' => ['classic', 'gradient'],
				'exclude' => [
					'classic' => 'image'
				],
				'selector' => '{{WRAPPER}} .ea-main-btn-area:hover',
			]
		);

		$this->end_controls_tab();

		$this->end_controls_tabs();

		$this->end_controls_section();

		require plugin_dir_path( dirname( __FILE__ ) ) . 'class-endless-addons-tooltip.php';

		require plugin_dir_path( dirname( __FILE__ ) ) . 'floating/ea-button-floating.php';

	}

	/**
	 * Render Button widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.5
	 * @access protected
	 */
	protected function render() {

		$settings = $this->get_settings_for_display(); 

		if( $settings['single_btn_alignment'] == 'left' ) : 
		    $this->add_render_attribute('single_btn_align', 'class', 'ea-btn-align is-btn-left');
		elseif( $settings['single_btn_alignment'] == 'center' ) :
            $this->add_render_attribute('single_btn_align', 'class', 'ea-btn-align is-btn-center');
		elseif( $settings['single_btn_alignment'] == 'right' ) :
            $this->add_render_attribute('single_btn_align', 'class', 'ea-btn-align is-btn-right');
        else: $this->add_render_attribute('single_btn_align', 'class', 'ea-btn-align');
        endif; 

        if( $settings['multiple_active_btn_alignment'] == 'left' ) : 
		    $this->add_render_attribute('multiple_active_btn_align', 'class', 'ea-multi-active-btn-align is-btn-left');
		elseif( $settings['multiple_active_btn_alignment'] == 'center' ) :
            $this->add_render_attribute('multiple_active_btn_align', 'class', 'ea-multi-active-btn-align is-btn-center');
		elseif( $settings['multiple_active_btn_alignment'] == 'right' ) :
            $this->add_render_attribute('multiple_active_btn_align', 'class', 'ea-multi-active-btn-align is-btn-right');
        else: $this->add_render_attribute('multiple_active_btn_align', 'class', 'ea-multi-active-btn-align');
        endif; 

        if( $settings['multiple_hover_btn_alignment'] == 'left' ) : 
		    $this->add_render_attribute('multiple_hover_btn_align', 'class', 'ea-multi-hover-btn-align is-btn-left');
		elseif( $settings['multiple_hover_btn_alignment'] == 'center' ) :
            $this->add_render_attribute('multiple_hover_btn_align', 'class', 'ea-multi-hover-btn-align is-btn-center');
		elseif( $settings['multiple_hover_btn_alignment'] == 'right' ) :
            $this->add_render_attribute('multiple_hover_btn_align', 'class', 'ea-multi-hover-btn-align is-btn-right');
        else: $this->add_render_attribute('multiple_hover_btn_align', 'class', 'ea-multi-hover-btn-align');
        endif; 
        
        // Tooltip Position 
        if( $settings['ea_advanced_tooltip_position'] == 'top' ) : 
		    $this->add_render_attribute('btn_tooltip_position', 'class', 'ea-tooltip-top');
		elseif( $settings['ea_advanced_tooltip_position'] == 'bottom' ) :
            $this->add_render_attribute('btn_tooltip_position', 'class', 'ea-tooltip-bottom');
        endif;

		if( $settings['select_button_style'] == 'style-01' ) :
        	$ea_button_area = 'pb-70';
        	$ea_button_col_1 = '';
        	$ea_button_col_2 = '';
        	$ea_button_col_3 = '';
        	$ea_bg_title = '';
        	$ea_button_title = '';
        	$ea_button_card1 = ''; 
        	$ea_button_card2 = '';
        	$ea_default_btn = '';
        elseif( $settings['select_button_style'] == 'style-02' ) :
        	$ea_button_area = 'style-two';
        	$ea_button_col_1 = 'pl-0';
        	$ea_button_col_2 = 'pr-0';
        	$ea_button_col_3 = 'pl-0 pr-0';
        	$ea_bg_title = 'ea-bg-title';
        	$ea_button_title = 'style-two mb-0';
        	$ea_button_card1 = 'bg-color-fff7f2 mb-0'; 
        	$ea_button_card2 = 'bg-color-fffbf9 mb-0';
        	$ea_default_btn = 'btn-style-two';
        elseif( $settings['select_button_style'] == 'style-03' ) :
        	$ea_button_area = 'pt-100 pb-70';
        	$ea_button_col_1 = '';
        	$ea_button_col_2 = '';
        	$ea_button_col_3 = '';
        	$ea_bg_title = '';
        	$ea_button_title = '';
        	$ea_button_card1 = ''; 
        	$ea_button_card2 = '';
        	$ea_default_btn = 'btn-style-three';
        elseif( $settings['select_button_style'] == 'style-04' ) :
        	$ea_button_area = 'style-two style-four';
        	$ea_button_col_1 = 'pl-0';
        	$ea_button_col_2 = 'pr-0';
        	$ea_button_col_3 = 'pl-0';
        	$ea_bg_title = 'ea-bg-title';
        	$ea_button_title = 'style-two mb-0';
        	$ea_button_card1 = 'bg-color-fff7f2 bg-color-f0fbf7 mb-0'; 
        	$ea_button_card2 = 'bg-color-fffbf9 bg-color-e7f8f2 mb-0';
        	$ea_default_btn = 'btn-style-four';
        elseif( $settings['select_button_style'] == 'style-05' ) :
        	$ea_button_area = 'pt-100 pb-70';
        	$ea_button_col_1 = '';
        	$ea_button_col_2 = '';
        	$ea_button_col_3 = '';
        	$ea_bg_title = '';
        	$ea_button_title = '';
        	$ea_button_card1 = ''; 
        	$ea_button_card2 = '';
        	$ea_default_btn = 'btn-style-five';
        elseif( $settings['select_button_style'] == 'style-06' ) :
        	$ea_button_area = 'style-two style-six';
        	$ea_button_col_1 = 'pl-0';
        	$ea_button_col_2 = 'pr-0';
        	$ea_button_col_3 = 'pr-0 pl-0';
        	$ea_bg_title = 'ea-bg-title';
        	$ea_button_title = 'style-two mb-0';
        	$ea_button_card1 = 'bg-color-fff7f2 bg-color-e7faff mb-0'; 
        	$ea_button_card2 = 'bg-color-fffbf9 bg-color-f1fbfe mb-0';
        	$ea_default_btn = 'btn-style-six';
        elseif( $settings['select_button_style'] == 'style-07' ) :
        	$ea_button_area = 'pt-100 pb-70';
        	$ea_button_col_1 = '';
        	$ea_button_col_2 = '';
        	$ea_button_col_3 = '';
        	$ea_bg_title = '';
        	$ea_button_title = '';
        	$ea_button_card1 = ''; 
        	$ea_button_card2 = '';
        	$ea_default_btn = 'btn-style-seven';
        elseif( $settings['select_button_style'] == 'style-08' ) :
        	$ea_button_area = 'style-two style-eight';
        	$ea_button_col_1 = 'pl-0';
        	$ea_button_col_2 = 'pr-0';
        	$ea_button_col_3 = 'pl-0';
        	$ea_bg_title = 'ea-bg-title';
        	$ea_button_title = 'style-two mb-0';
        	$ea_button_card1 = 'bg-color-fff7f2 bg-color-f7f8fb mb-0'; 
        	$ea_button_card2 = 'bg-color-fffbf9 bg-color-eff1f6 mb-0';
        	$ea_default_btn = 'btn-style-eight';
        elseif( $settings['select_button_style'] == 'style-09' ) :
        	$ea_button_area = 'style-nine bg-shape pt-100 pb-70';
        	$ea_button_col_1 = '';
        	$ea_button_col_2 = '';
        	$ea_button_col_3 = '';
        	$ea_bg_title = '';
        	$ea_button_title = '';
        	$ea_button_card1 = ''; 
        	$ea_button_card2 = '';
        	$ea_default_btn = 'btn-style-nine';
        endif;
        
        if( $settings['select_button_size'] == 'ex-large' ) :
        	$select_button_size = 'extra-large';
        elseif( $settings['select_button_size'] == 'large' ) :
        	$select_button_size = 'large';
        elseif( $settings['select_button_size'] == 'normal' ) :
        	$select_button_size = 'normal';
        elseif( $settings['select_button_size'] == 'small' ) :
        	$select_button_size = 'small';
        endif;

        if( $settings['show_button_section'] == 'show' ) :
        	$multiple_button_col = 'col-lg-4 col-md-6';
        elseif( $settings['show_button_section'] == 'hide' ) :
        	$multiple_button_col = 'col-lg-6 col-md-6';
        endif;

		if( $settings['show_button'] == 'show' ) : ?>

			<!-- Start Button Design Area -->
			<?php if( $settings['select_button_type'] == 'single' ) : ?>
				<div class="ea-button-area ea-main-btn-area ea-elementor-floating">
					<div class="container"> 
						<?php if( ! $settings['button_text_single'] == '' ) :
							$target = $settings['button_link_single']['is_external'] ? ' target="_blank"' : '';
			                $nofollow = $settings['button_link_single']['nofollow'] ? ' rel="nofollow"' : ''; ?>
			                <div class="<?php echo esc_attr($settings['button_animation']); ?>">
				                <div <?php echo $this->get_render_attribute_string('single_btn_align'); ?>>
									<a href="<?php echo esc_url( $settings['button_link_single']['url'] ); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="ea-default-btn ea-button-area ea-elementor-floating <?php echo esc_attr($ea_default_btn); ?> <?php echo esc_attr($select_button_size); ?>">
										<?php if( $settings['btn_icon_position'] == 'before' ) : ?>
											<span class="icon-before">
												<?php endad_render_icon( $settings, 'icon', 'btn_icon' ); ?>
											</span>
										<?php endif; ?> 
					                    <?php echo esc_html__( $settings['button_text_single'] ); ?>
					                    <?php if( $settings['btn_icon_position'] == 'after' ) : ?>
											<span class="icon-after">
												<?php endad_render_icon( $settings, 'icon', 'btn_icon' ); ?>
											</span>
										<?php endif; ?>
					                </a>
					                <?php if( $settings['ea_advanced_tooltip_enable'] == 'show' ) : ?>
						                <div <?php echo $this->get_render_attribute_string('btn_tooltip_position'); ?>>
						                	<?php if( $settings['ea_advanced_tooltip_arrow'] == 'true' ) : ?>
							                    <span class="ea-advanced-tooltip-content ea-btn-arrow"><?php echo wp_kses_post($settings['ea_advanced_tooltip_content']); ?></span>
							                <?php else: ?>
							                    <span class="ea-advanced-tooltip-content"><?php echo wp_kses_post($settings['ea_advanced_tooltip_content']); ?></span>
							                <?php endif; ?>
							            </div>
						            <?php endif; ?>
					            </div>
					        </div>
		                <?php endif; ?>
		            </div>
	            </div>
            <?php elseif( $settings['select_button_type'] == 'multiple' ) : ?>
		        <div class="ea-button-area ea-main-btn-area ea-elementor-floating <?php echo esc_attr($ea_button_area); ?>">
		            <div class="container">
		                <div class="row align-items-center">
		                	<?php if( $settings['select_button_style'] == 'style-01' || $settings['select_button_style'] == 'style-03' || $settings['select_button_style'] == 'style-04' || $settings['select_button_style'] == 'style-05' || $settings['select_button_style'] == 'style-07' || $settings['select_button_style'] == 'style-08' || $settings['select_button_style'] == 'style-09' ) : ?>
			                	<?php if( $settings['show_button_section'] == 'show' ) : ?>
				                    <div class="col-lg-4 col-md-6 <?php echo esc_attr($ea_button_col_1); ?>">
				                    	<div class="<?php echo esc_attr($ea_bg_title); ?>">
				                            <div class="ea-button-title <?php echo esc_attr($ea_button_title); ?>">
					                            <h2>
					                            	<?php echo esc_html__($settings['section_title']); ?>
					                            </h2>
					                            <h3>
					                            	<?php echo esc_html__($settings['section_subtitle']); ?>
					                            </h3>
				                            </div>
				                        </div>
				                    </div>
				                <?php endif; ?>
			                <?php endif; ?>
		                    <div class="<?php echo esc_attr($multiple_button_col); ?> <?php echo esc_attr($ea_button_col_2); ?>">
		                    	<div <?php echo $this->get_render_attribute_string('multiple_active_btn_align'); ?>>
			                        <ul class="ea-button-card <?php echo esc_attr($ea_button_card1); ?>">
			                        	<?php foreach ( $settings['single_button_active'] as $item ) : 
			                        		if( $item['select_button_size_active'] == 'ex-large' ) :
									        	$select_button_size_active = 'extra-large';
									        elseif( $item['select_button_size_active'] == 'large' ) :
									        	$select_button_size_active = 'large';
									        elseif( $item['select_button_size_active'] == 'normal' ) :
									        	$select_button_size_active = 'normal';
									        elseif( $item['select_button_size_active'] == 'small' ) :
									        	$select_button_size_active = 'small';
									        endif;
			                        		$target1 = $item['button_link_active']['is_external'] ? ' target="_blank"' : '';
		                                    $nofollow1 = $item['button_link_active']['nofollow'] ? ' rel="nofollow"' : ''; ?>
				                            <li>
				                            	<div class="<?php echo esc_attr($settings['button_animation']); ?>">
					                                <a href="<?php echo esc_url( $item['button_link_active']['url'] ); ?>" <?php echo wp_kses_post( $target1 ); ?> <?php echo wp_kses_post( $nofollow1 ); ?> class="ea-default-btn ea-default-btn1 <?php echo esc_attr($ea_default_btn); ?> <?php echo esc_attr($select_button_size_active); ?>">
					                                	<?php if( $item['btn_icon_position1'] == 'before' ) : ?>
															<span class="icon-before">
																<?php endad_render_icon( $item, 'icon', 'btn_icon1' ); ?>
															</span>
														<?php endif; ?> 
									                    <?php echo esc_html( $item['button_text_active'] ); ?>
									                    <?php if( $item['btn_icon_position1'] == 'after' ) : ?>
															<span class="icon-after">
																<?php endad_render_icon( $item, 'icon', 'btn_icon1' ); ?>
															</span>
														<?php endif; ?>
					                                </a>
					                            </div>
				                            </li>
			                            <?php endforeach; ?>
	                                    <?php if( ! $settings['active_section_title'] == '' ) : ?>
				                            <li>
				                                <h4><?php echo esc_html__($settings['active_section_title']); ?></h4>
				                            </li>
			                            <?php endif; ?>
			                        </ul>
			                    </div>
		                    </div>
		                    <div class="<?php echo esc_attr($multiple_button_col); ?> <?php echo esc_attr($ea_button_col_3); ?>">
		                    	<div <?php echo $this->get_render_attribute_string('multiple_hover_btn_align'); ?>>
			                        <ul class="ea-button-card <?php echo esc_attr($ea_button_card2); ?>">
			                            <?php foreach ( $settings['single_button_hover'] as $item ) : 
			                        		if( $item['select_button_size_hover'] == 'ex-large' ) :
									        	$select_button_size_hover = 'extra-large';
									        elseif( $item['select_button_size_hover'] == 'large' ) :
									        	$select_button_size_hover = 'large';
									        elseif( $item['select_button_size_hover'] == 'normal' ) :
									        	$select_button_size_hover = 'normal';
									        elseif( $item['select_button_size_hover'] == 'small' ) :
									        	$select_button_size_hover = 'small';
									        endif;
			                        		$target2 = $item['button_link_hover']['is_external'] ? ' target="_blank"' : '';
		                                    $nofollow2 = $item['button_link_hover']['nofollow'] ? ' rel="nofollow"' : ''; ?>
				                            <li>
				                            	<div class="<?php echo esc_attr($settings['button_animation']); ?>">
					                                <a href="<?php echo esc_url( $item['button_link_hover']['url'] ); ?>" <?php echo wp_kses_post( $target2 ); ?> <?php echo wp_kses_post( $nofollow2 ); ?> class="ea-default-btn ea-default-btn2 hover <?php echo esc_attr($ea_default_btn); ?> <?php echo esc_attr($select_button_size_hover); ?>">
					                                	<?php if( $item['btn_icon_position2'] == 'before' ) : ?>
															<span class="icon-before">
																<?php endad_render_icon( $item, 'icon', 'btn_icon2' ); ?>
															</span>
														<?php endif; ?> 
									                    <?php echo esc_html( $item['button_text_hover'] ); ?>
									                    <?php if( $item['btn_icon_position2'] == 'after' ) : ?>
															<span class="icon-after">
																<?php endad_render_icon( $item, 'icon', 'btn_icon2' ); ?>
															</span>
														<?php endif; ?>
					                                </a>
					                            </div>
				                            </li>
			                            <?php endforeach; ?>
			                            <?php if( ! $settings['hover_section_title'] == '' ) : ?>
				                            <li>
				                                <h4><?php echo esc_html__($settings['hover_section_title']); ?></h4>
				                            </li>
			                            <?php endif; ?>
			                        </ul>
			                    </div>
		                    </div>
		                    <?php if( $settings['select_button_style'] == 'style-02' || $settings['select_button_style'] == 'style-06' ) : ?>
			                	<?php if( $settings['show_button_section'] == 'show' ) : ?>
				                    <div class="col-lg-4 col-md-6 <?php echo esc_attr($ea_button_col_1); ?>">
				                        <div class="<?php echo esc_attr($ea_bg_title); ?>">
				                            <div class="ea-button-title <?php echo esc_attr($ea_button_title); ?>">
					                            <h2>
					                            	<?php echo esc_html__($settings['section_title']); ?>
					                            </h2>
					                            <h3>
					                            	<?php echo esc_html__($settings['section_subtitle']); ?>
					                            </h3>
				                            </div>
				                        </div>
				                    </div>
				                <?php endif; ?>
			                <?php endif; ?>
		                </div>
		            </div>
		        </div>
	        <?php endif; ?>
	        <!-- End Button Design Area -->

	        <?php if( $settings['show_button_border'] == 'hide' ) : ?>
	        	<style type="text/css">
	        		.ea-default-btn, .ea-default-btn::before {
	        			border: none !important;
	        		}
	        	</style>
	        <?php endif;

        endif;

    }

}
