<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php

class Beruco_Wp_Actions {

	private static $_instance = null;

	public function __construct() {
		
		//Google fonts
		add_action( 'wp_head', array( $this, 'beruco_google_fonts_con' ), 10 );

		//Theme front scripts
		add_action( 'wp_enqueue_scripts', array( $this, 'beruco_front_scripts' ), 10 );

		//body class
		add_filter( 'body_class', array( $this, 'beruco_custom_class' ), 99 );

	}

	public static function beruco_google_fonts_con(){

		$g_arr = get_option( 'beruco_google_fonts_list' );
		
		if( !empty( $g_arr ) ){
		
			$g_fonts = array();
			$g_arr_len = count( $g_arr );
			$i = 0;
			$sub_sets = array();
			$sub_str = '';
			foreach( $g_arr as $family => $weght_sub ){
				$i++;
				$weight = isset( $weght_sub['weight'] ) && !empty( $weght_sub['weight'] ) ? implode( ",", array_unique( $weght_sub['weight'] ) ) : '';
				$subset = isset( $weght_sub['subset'] ) && !empty( $weght_sub['subset'] ) ? $weght_sub['subset'] : '';
				$sub_sets = array_merge( $sub_sets, $subset );
				$font_attr = !empty( $weight ) ? $weight : $weight;
				if( $g_arr_len == $i && !empty( $sub_sets ) ){
					$sub_sets = implode( ",", array_unique( $sub_sets ) );
					$font_attr = $font_attr . '&amp;subset='. $sub_sets;
				}
				$g_fonts[] = urlencode_deep( $family ) .':'. $font_attr;
			}
			$web_font_arr = str_replace( '"', "'", json_encode( $g_fonts ) );
			 ?>
			<script>
				/* You can add more configuration options to webfontloader by previously defining the WebFontConfig with your options */
				if ( typeof WebFontConfig === "undefined" ) {
					WebFontConfig = new Object();
				}
				WebFontConfig['google'] = {families: <?php echo str_replace( "', ", "',", $web_font_arr ); ?>};
		
				(function() {
					var wf = document.createElement( 'script' );
					wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.5.3/webfont.js';
					wf.type = 'text/javascript';
					wf.async = 'true';
					var s = document.getElementsByTagName( 'script' )[0];
					s.parentNode.insertBefore( wf, s );
				})();
			</script>
			<?php
		}//google font exists
	}

	function beruco_front_scripts(){
		//Register font awesome styles
		wp_register_style( 'font-awesome', BERUCO_ADDON_URL . 'admin/extension/theme-options/assets/css/font-awesome.min.css', array(), '4.7.0', 'all' );
	}

	function beruco_custom_class( $classes ) {
		$beruco_options = get_option( 'beruco_options' ); 
		$rtl = isset( $beruco_options['rtl'] ) ? $beruco_options['rtl'] : false;
		if( $rtl ) {
			$classes[] = 'rtl';
		}
		
		$field = 'page_loader';
		$img_arr = array(
			'id' => null,
			'url' => null
		);
		$image = isset( $beruco_options[$field] ) && isset( $beruco_options[$field]['image'] ) ? $beruco_options[$field]['image'] : '';
		if( !empty( $image ) ){
			$img_arr['id'] = isset( $image['id'] ) ? $image['id'] : null;
			$img_arr['url'] = isset( $image['url'] ) ? $image['url'] : null;
		}
		if( $img_arr['id'] != null ){
			$classes[] = 'initiate';
		}else{
			$classes[] = 'page-load-initiate';
		}
		
		return $classes;
	}

	public static function get_instance() {
		if ( is_null( self::$_instance ) ) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}

}
Beruco_Wp_Actions::get_instance();