<?php
/**
 * @package     productive-forms
 * @author      productiveminds.com
 * @copyright   productiveminds.com
 */

if ( !defined( 'ABSPATH' ) ) {
    die();
}

/**
 * Productive Newsletter_Element Widget for Elementor.
 *
 */
class Productive_Elementor_Widget_Newsletter_Element extends \Elementor\Widget_Base {

    /**
     *
     * Widget Name (System).
     */
    public function get_name() {
        return 'productive_elementor_widget_cpt_newsletter_element';
    }

    /**
     *
     * Widget Name (Visible).
     */
    public function get_title() {
        return esc_html__( 'Newsletter Element', 'productive-forms' );
    }

    /**
     *
     * Widget Icon
     */
    public function get_icon() {
        return 'eicon-circle-o';
    }

    /**
     *
     * Widget Support Url
     */
    public function get_custom_help_url() {
        return PRODUCTIVE_GLOBAL_PRODUCT_SUPPORT_BASE_URL;
    }

    /**
     *
     * Category in Element Admin Area
     */
    public function get_categories() {
        return [ 'productiveminds' ];
    }

    /**
     *
     * Widget Keywords
     */
    public function get_keywords() {
        return [ 'productive_elementor_widget_cpt_newsletter_element', 'Newsletter', 'Newsletter Element', 'productiveminds', 'productiveminds.com' ];
    }

    /**
     *
     * Widget Controls
     */
    protected function register_controls() {
        require( plugin_dir_path( __FILE__ ) . 'partials/partial-productive-elementor-widget-layout.php' );
        require( plugin_dir_path( __FILE__ ) . 'partials/partial-productive-elementor-widget-header.php' );
        require( plugin_dir_path( __FILE__ ) . 'partials/partial-productive-elementor-widget-content.php' );
        require( plugin_dir_path( __FILE__ ) . 'partials/partial-productive-elementor-widget-settings.php' );
        require( plugin_dir_path( __FILE__ ) . 'partials/partial-productive-elementor-widget-update-data.php' );
    }
    
    /**
     *
     * Widget Rendered Content
     */
    protected function render() {
        $settings = $this->get_settings_for_display();
        
        if ( !isset($settings['section_content_header_is_show_section_header']) || empty($settings['section_content_header_is_show_section_header'])) {
            $settings['section_content_header_is_show_section_header'] = 0;
        } else {
            $settings['section_content_header_is_show_section_header'] = 1;
        }
        
        if ( !isset($settings['section_style_content_button_hover_animation']) || empty($settings['section_style_content_button_hover_animation']) ) {
            $settings['section_style_content_button_hover_animation'] = '';
        } else {
            $this->add_render_attribute( 'wrapper', 'class', $settings['section_style_content_button_hover_animation'] );
            $settings['section_style_content_button_hover_animation'] = 'elementor-animation-' . $settings['section_style_content_button_hover_animation'];
        }
        
        $settings['slider_swiper_css_class_from_elementor'] = 'via_elementor_slider';
        $settings['section_content_settings_unique_id'] = 'section_unique_id_' . rand() . '_' . rand();
        
        $cpt_section_args = array(
            'section_initiator'                                     => 'elementor',
            'section_content_settings_unique_id'                    => $settings['section_content_settings_unique_id'],
            'section_content_header_is_show_section_header'         => $settings['section_content_header_is_show_section_header'],
            'productive_forms_newsletter_form_style'                => $settings['productive_forms_newsletter_form_style'],
            'productive_forms_form_submit_text'                     => $settings['productive_forms_form_submit_text'],
            'productive_forms_form_footnote_text'                   => $settings['productive_forms_form_footnote_text'],
            'section_title'                                         => $settings['section_title'],
            'section_title_suffix'                                  => $settings['section_title_suffix'],
            'section_title_html_tag'                                => $settings['section_title_html_tag'],
            'section_intro'                                         => $settings['section_intro'],
            'section_heading_auxiliary'                             => $settings['section_heading_auxiliary'],
            'section_heading_auxiliary_position'                    => $settings['section_heading_auxiliary_position'],
            'display_contact_form_label'                            => $settings['display_contact_form_label'],
            'section_style_content_button_hover_animation'          => $settings['section_style_content_button_hover_animation'],
            'newsletter_how_to_display_contact_name_field'          => $settings['newsletter_how_to_display_contact_name_field'],
            'request_data_privacy_consent'                          => $settings['request_data_privacy_consent'],
            'submission_verify_type'                                => $settings['submission_verify_type'],
            'display_email_field_only'                              => $settings['display_email_field_only'],
            'slider_swiper_css_class_from_elementor'                => $settings['slider_swiper_css_class_from_elementor'],
        );
        
        $section_bg_color_scheme        = 'productive-paddable-section page_main_section_container ' . $settings['section_gtbg_align'] 
                . ' ' . $settings['section_bg_color_scheme'] . ' ' . $settings['section_block_max_width'] . ' ' . $settings['section_block_spacing'];
    
        do_action( 'productive_global_render_content_wrapper_full_full_top', $section_bg_color_scheme );
            do_action('productive_global_render_content_wrapper_full_top');
                productive_forms_render_newsletter_element( $cpt_section_args );
            do_action('productive_global_render_content_wrapper_full_bottom');
        do_action('productive_global_render_content_wrapper_full_full_bottom');
    }
    
}
