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

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

/**
 * Productive Google_Map Widget for Elementor.
 *
 */
class Productive_Elementor_Widget_Google_Maps extends \Elementor\Widget_Base {

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

    /**
     *
     * Widget Name (Visible).
     */
    public function get_title() {
        return esc_html__( 'Google Maps', '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_google_map', 'Google Map', 'Google Maps', '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-settings.php' );
        require( plugin_dir_path( __FILE__ ) . 'partials/partial-productive-elementor-widget-update-data.php' );
    }
    
    public function get_script_depends() {
        return [ 'productiveminds_lib_elementor_productive_forms_js_handle' ];
    }
    
    /**
     *
     * 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;
        }
        
        $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'],
            'section_title'                                         => $settings['section_title'],
            'section_title_html_tag'                                => $settings['section_title_html_tag'],
            'section_intro'                                         => $settings['section_intro'],
            'google_map_api_key'                                    => $settings['google_map_api_key'],
            'google_map_address'                                    => $settings['google_map_address'],
            'google_map_container_width'                            => $settings['google_map_container_width'],
            'google_map_container_height'                           => $settings['google_map_container_height'],
            'google_map_map_magnification'                          => $settings['google_map_map_magnification'],
            'google_map_display_physical_address'                   => $settings['google_map_display_physical_address'],
            '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_google_map( $cpt_section_args );
            do_action('productive_global_render_content_wrapper_full_bottom');
        do_action('productive_global_render_content_wrapper_full_full_bottom');
    }
    
}
