<?php
/**
 * Created by Code Monkeys LLC
 * http://www.codemonkeysllc.com
 */

//* ENQUEUE ADMIN SCRIPTS AND STYLES
function cm_hipaa_enqueue_admin_scripts() {
    // ENQUEUE GOOGLE FONTS
    $gFonts = array(
        "Roboto+Condensed:300,300i,400,400i,700,700i",
        "Roboto:100,100i,200,200i,300,300i,400,400i,500,500i,700,700i,900,900i"
    );

    $gf_args = array(
        'family' => urlencode(implode("|",$gFonts)),
        'subset' => 'latin,latin-ext'
    );

    // ONLY ENQUEUE STYLES WHEN ON HIPAA FORMS ADMIN PAGE
    if ( isset($_GET['page']) ) {
        global $pagenow;
        if( in_array( $pagenow, array('admin.php') ) && ( $_GET['page'] == 'hipaa-forms.php' ) ) {
            wp_enqueue_style( 'google_fonts', add_query_arg($gf_args, "//fonts.googleapis.com/css"), array(), null);

            // ENQUEUE GOOGLE MATERIAL.IO ICONS
            wp_enqueue_style( 'materialIcons', 'https://fonts.googleapis.com/icon?family=Material+Icons' );

            // ENQUEUE GRAVITY CSS
            wp_enqueue_style( 'cmHipaaGravityAdminBasicStyle', plugin_dir_url(__FILE__) . '/css/gravity-basic.min.css' );
            wp_enqueue_style( 'cmHipaaGravityAdminCustomStyle', plugin_dir_url(__FILE__) . '/css/gravity-admin.css' );
            wp_enqueue_style( 'cmHipaaGravityAdminPrintStyle', plugin_dir_url(__FILE__) . '/css/print.css' );

            // ENQUEUE MAIN PLUGIN ADMIN CSS
            wp_enqueue_style( 'cmHipaaAdminStyle', plugin_dir_url(__FILE__) . '/css/admin-style.css' );

            // ENQUEUE SCRIPT
            wp_enqueue_script( 'jquery-form' );
            wp_enqueue_script( 'cmHipaaAdminBuggyFill', plugin_dir_url(__FILE__) . 'js/viewport-units-buggyfill.js', array('jquery'), '3.2.2', true );
            wp_enqueue_script( 'cmHipaaAdminBuggyFillHack', plugin_dir_url(__FILE__) . 'js/viewport-units-buggyfill.hacks.js', array('jquery'), '3.2.2', true );
            wp_enqueue_script( 'cmHipaaAdminScript', plugin_dir_url(__FILE__) . 'js/admin-script.js', array('jquery'), '3.2.2', true );
            wp_enqueue_script( 'cm-hipaa-signature', plugin_dir_url(__FILE__) . 'js/jSignature/jSignature.min.noconflict.js', array('jquery'), '3.2.2', true);
            wp_enqueue_script( 'cm-hipaa-jquery-print', plugin_dir_url(__FILE__) . 'js/printThis.js', array('jquery'), '3.2.2', true);
        };
    };

    // PASS PHP DATA TO SCRIPT FILE
    global $post;
    wp_localize_script('cmHipaaAdminScript', 'hipaaScript', array(
        'pluginUrl' => plugin_dir_url(__FILE__),
        'siteUrl' =>  get_site_url(),
        'contentUrl' => WP_CONTENT_URL,
        'nonce' => wp_create_nonce('cm-hipaa-admin-nonce'),
        'ajax_url' => admin_url( 'admin-ajax.php' )
    ));
}
add_action( 'admin_enqueue_scripts', 'cm_hipaa_enqueue_admin_scripts' );