<?php defined('ABSPATH') or die('No script kiddies please!!');
if ( !class_exists('EGPR_Enqueue') ) {
    class EGPR_Enqueue extends EGPR_Library{
        /**
         * Enqueue all the necessary JS and CSS
         *
         * since @1.0.0
         */
        function __construct() {
            add_action('admin_enqueue_scripts', array($this, 'egpr_admin_load_scripts')); // enqueued admin scripts
            add_action('wp_enqueue_scripts', array( $this, 'register_frontend_assets' ));
        }

        /*
         * Load Admin Scripts
        */
        public function egpr_admin_load_scripts($hook){
            $screen = get_current_screen();
            if ($hook == 'post-new.php' || $hook == 'edit.php' || $hook == 'post.php' || $hook == 'egprreviews_page_egpr-configuration-settings' || $hook == 'egprreviews_page_egpr-howtouse' || $hook == 'egprreviews_page_egpr-about-us') {
                if (isset($screen->post_type) && $screen->post_type == "egprreviews") {
                    $egpr_reviews = get_option('egp_reviews');
                    $apikey = (isset($egpr_reviews['nverified_api_key']) && $egpr_reviews['nverified_api_key'] != '')?$egpr_reviews['nverified_api_key']:'';
                    wp_enqueue_style('wp-color-picker');
                    wp_enqueue_script('wp-color-picker');
                    wp_enqueue_script('accordion');
                    wp_enqueue_style('egpr-jquery-ui', EGPR_BACKEND_CSS_DIR . 'jquery-ui.css');
                    //wp_register_script( 'egpr_google_places_gmaps', 'https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&key=' . esc_attr($apikey), array( 'jquery' ) );
                    wp_register_script( 'egpr_google_places_gmaps', 'https://maps.googleapis.com/maps/api/js?key=' . esc_attr($apikey).'&libraries=places', array( 'jquery' ) );
		            wp_enqueue_script( 'egpr_google_places_gmaps' );
                    wp_enqueue_script('egpr_webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
                    wp_enqueue_script('egpr-colorpicker-alpha-js', EGPR_BACKEND_JS_DIR . 'wp-color-picker-alpha.js', array('jquery'), EGPR_VERSION);

                    wp_enqueue_script('egpr-admin-script', EGPR_BACKEND_JS_DIR . 'egpr-admin-script.js', array('jquery', 'wp-color-picker', 'jquery-ui-sortable','jquery-ui-accordion','egpr_webfont'), EGPR_VERSION);
                    $admin_ajax_nonce = wp_create_nonce('egpr-admin-ajax-nonce');
                    $admin_ajax_object = array(
                        'ajax_url' => admin_url('admin-ajax.php'),
                        'ajax_nonce' => $admin_ajax_nonce
                    );
                    wp_localize_script('egpr-admin-script', 'egpr_admin_params', $admin_ajax_object);
                    wp_enqueue_style('egpr-backend-style', EGPR_BACKEND_CSS_DIR . 'egpr-admin-style.css', false, EGPR_VERSION);
                    wp_enqueue_style('egpr_fontawesome_style', EGPR_BACKEND_CSS_DIR . 'font-awesome/font-awesome.min.css',false,EGPR_VERSION);
                  }
            }     
        }

      public function register_frontend_assets() {
         wp_enqueue_style('egpr-mCustomScrollbar',EGPR_FRONTEND_CSS_DIR.'jquery.mCustomScrollbar.css');
         wp_enqueue_script('egpr-mCustomScrollbarjs',EGPR_FRONTEND_JS_DIR.'jquery.mCustomScrollbar.concat.min.js',array('jquery'),EGPR_VERSION);
         wp_enqueue_style('egpr-frontend-style', EGPR_FRONTEND_CSS_DIR . 'egpr-style.css', false, EGPR_VERSION);
         wp_enqueue_style('egpr_fontawesome_style', EGPR_BACKEND_CSS_DIR . 'font-awesome/font-awesome.min.css',false,EGPR_VERSION);
         wp_enqueue_style('egpr-bxslider-style', EGPR_FRONTEND_CSS_DIR . 'jquery.bxslider.css', false, EGPR_VERSION);
         wp_enqueue_script('egpr-bxslider-script', EGPR_FRONTEND_JS_DIR . 'jquery.bxslider.js', array('jquery'), EGPR_VERSION);

         wp_enqueue_style('egpr-animation',EGPR_FRONTEND_CSS_DIR.'animate.css');
         wp_enqueue_script('egpr-wow-animation',EGPR_FRONTEND_JS_DIR.'wow.js',array('jquery'),EGPR_VERSION);

         wp_enqueue_script('egpr-frontend-script', EGPR_FRONTEND_JS_DIR . 'egpr-frontend-script.js', array('jquery'), EGPR_VERSION);
      }
    }
    new EGPR_Enqueue();
}