<?php
function wpfresh5_scripts_and_styles() {
	wp_enqueue_script( 'fresh5-jquery-cookie', WPFRESH5_URL . '/js/front/jquery.cookie-1.4.1.min.js',	array( 'jquery' ), '1.4.1' );

	wp_register_script( 'wpfresh5_front_js', WPFRESH5_URL . '/js/wpfresh5-front.js', array( 'jquery' ), WPFRESH5_VERSION);

	$legal = wpfresh5_get_settings( array( 'legal', 'cookies' ) );
// var_dump($legal);die();
    $script_vars = array(
            'message' => ( isset( $legal['cookiew_text'] ) && $legal['cookiew_text'] ) ? $legal['cookiew_text'] : '',
            'button'  => ( isset( $legal['cookiew_accept'] ) && $legal['cookiew_accept'] ) ? $legal['cookiew_accept'] : '',
            'decline_button'  => ( isset( $legal['cookiew_cancel'] ) && $legal['cookiew_cancel'] ) ? $legal['cookiew_cancel'] : 'Decline',
            'more'    => __( 'Cookie Policy', 'cookie-pop' ),
            'url'     => ( isset( $legal['cookiew_url'] ) && $legal['cookiew_url'] ) ? $legal['cookiew_url'] : '',
            'decline_url'     => ( isset( $legal['cookiew_cancel_url'] ) && $legal['cookiew_cancel_url'] ) ? $legal['cookiew_cancel_url'] : '#',
            'cookie_enabled'  => ( isset( $legal['cookiew_enabled'] ) && $legal['cookiew_enabled'] ) ? 1 : 0,
            'cookie_pos' =>  ( isset( $legal['cookiew_position'] ) ) ? $legal['cookiew_position'] : 0,
    );

	wp_localize_script( 'wpfresh5_front_js', 'wpfresh5_vars', $script_vars );
	wp_enqueue_script( 'wpfresh5_front_js' );

    $pinterest = wpfresh5_get_settings( array( 'social', 'pinterest', 'pin_img' ) );
    if( $pinterest )
        wp_enqueue_script( 'fresh5-pinterest', WPFRESH5_URL . '/js/front/wpfresh5-pinterest.js',   array( 'jquery' ), WPFRESH5_VERSION );

    wp_register_style( 'wpfresh5_front_css', WPFRESH5_URL . '/css/wpfresh5-front.css', array(), WPFRESH5_VERSION );
    wp_enqueue_style( 'wpfresh5_front_css' );

    wp_register_style( 'wpfresh5_fa', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css', array(), WPFRESH5_VERSION);
    wp_enqueue_style( 'wpfresh5_fa' );

    $enable_fonts = wpfresh5_get_settings( array( 'content', 'fonts', 'enable_fonts' ) );
    if( !$enable_fonts )
        return;
    $fonts_txt = '';
    for( $i=1; $i<6;$i++ ) {
        $font = wpfresh5_get_settings( array( 'content', 'fonts', 'font'.$i ) );
        if( $font )
            $fonts_txt .= str_replace( ' ', '+', $font).'|';
    }
    wp_register_style('wpfresh5_google_fonts_front', WPFRESH5_GOOGLE_FONTS_URL.'/css?family='.$fonts_txt);
    wp_enqueue_style( 'wpfresh5_google_fonts_front');
}

add_action( 'wp_enqueue_scripts', 'wpfresh5_scripts_and_styles' );

add_action( 'wp_head', 'wpfresh5_maybe_hide_cookies' );

function wpfresh5_maybe_hide_cookies() {
    if( is_admin() )
        return;
    $legal = wpfresh5_get_settings( array( 'legal', 'cookies' ) );
    $cookie_enabled  = ( isset( $legal['cookiew_enabled'] ) && $legal['cookiew_enabled'] ) ? 1 : 0;
    $ueonly  = ( isset( $legal['cookiew_euonly'] ) && $legal['cookiew_euonly'] ) ? 1 : 0;
    if( $cookie_enabled && !isset( $_COOKIE['wpfresh5-cookie-pop'] ) ) {
        if( $ueonly && !wpfresh5_is_eu_visitor() ) {
            echo '<style>.wpfresh5-cookie-pop{ display:none!important;}</style>';
        }
    }
}
?>