<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
use Elementor\Widget_Base;
use Elementor\Utils;
use Elementor\Icons_Manager;
use Elementor\Controls_Manager;
use Elementor\Control_Media;
use \Elementor\Group_Control_Box_Shadow;
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Text_Stroke;
use Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Image_Size;
use \Elementor\Group_Control_Background;

class Rswpthemes_Awt_Email_Signup_Widget extends \Elementor\Widget_Base {

    // Widget Name
    public function get_name() {
        return 'rswpthemes_awt_email_signup_widget';
    }

    // Widget Title
    public function get_title() {
        return __( 'AWT Email Signup Form', 'author-website-templates' );
    }

    // Widget Icon
    public function get_icon() {
        return 'dashicons dashicons-email';
    }

    // Widget Categories
    public function get_categories() {
        return [ 'rswpthemes_awt_widgets' ];
    }
    public function get_style_depends() {
        return [ 'rswpthemes-awt-email-signup' ];
    }

    // Widget Controls
    protected function _register_controls() {

        $this->start_controls_section(
            'content_section',
            [
                'label' => __( 'Content', 'author-website-templates' ),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'signup_heading',
            [
                'label' => __( 'Heading', 'author-website-templates' ),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => __( 'Want To Hear More From Taylor?', 'author-website-templates' ),
            ]
        );

        $this->add_control(
            'signup_sub_heading',
            [
                'label' => __( 'Subheading', 'author-website-templates' ),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => __( 'Sign up to receive news, updates, and exclusive content.', 'author-website-templates' ),
            ]
        );

        $this->add_control(
            'signup_shortcode',
            [
                'label' => __( 'Form Shortcode', 'author-website-templates' ),
                'type' => \Elementor\Controls_Manager::TEXT,
                'input_type' => 'text',
                'placeholder' => __( '[your_form_shortcode]', 'author-website-templates' ),
            ]
        );

        $this->end_controls_section();


       $this->start_controls_section(
            'awt_email_signup_box_style',
            [
                'label' => __( 'Signup Box', 'extra-addons-for-elementor' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'awt_email_signup_box_bg',
                'separator' => 'before',
                'label' => __( 'Box Background', 'extra-addons-for-elementor' ),
                'types' => [ 'classic', 'gradient' ],
                'selector' => '{{WRAPPER}} .awt-email-signup-section .email-signup-wrapper',
            ]
        );
        $this->add_control(
            'awt_email_signup_box_border_radius',
            [
                'label' => __( 'Border Radius', 'extra-addons-for-elementor' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section .email-signup-wrapper' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
       $this->end_controls_section();
       $this->start_controls_section(
            'awt_email_signup_title_style',
            [
                'label' => __( 'Title', 'extra-addons-for-elementor' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_email_signup_title_typography',
                'selector' => '{{WRAPPER}} .awt-email-signup-section .email-signup-content-wrapper h4',
            ]
        );
       $this->add_control(
            'awt_email_signup_title_color',
            [
                'label' => __( 'Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section .email-signup-content-wrapper h4' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_section();
       $this->start_controls_section(
            'awt_email_signup_description_style',
            [
                'label' => __( 'Description', 'extra-addons-for-elementor' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_email_signup_description_typography',
                'selector' => '{{WRAPPER}} .awt-email-signup-section .email-signup-content-wrapper p',
            ]
        );
       $this->add_control(
            'awt_email_signup_description_color',
            [
                'label' => __( 'Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section .email-signup-content-wrapper p' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_section();
       $this->start_controls_section(
            'awt_email_signup_button_style',
            [
                'label' => __( 'Button', 'extra-addons-for-elementor' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->start_controls_tabs(
            'awt_email_signup_button_tab'
        );
       $this->start_controls_tab(
                'awt_email_signup_button_normal',
                [
                    'label' => __( 'Normal', 'extra-addons-for-elementor' ),
                ]
            );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_email_signup_button_typography',
                'selector' => '{{WRAPPER}} .awt-email-signup-section input[type="submit"]',
            ]
        );
       $this->add_control(
            'awt_email_signup_button_bg_color',
            [
                'label' => __( 'Background Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="submit"]' => 'background-color: {{VALUE}}',
                ],
            ]
        );
       $this->add_control(
            'awt_email_signup_button_color',
            [
                'label' => __( 'Text Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="submit"]' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_tab();
       $this->start_controls_tab(
                'awt_email_signup_button_tab_hover',
                [
                    'label' => __( 'Hover', 'extra-addons-for-elementor' ),
                ]
            );
       $this->add_control(
            'awt_email_signup_button_hover_bg_color',
            [
                'label' => __( 'Background Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="submit"]:hover' => 'background-color: {{VALUE}}',
                ],
            ]
        );
       $this->add_control(
            'awt_email_signup_button_hover_color',
            [
                'label' => __( 'Text Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="submit"]:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_tab();
       $this->end_controls_tabs();
       $this->add_control(
            'awt_email_signup_button_border_radius',
            [
                'label' => __( 'Border Radius', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="submit"]' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
       $this->end_controls_section();
       $this->start_controls_section(
            'awt_email_signup_input_style',
            [
                'label' => __( 'Input Field', 'extra-addons-for-elementor' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->start_controls_tabs(
            'awt_email_signup_input_tab'
        );
       $this->start_controls_tab(
                'awt_email_signup_input_normal',
                [
                    'label' => __( 'Normal', 'extra-addons-for-elementor' ),
                ]
            );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_email_signup_input_typography',
                'selector' => '{{WRAPPER}} .awt-email-signup-section input[type="email"]',
            ]
        );
       $this->add_control(
            'awt_email_signup_input_bg_color',
            [
                'label' => __( 'Background Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="email"]' => 'background-color: {{VALUE}}',
                ],
            ]
        );
       $this->add_control(
            'awt_email_signup_input_color',
            [
                'label' => __( 'Text Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="email"]' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_tab();
       $this->start_controls_tab(
                'awt_email_signup_input_tab_hover',
                [
                    'label' => __( 'Hover', 'extra-addons-for-elementor' ),
                ]
            );
       $this->add_control(
            'awt_email_signup_input_hover_bg_color',
            [
                'label' => __( 'Background Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="email"]:hover' => 'background-color: {{VALUE}}',
                ],
            ]
        );
       $this->add_control(
            'awt_email_signup_input_hover_color',
            [
                'label' => __( 'Text Color', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="email"]:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_tab();
       $this->end_controls_tabs();
       $this->add_control(
            'awt_email_signup_input_border_radius',
            [
                'label' => __( 'Border Radius', 'extra-addons-for-elementor' ),
                'separator' => 'before',
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .awt-email-signup-section input[type="email"]' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
       $this->end_controls_section();
    }

    // Widget Output in Frontend
    protected function render() {

        $settings = $this->get_settings_for_display();

        $signupHeading = $settings['signup_heading'];
        $signupSubHeading = $settings['signup_sub_heading'];
        $fromShortcode = $settings['signup_shortcode'];
        ?>
        <div class="awt-email-signup-section">
            <div class="container">
                <div class="email-signup-wrapper">
                    <div class="row justify-content-md-center align-items-center email-signup-item email-signup-row">
                        <div class="col-lg-7 mb-md-4 mb-4 mb-lg-0 col-md-12 align-self-center email-signup-column email-signup-cover-column">
                            <div class="email-signup-content-wrapper">
                                <?php if ( ! empty( $signupHeading ) ) : ?>
                                    <h4 class="email-signup-title"><?php echo esc_html( $signupHeading ); ?></h4>
                                <?php endif; ?>

                                <?php if ( ! empty( $signupSubHeading ) ) : ?>
                                    <p class="email-signup-desc"><?php echo esc_html( $signupSubHeading ); ?></p>
                                <?php endif; ?>
                            </div>
                        </div>
                        <?php if ( ! empty( $fromShortcode ) ) : ?>
                        <div class="col-lg-5 col-md-12 align-self-center email-signup-column email-signup-content-column">
                            <div class="email-signup-form-wrapper">
                                <div class="email-signup-form-container">
                                    <?php echo do_shortcode( $fromShortcode ); ?>
                                </div>
                            </div>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <?php
    }
}
