<?php
/**
 *
 * @package productive-forms
 */

require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/db/db_install.php';
require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/db/db_upgrade.php';
require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/db/db_transactions.php';
require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/activate.php';
require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/deactivate.php';

require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'admin/standard/options/settings.php'; 

require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/helper/productive-email.php';

require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'admin/common/options/functions-options.php';

require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/productive-plugin-customiser.php';
require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/module/header-contact-section.php';

require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/render/partials/productive-render-functions-common.php';

require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/render/productive-render-contact-us-page.php';
require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/render/productive-render-newsletter-element.php';
require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/render/productive-render-google-map.php';

require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'standard/gutenberg/productive-gutenberg.php';

if ( productive_global_is_elementor_active() ) {
    require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'standard/elementor/productive-elementor.php';
}


/**
 * Method productive_forms_scripts.
 */
function productive_forms_scripts() {
    global $productive_forms_plugin_version;
    $productiveminds_global_localize_script_vars = array();
    
    $wp_scripts = wp_scripts();
    
    // Swiper
    if ( !function_exists( 'productiveminds_library_swiper') ) {
        wp_enqueue_style( 'productiveminds_library_swiper_css', PRODUCTIVE_FORMS_PLUGIN_URI . 'libraries/swiper/11-2-10/swiper-bundle.min.css', array(), $productive_forms_plugin_version );
        wp_enqueue_script( 'productiveminds_library_swiper_js', PRODUCTIVE_FORMS_PLUGIN_URI . 'libraries/swiper/11-2-10/swiper-bundle.min.js', array(), $productive_forms_plugin_version, true );

        require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'libraries/swiper/productiveminds-library-swiper.php';
    }
    
    // Common assets
    if ( !function_exists( 'productiveminds_common_asset') ) {
        
        $productiveminds_library_swiper_css = array();
        if( isset( $wp_scripts->registered['productiveminds_library_swiper_css'] ) && !empty($wp_scripts->registered['productiveminds_library_swiper_css']) ) {
            $productiveminds_library_swiper_css[] = 'productiveminds_library_swiper_css';
        }
        wp_enqueue_style( 'productiveminds_common_css', PRODUCTIVE_FORMS_PLUGIN_URI . 'public/css/productiveminds-common-css.min.css', $productiveminds_library_swiper_css, $productive_forms_plugin_version );
        wp_style_add_data( 'productiveminds_common_css', 'rtl', 'replace' );
        
        $productiveminds_library_swiper_js = array();
        if( isset( $wp_scripts->registered['productiveminds_library_swiper_js'] ) && !empty($wp_scripts->registered['productiveminds_library_swiper_js']) ) {
            $productiveminds_library_swiper_js[] = 'productiveminds_library_swiper_js';
        }
        wp_enqueue_script( 'productiveminds_common_js_handle', PRODUCTIVE_FORMS_PLUGIN_URI . 'public/js/productiveminds-common-js.min.js', $productiveminds_library_swiper_js, $productive_forms_plugin_version, true );
        
        productive_global_get_common_swiper_localize_script( $productiveminds_global_localize_script_vars );
        // Assign others
        productive_global_get_common_std_localize_script( $productiveminds_global_localize_script_vars );
        wp_localize_script(
            'productiveminds_common_js_handle',
            'productiveminds_common_js_name',
            $productiveminds_global_localize_script_vars
            );
        
        $custom_css_global = productive_global_apply_custom_css();
        wp_add_inline_style('productiveminds_common_css', $custom_css_global);
        
        require_once PRODUCTIVE_FORMS_PLUGIN_PATH . 'includes/common/productiveminds-common-asset.php';
    }
    
    $productiveminds_common_css = array();
    if( !productive_global_is_productive_style_active() && !productive_global_is_pass_addons_active() ) {
        if( isset( $wp_scripts->registered['productiveminds_common_css'] ) && !empty($wp_scripts->registered['productiveminds_common_css']) ) {
            $productiveminds_common_css[] = 'productiveminds_common_css';
        }
        wp_enqueue_style( 'productive_forms_font_awesome', PRODUCTIVE_FORMS_PLUGIN_URI . 'libraries/fonts/font-awesome-6.7.1/css/fontawesome.min.css', $productiveminds_common_css, $productive_forms_plugin_version );
        wp_enqueue_style( 'productive_forms_font_awesome_brands', PRODUCTIVE_FORMS_PLUGIN_URI . 'libraries/fonts/font-awesome-6.7.1/css/brands.min.css', array( 'productive_forms_font_awesome' ), $productive_forms_plugin_version );
        wp_enqueue_style( 'productive_forms_font_awesome_solid', PRODUCTIVE_FORMS_PLUGIN_URI . 'libraries/fonts/font-awesome-6.7.1/css/solid.min.css', array( 'productive_forms_font_awesome_brands' ), $productive_forms_plugin_version );
        
        wp_enqueue_style( 'productive_forms_font_awesome_v4', PRODUCTIVE_FORMS_PLUGIN_URI . 'libraries/fonts/font-awesome-6.7.1/css/v4-shims.min.css', array( 'productive_forms_font_awesome_solid' ), $productive_forms_plugin_version );
        $productiveminds_common_css[] = 'productive_forms_font_awesome_v4';
    }
    
    wp_enqueue_style( 'productive_forms_style', PRODUCTIVE_FORMS_PLUGIN_URI . 'public/css/style.bundle.min.css', $productiveminds_common_css, $productive_forms_plugin_version );
    wp_style_add_data( 'productive_forms_style', 'rtl', 'replace' );
    
    $custom_css = productive_forms_apply_custom_css();
    wp_add_inline_style('productive_forms_style', $custom_css);
    
    $recaptcha_site_key = '';
    $productiveminds_common_js_handle = array();
    if( !empty(productive_forms_integration_recaptcha_key()) && !empty(productive_forms_integration_recaptcha_secret()) ) {
        if( isset( $wp_scripts->registered['productiveminds_common_js_handle'] ) && !empty($wp_scripts->registered['productiveminds_common_js_handle']) ) {
            $productiveminds_common_js_handle[] = 'productiveminds_common_js_handle';
        }   
        $recaptcha_site_key = productive_forms_integration_recaptcha_key();
        wp_enqueue_script( 'productive_forms_recaptcha_js', 'https://www.google.com/recaptcha/api.js?render='.$recaptcha_site_key, $productiveminds_common_js_handle, $productive_forms_plugin_version, true );
        $productiveminds_common_js_handle[] = 'productive_forms_recaptcha_js';
    }
    
    wp_enqueue_script( 'productive_forms_js_url_handle', PRODUCTIVE_FORMS_PLUGIN_URI . 'public/js/plugin.min.js', $productiveminds_common_js_handle, $productive_forms_plugin_version, true );
    $wp_localize_script_values_std_plugin_js_handle = array(
        'ajax_admin_url'        => admin_url( 'admin-ajax.php' ),
        'nonce'                 => wp_create_nonce('productive_forms_scripts'),
        'msg_recaptcha_site_key' => $recaptcha_site_key,
        'productive_forms_integration_google_map_api_key'   => productive_forms_integration_google_map_api_key(),
        'msg_error_add_name' => esc_html__( 'Please enter your name, then try again.', 'productive-forms' ),
        'msg_error_add_first_name' => esc_html__( 'Please enter your first name, then try again.', 'productive-forms' ),
        'msg_error_add_last_name' => esc_html__( 'Please enter your last name, then try again.', 'productive-forms' ),
        'msg_error_add_email' => esc_html__( 'Please enter a valid email address, then try again.', 'productive-forms' ),
        'msg_error_add_phone' => esc_html__( 'Add a valid phone number, then try again.', 'productive-forms' ),
        'msg_error_add_message' => esc_html__( 'Add message, then try again.', 'productive-forms' ),
        'msg_error_add_consent' => esc_html__( 'Please tick the consent box, then try again.', 'productive-forms' ),
        'msg_error_add_maths_challenge' => esc_html__( 'Please provide the correct answer to the math challenge, then try again.', 'productive-forms' ),
    );
    wp_localize_script(
        'productive_forms_js_url_handle',
        'productive_forms_js_url_handle_name',
        $wp_localize_script_values_std_plugin_js_handle
    );
    
}
if ( !is_admin() ) {
    add_action( 'wp_enqueue_scripts', 'productive_forms_scripts', 72 );
} else if ( is_admin() ) {
    global $pagenow;
    if( productive_global_is_block_editor_active() && 
            ( 'post.php' == $pagenow || 'post-new.php' == $pagenow || 'comment.php' == $pagenow ) ) {
        add_action( 'enqueue_block_assets', 'productive_forms_scripts', 72 );
    }
}

