<?php

namespace Elementor;

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


class Rivax_Advanced_Button_Widget extends Widget_Base {

    public function get_name() {
        return 'rivax-advanced-button';
    }

    public function get_title() {
        return esc_html__('Advanced Button', 'newsfy');
    }

    public function get_icon() {
        return 'eicon-button rivax-e-icon';
    }

    protected function get_html_wrapper_class() {
        return $this->get_name() . '-widget';
    }

    public function get_categories() {
        return ['rivax-elements'];
    }

    public function get_style_depends() {
        return [ 'rivax-advanced-button' ];
    }

    protected function register_controls() {
        $this->start_controls_section(
            'section_advanced_button',
            [
                'label' => esc_html__( 'Advanced Button', 'newsfy' ),
                'tab'   => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'button_style',
            [
                'label'   => esc_html__( 'Style', 'newsfy' ),
                'type'    => Controls_Manager::SELECT,
                'default' => '1',
                'options' => [
                    '1'      => esc_html__( 'Style 1', 'newsfy' ),
                    '2'      => esc_html__( 'Style 2', 'newsfy' ),
                    '3'      => esc_html__( 'Style 3', 'newsfy' ),
                    '4'      => esc_html__( 'Style 4', 'newsfy' ),
                    '5'      => esc_html__( 'Style 5', 'newsfy' ),
                    '6'      => esc_html__( 'Style 6', 'newsfy' ),
                    '7'      => esc_html__( 'Style 7', 'newsfy' ),
                    '8'      => esc_html__( 'Style 8', 'newsfy' ),
                    '9'      => esc_html__( 'Style 9', 'newsfy' ),
                    '10'      => esc_html__( 'Style 10', 'newsfy' ),
                    '11'      => esc_html__( 'Style 11', 'newsfy' ),
                    '12'     => esc_html__( 'Style 12', 'newsfy' ),
                    '13'     => esc_html__( 'Style 13', 'newsfy' ),
                    '14'     => esc_html__( 'Style 14', 'newsfy' ),
                    '15'     => esc_html__( 'Style 15', 'newsfy' ),
                    '16'     => esc_html__( 'Style 16', 'newsfy' ),
                    '17'     => esc_html__( 'Style 17', 'newsfy' ),
                ],
            ]
        );

        $this->add_control(
            'button_skew',
            [
                'label'     => esc_html__( 'Skew Style', 'newsfy' ),
                'type'      => Controls_Manager::SWITCHER,
                'prefix_class' => 'btn-skew-',
            ]
        );

        $this->add_control(
            'button_hover_animation',
            [
                'label'         => esc_html__( 'Hover Animation', 'newsfy' ),
                'type'          => Controls_Manager::HOVER_ANIMATION,
            ]
        );

        $this->add_control(
            'title_animation',
            [
                'label'   => esc_html__( 'Title Animation', 'newsfy' ),
                'type'    => Controls_Manager::SELECT,
                'options' => [
                    ''                 => esc_html__( 'None', 'newsfy' ),
                    'title-up'         => esc_html__( 'Title Up', 'newsfy' ),
                    'title-left'       => esc_html__( 'Title Left', 'newsfy' ),
                    'icon-fade'        => esc_html__( 'Icon Fade', 'newsfy' ),
                    'icon-up'        => esc_html__( 'Icon Up', 'newsfy' ),
                ],
                'condition' => [
                    'button_style!' => ['12', '13'],
                ],
            ]
        );

        $this->add_control(
            'button_text',
            [
                'label'       => esc_html__( 'Title', 'newsfy' ),
                'type'        => Controls_Manager::TEXT,
                'default'     => esc_html__( 'Read More', 'newsfy' ),
                'placeholder' => esc_html__( 'Type Button Title', 'newsfy' ),
            ]
        );

        $this->add_control(
            'button_url',
            [
                'label'         => esc_html__( 'Link', 'newsfy' ),
                'type'          => Controls_Manager::URL,
                'placeholder'   => esc_html__( 'https://your-link.com', 'newsfy' ),
            ]
        );


        $this->add_responsive_control(
            'button_align',
            [
                'label' => esc_html__( 'Alignment', 'newsfy' ),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'left' => [
                        'title' => esc_html__( 'Left', 'newsfy' ),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__( 'Center', 'newsfy' ),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__( 'Right', 'newsfy' ),
                        'icon' => 'eicon-text-align-right',
                    ]
                ],
                'selectors' => [
                    '{{WRAPPER}}' => 'text-align: {{VALUE}};'
                ]
            ]
        );


	    $this->add_control('button_show_icon',
		    [
			    'label'     => esc_html__( 'Show Icon', 'newsfy' ),
			    'type'      => Controls_Manager::SWITCHER,
			    'separator' => 'before',
		    ]
	    );

	    $this->add_control(
		    'button_icon',
		    [
			    'label' => esc_html__( 'Icon', 'newsfy' ),
			    'type' => Controls_Manager::ICONS,
			    'condition' => [
				    'button_show_icon' => 'yes',
			    ],
		    ]
	    );

	    $this->add_control(
		    'button_icon_position',
		    [
			    'label' => esc_html__( 'position', 'newsfy' ),
			    'type' => Controls_Manager::CHOOSE,
			    'toggle' => false,
			    'options' => [
                    'left' => [
                        'title' => esc_html__( 'Left', 'newsfy' ),
                        'icon' => 'eicon-h-align-left',
                    ],
				    'right' => [
					    'title' => esc_html__( 'Right', 'newsfy' ),
					    'icon' => 'eicon-h-align-right',
				    ],
			    ],
			    'default' => 'left',
			    'condition' => [
				    'button_show_icon' => 'yes',
			    ],
		    ]
	    );

        $this->add_control(
            'button_icon_spacing',
            [
                'label'     => esc_html__( 'Spacing', 'newsfy' ),
                'type'      => Controls_Manager::SLIDER,
                'range'     => [
                    'px' => [
                        'min' => 0,
                        'max' => 30,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .title-wrap' => 'gap: {{SIZE}}{{UNIT}};',
                ],
                'condition' => [
                    'button_show_icon' => 'yes',
                ],
            ]
        );


        $this->end_controls_section();


        $this->start_controls_section(
            'section_button_style',
            [
                'label' => esc_html__( 'Button', 'newsfy' ),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );

	    $this->add_responsive_control(
		    'button_padding',
		    [
			    'label'      => esc_html__( 'Padding', 'newsfy' ),
			    'type'       => Controls_Manager::DIMENSIONS,
			    'selectors'  => [
				    '{{WRAPPER}} .rivax-advanced-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
			    ],
		    ]
	    );

        $this->add_control(
            'button_border_radius',
            [
                'label'      => esc_html__( 'Border Radius', 'newsfy' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'selectors'  => [
                    '{{WRAPPER}} .rivax-advanced-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

	    $this->add_group_control(
		    Group_Control_Typography::get_type(),
		    [
			    'name'     => 'button_typography',
			    'label'    => esc_html__( 'Typography', 'newsfy' ),
			    'selector' => '{{WRAPPER}} .rivax-advanced-button',
		    ]
	    );

        $this->start_controls_tabs(
            'button_style_tabs'
        );

        $this->start_controls_tab(
            'button_style_normal_tab',
            [
                'label' => esc_html__( 'Normal', 'newsfy' ),
            ]
        );

        $this->add_control(
            'button_bg',
            [
                'label'     => esc_html__( 'Background', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button' => '--button-bg: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'button_bg_dark_mode',
            [
                'label'     => esc_html__( 'Background - Dark Mode', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button' => '--button-bg: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'button_color',
            [
                'label'     => esc_html__( 'Color', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'button_color_dark_mode',
            [
                'label'     => esc_html__( 'Color - Dark Mode', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button' => 'color: {{VALUE}};',
                ],
            ]
        );


	    $this->add_group_control(
		    Group_Control_Border::get_type(),
		    [
			    'name'     => 'button_border',
			    'selector' => '{{WRAPPER}} .rivax-advanced-button',
		    ]
	    );

        $this->add_control('button_border_color_dark_mode',
            [
                'label' => esc_html__('Border Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'button_border_border!' => '',
                ],
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button' => 'border-color: {{VALUE}};',
                ],
            ]);

	    $this->add_group_control(Group_Control_Box_Shadow::get_type(),
		    [
			    'name' => 'button_box_shadow',
			    'selector' => '{{WRAPPER}} .rivax-advanced-button',
		    ]);

        $this->add_control('button_bg_02',
            [
                'label' => esc_html__('Background 02', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'button_style' => ['6', '7', '8', '10', '17'],
                ],
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button' => '--bg-02: {{VALUE}};',
                ],
            ]);


        $this->end_controls_tab();

        $this->start_controls_tab(
            'button_style_hover_tab',
            [
                'label' => esc_html__( 'Hover', 'newsfy' ),
            ]
        );

        $this->add_control(
            'button_hover_bg',
            [
                'label'     => esc_html__( 'Background', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button:hover' => '--button-bg: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'button_hover_bg_dark_mode',
            [
                'label'     => esc_html__( 'Background - Dark Mode', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button:hover' => '--button-bg: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'button_hover_color',
            [
                'label'     => esc_html__( 'Color', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button:hover' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'button_hover_color_dark_mode',
            [
                'label'     => esc_html__( 'Color - Dark Mode', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button:hover' => 'color: {{VALUE}};',
                ],
            ]
        );


	    $this->add_control('button_hover_border_color',
		    [
			    'label' => esc_html__('Border Color', 'newsfy'),
			    'type' => Controls_Manager::COLOR,
			    'condition' => [
				    'button_border_border!' => '',
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .rivax-advanced-button:hover' => 'border-color: {{VALUE}};',
			    ],
		    ]);

        $this->add_control('button_hover_border_color_dark_mode',
            [
                'label' => esc_html__('Border Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'button_border_border!' => '',
                ],
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button:hover' => 'border-color: {{VALUE}};',
                ],
            ]);


	    $this->add_group_control(Group_Control_Box_Shadow::get_type(),
		    [
			    'name' => 'button_hover_box_shadow',
			    'selector' => '{{WRAPPER}} .rivax-advanced-button:hover',
		    ]);


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

        $this->end_controls_section();



	    $this->start_controls_section(
		    'section_icon_style',
		    [
			    'label' => esc_html__( 'Icon', 'newsfy' ),
			    'tab'   => Controls_Manager::TAB_STYLE,
			    'condition'   => [
				    'button_show_icon' => 'yes',
			    ],
		    ]
	    );


	    $this->add_control(
		    'button_icon_size',
		    [
			    'label'     => esc_html__( 'Icon Size', 'newsfy' ),
			    'type'      => Controls_Manager::SLIDER,
			    'range'     => [
				    'px' => [
					    'min' => 10,
					    'max' => 50,
				    ],
			    ],
			    'selectors' => [
				    '{{WRAPPER}} .rivax-advanced-button .icon' => 'font-size: {{SIZE}}{{UNIT}};',
			    ],
		    ]
	    );

        $this->add_responsive_control(
            'icon_padding',
            [
                'label'      => esc_html__( 'Padding', 'newsfy' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'selectors'  => [
                    '{{WRAPPER}} .rivax-advanced-button .icon' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'icon_border_radius',
            [
                'label'      => esc_html__( 'Border Radius', 'newsfy' ),
                'type'       => Controls_Manager::DIMENSIONS,
                'selectors'  => [
                    '{{WRAPPER}} .rivax-advanced-button .icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->start_controls_tabs(
            'icon_style_tabs'
        );

        $this->start_controls_tab(
            'icon_style_normal_tab',
            [
                'label' => esc_html__( 'Normal', 'newsfy' ),
            ]
        );

        $this->add_control(
            'icon_bg',
            [
                'label'     => esc_html__( 'Background', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button .icon' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'icon_bg_dark_mode',
            [
                'label'     => esc_html__( 'Background - Dark Mode', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button .icon' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'icon_color',
            [
                'label'     => esc_html__( 'Color', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button .icon' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'icon_color_dark_mode',
            [
                'label'     => esc_html__( 'Color - Dark Mode', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button .icon' => 'color: {{VALUE}};',
                ],
            ]
        );


        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name'     => 'icon_border',
                'selector' => '{{WRAPPER}} .rivax-advanced-button .icon',
            ]
        );

        $this->add_control('icon_border_color_dark_mode',
            [
                'label' => esc_html__('Border Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'icon_border_border!' => '',
                ],
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button .icon' => 'border-color: {{VALUE}};',
                ],
            ]);

        $this->add_group_control(Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'icon_box_shadow',
                'selector' => '{{WRAPPER}} .rivax-advanced-button .icon',
            ]);


        $this->end_controls_tab();

        $this->start_controls_tab(
            'icon_style_hover_tab',
            [
                'label' => esc_html__( 'Hover', 'newsfy' ),
            ]
        );

        $this->add_control(
            'icon_hover_bg',
            [
                'label'     => esc_html__( 'Background', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button:hover .icon' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'icon_hover_bg_dark_mode',
            [
                'label'     => esc_html__( 'Background - Dark Mode', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button:hover .icon' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'icon_hover_color',
            [
                'label'     => esc_html__( 'Color', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button:hover .icon' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'icon_hover_color_dark_mode',
            [
                'label'     => esc_html__( 'Color - Dark Mode', 'newsfy' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button:hover .icon' => 'color: {{VALUE}};',
                ],
            ]
        );


        $this->add_control('icon_hover_border_color',
            [
                'label' => esc_html__('Border Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'icon_border_border!' => '',
                ],
                'selectors' => [
                    '{{WRAPPER}} .rivax-advanced-button:hover .icon' => 'border-color: {{VALUE}};',
                ],
            ]);

        $this->add_control('icon_hover_border_color_dark_mode',
            [
                'label' => esc_html__('Border Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'icon_border_border!' => '',
                ],
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-advanced-button:hover .icon' => 'border-color: {{VALUE}};',
                ],
            ]);


        $this->add_group_control(Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'icon_hover_box_shadow',
                'selector' => '{{WRAPPER}} .rivax-advanced-button:hover .icon',
            ]);


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

	    $this->end_controls_section();


    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();

        $widget_path_name = str_replace('rivax-', '', $this->get_name() );
        include RIVAX_THEME_DIR . '/elementor/templates/' . $widget_path_name . '/' . $widget_path_name . '.php';
    }

}