<?php

require_once get_template_directory() . '/includes/loader.php';

add_action( 'after_setup_theme', 'roonix_setup_theme' );
add_action( 'after_setup_theme', 'roonix_load_default_hooks' );


function roonix_setup_theme() {

	load_theme_textdomain( 'roonix', get_template_directory() . '/languages' );

	// Add default posts and comments RSS feed links to head.

	/*
	 * Let WordPress manage the document title.
	 * By adding theme support, we declare that this theme does not use a
	 * hard-coded <title> tag in the document head, and expect WordPress to
	 * provide it for us.
	 */
	add_theme_support( 'title-tag' );
	add_theme_support( 'custom-header' );
	add_theme_support( 'custom-background' );
	add_theme_support( 'woocommerce' );
	add_theme_support( 'wc-product-gallery-lightbox' );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 *
	 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
	 */
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'align-wide' );
	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'editor-styles' );
	add_theme_support( 'post', 'page-attributes' );
    add_theme_support( 'post-formats', array( 'gallery', 'video', 'quote' ));
    
	// Set the default content width.
	$GLOBALS['content_width'] = 525;
	
	/*---------- Register image sizes ----------*/
	
	//Register image sizes
	add_image_size( 'roonix_1162x500', 1162, 500, true ); //roonix_1162x500 Our Projects V1
	add_image_size( 'roonix_568x500', 568, 500, true ); //roonix_568x500 Our Projects V1
	add_image_size( 'roonix_573x323', 573, 323, true ); //roonix_568x500 Our Projects V8
	add_image_size( 'roonix_300x362', 300, 362, true ); //roonix_300x362 Our Team V1
	add_image_size( 'roonix_275x330', 275, 330, true ); //roonix_300x362 Our Team V6
	add_image_size( 'roonix_94x94', 94, 94, true ); //roonix_94x94 Our Testimonials V1
	add_image_size( 'roonix_410x272', 410, 272, true ); //roonix_410x272 Latest News V1
	add_image_size( 'roonix_480x402', 480, 402, true ); //roonix_480x402 Our Services V2
	add_image_size( 'roonix_659x459', 659, 459, true ); //roonix_659x459 Our Projects V2
	add_image_size( 'roonix_369x300', 369, 300, true ); //roonix_369x300 Latest News V2
	add_image_size( 'roonix_645x409', 645, 409, true ); //roonix_645x409 Our Projects V3
	add_image_size( 'roonix_430x464', 430, 464, true ); //roonix_430x464 Our Projects V3
	add_image_size( 'roonix_430x514', 430, 514, true ); //roonix_430x514 Latest News V3
	add_image_size( 'roonix_410x393', 410, 393, true ); //roonix_410x393 Our Services V5
	add_image_size( 'roonix_600x770', 600, 770, true ); //roonix_600x770 Our Projects V4
	add_image_size( 'roonix_90x90', 90, 90, true ); //roonix_90x90 Our Testimonials V4
	add_image_size( 'roonix_606x349', 606, 349, true ); //roonix_606x349 Latest News V4
	add_image_size( 'roonix_630x355', 630, 355, true ); //roonix_630x355 Our Projects V5
	add_image_size( 'roonix_410x355', 410, 355, true ); //roonix_410x355 Our Projects V6
	add_image_size( 'roonix_1170x410', 1170, 410, true ); //roonix_1170x410 Archieve
	add_image_size( 'roonix_80x80', 80, 80, true ); //roonix_80x80 Single Comment Box
	add_image_size( 'roonix_813x500', 813, 500, true ); //roonix_813x500 Our Latest Projects
	
	
	
	/*---------- Register image sizes ends ----------*/
	
	
	
	// This theme uses wp_nav_menu() in two locations.
	register_nav_menus( array(
		'main_menu' => esc_html__( 'Main Menu', 'roonix' ),
	) );

	/*
	 * Switch default core markup for search form, comment form, and comments
	 * to output valid HTML5.
	 */
	add_theme_support( 'html5', array(
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );

	// Add theme support for Custom Logo.
	add_theme_support( 'custom-logo', array(
		'width'      => 250,
		'height'     => 250,
		'flex-width' => true,
	) );

	// Add theme support for selective refresh for widgets.
	add_theme_support( 'customize-selective-refresh-widgets' );

	/*
	 * This theme styles the visual editor to resemble the theme style,
	 * specifically font, colors, and column width.
 	 */
	add_editor_style();
	add_action( 'admin_init', 'roonix_admin_init', 2000000 );
}

/**
 * [roonix_admin_init]
 *
 * @param  array $data [description]
 *
 * @return [type]       [description]
 */


function roonix_admin_init() {
	remove_action( 'admin_notices', array( 'ReduxFramework', '_admin_notices' ), 99 );
}

/*---------- Sidebar settings ----------*/

/**
 * [roonix_widgets_init]
 *
 * @param  array $data [description]
 *
 * @return [type]       [description]
 */
function roonix_widgets_init() {

	global $wp_registered_sidebars;

	$theme_options = get_theme_mod( 'roonix' . '_options-mods' );

	register_sidebar( array(
		'name'          => esc_html__( 'Default Sidebar', 'roonix' ),
		'id'            => 'default-sidebar',
		'description'   => esc_html__( 'Widgets in this area will be shown on the right-hand side.', 'roonix' ),
		'before_widget' => '<div id="%1$s" class="widget sidebar-widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<div class="sidebar-title"><h4>',
		'after_title'   => '</h4></div>',
	) );
	register_sidebar(array(
		'name' => esc_html__('Footer Widget', 'roonix'),
		'id' => 'footer-sidebar',
		'description' => esc_html__('Widgets in this area will be shown in Footer Area.', 'roonix'),
		'before_widget'=>'<div class="footer-column col-lg-3 col-md-6 col-sm-12"><div id="%1$s" class="footer-widget %2$s">',
		'after_widget'=>'</div></div>',
		'before_title' => '<h6>',
		'after_title' => '</h6>'
	));
	if ( class_exists( '\Elementor\Plugin' )){
		register_sidebar(array(
		  'name' => esc_html__( 'Blog Listing', 'roonix' ),
		  'id' => 'blog-sidebar',
		  'description' => esc_html__( 'Widgets in this area will be shown on the right-hand side.', 'roonix' ),
		  'before_widget'=>'<div id="%1$s" class="widget sidebar-widget %2$s">',
		  'after_widget'=>'</div>',
		  'before_title' => '<div class="sidebar-title"><h4>',
		  'after_title' => '</h4></div>'
		));
	}
	if ( ! is_object( roonix_WSH() ) ) {
		return;
	}

	$sidebars = roonix_set( $theme_options, 'custom_sidebar_name' );

	foreach ( array_filter( (array) $sidebars ) as $sidebar ) {

		if ( roonix_set( $sidebar, 'topcopy' ) ) {
			continue;
		}

		$name = $sidebar;
		if ( ! $name ) {
			continue;
		}
		$slug = str_replace( ' ', '_', $name );

		register_sidebar( array(
			'name'          => $name,
			'id'            => sanitize_title( $slug ),
			'before_widget' => '<div id="%1$s" class="%2$s widget sidebar-widget">',
			'after_widget'  => '</div>',
			'before_title'  => '<div class="sidebar-title"><h4>',
			'after_title'   => '</h4></div>',
		) );
	}

	update_option( 'wp_registered_sidebars', $wp_registered_sidebars );
}

add_action( 'widgets_init', 'roonix_widgets_init' );

/*---------- Sidebar settings ends ----------*/

/*---------- Gutenberg settings ----------*/

function roonix_gutenberg_editor_palette_styles() {
    add_theme_support( 'editor-color-palette', array(
        array(
            'name' => esc_html__( 'strong yellow', 'roonix' ),
            'slug' => 'strong-yellow',
            'color' => '#f7bd00',
        ),
        array(
            'name' => esc_html__( 'strong white', 'roonix' ),
            'slug' => 'strong-white',
            'color' => '#fff',
        ),
		array(
            'name' => esc_html__( 'light black', 'roonix' ),
            'slug' => 'light-black',
            'color' => '#242424',
        ),
        array(
            'name' => esc_html__( 'very light gray', 'roonix' ),
            'slug' => 'very-light-gray',
            'color' => '#797979',
        ),
        array(
            'name' => esc_html__( 'very dark black', 'roonix' ),
            'slug' => 'very-dark-black',
            'color' => '#000000',
        ),
    ) );
	
	add_theme_support( 'editor-font-sizes', array(
		array(
			'name' => esc_html__( 'Small', 'roonix' ),
			'size' => 10,
			'slug' => 'small'
		),
		array(
			'name' => esc_html__( 'Normal', 'roonix' ),
			'size' => 15,
			'slug' => 'normal'
		),
		array(
			'name' => esc_html__( 'Large', 'roonix' ),
			'size' => 24,
			'slug' => 'large'
		),
		array(
			'name' => esc_html__( 'Huge', 'roonix' ),
			'size' => 36,
			'slug' => 'huge'
		)
	) );
	
}
add_action( 'after_setup_theme', 'roonix_gutenberg_editor_palette_styles' );

/*---------- Gutenberg settings ends ----------*/

/*---------- Enqueue Styles and Scripts ----------*/

function roonix_enqueue_scripts() {
	$options = roonix_WSH()->option();
	
    //styles
	wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.css' );
	wp_enqueue_style( 'roonix-global', get_template_directory_uri() . '/assets/css/global.css' );
	wp_enqueue_style( 'header', get_template_directory_uri() . '/assets/css/header.css' );
	wp_enqueue_style( 'roonix-footer', get_template_directory_uri() . '/assets/css/footer.css' );
	wp_enqueue_style( 'roonix-icofont', get_template_directory_uri() . '/assets/css/icofont.css' );
	wp_enqueue_style( 'roonix-font-awesome', get_template_directory_uri() . '/assets/css/font-awesome.css' );
	wp_enqueue_style( 'flaticon', get_template_directory_uri() . '/assets/css/flaticon.css' );
	wp_enqueue_style( 'animate', get_template_directory_uri() . '/assets/css/animate.css' );
	wp_enqueue_style( 'owl', get_template_directory_uri() . '/assets/css/owl.css' );
	wp_enqueue_style( 'swiper', get_template_directory_uri() . '/assets/css/swiper.css' );
	wp_enqueue_style( 'linearicons', get_template_directory_uri() . '/assets/css/linearicons.css' );
	wp_enqueue_style( 'jquery-ui', get_template_directory_uri() . '/assets/css/jquery-ui.css' );
	wp_enqueue_style( 'preloader', get_template_directory_uri() . '/assets/css/preloader.css' );
	wp_enqueue_style( 'custom-animate', get_template_directory_uri() . '/assets/css/custom-animate.css' );
	wp_enqueue_style( 'magnific-popup', get_template_directory_uri() . '/assets/css/magnific-popup.css' );
	wp_enqueue_style( 'lightcase', get_template_directory_uri() . '/assets/css/lightcase.css' );
	wp_enqueue_style( 'jquery-bootstrap-touchspin', get_template_directory_uri() . '/assets/css/jquery.bootstrap-touchspin.css' );
	wp_enqueue_style( 'odometer-theme-default', get_template_directory_uri() . '/assets/css/odometer-theme-default.css' );
	wp_enqueue_style( 'jquery-mcustomscrollbar', get_template_directory_uri() . '/assets/css/jquery.mCustomScrollbar.min.css' );
	wp_enqueue_style( 'color-switcher-design', get_template_directory_uri() . '/assets/css/color-switcher-design.css' );
	wp_enqueue_style( 'default-color', get_template_directory_uri() . '/assets/css/color-themes/default-color.css' );
	wp_enqueue_style( 'roonix-main', get_stylesheet_uri() );
	wp_enqueue_style( 'roonix-main-style', get_template_directory_uri() . '/assets/css/style.css' );
    wp_enqueue_style( 'roonix-woocommerce', get_template_directory_uri() . '/assets/css/woocommerce.css' );
	wp_enqueue_style( 'roonix-custom', get_template_directory_uri() . '/assets/css/custom.css' );
	wp_enqueue_style( 'roonix-tut', get_template_directory_uri() . '/assets/css/tut.css' );
	wp_enqueue_style( 'roonix-gutenberg', get_template_directory_uri() . '/assets/css/gutenberg.css' );
	wp_enqueue_style( 'roonix-responsive', get_template_directory_uri() . '/assets/css/responsive.css' );
	
    //scripts
	wp_enqueue_script( 'jquery-ui-core');
	wp_enqueue_script( 'popper-min', get_template_directory_uri().'/assets/js/popper.min.js', array('jquery'), false, true );
	wp_enqueue_script( 'bootstrap', get_template_directory_uri().'/assets/js/bootstrap.min.js', array('jquery'), false, true );
	wp_enqueue_script( 'magnific-popup', get_template_directory_uri().'/assets/js/magnific-popup.min.js', array('jquery'), false, true );
	wp_enqueue_script( 'jquery-mcustomscrollbar-concat', get_template_directory_uri().'/assets/js/jquery.mCustomScrollbar.concat.min.js', array('jquery'), false, true );
	wp_enqueue_script( 'appear', get_template_directory_uri().'/assets/js/appear.js', array('jquery'), false, true );
	wp_enqueue_script( 'parallax', get_template_directory_uri().'/assets/js/parallax.min.js', array('jquery'), false, true );
	wp_enqueue_script( 'tilt-jquery', get_template_directory_uri().'/assets/js/tilt.jquery.min.js', array('jquery'), false, true );
	wp_enqueue_script( 'jquery-paroller', get_template_directory_uri().'/assets/js/jquery.paroller.min.js', array('jquery'), false, true );
	wp_enqueue_script( 'owl', get_template_directory_uri().'/assets/js/owl.js', array('jquery'), false, true );
	wp_enqueue_script( 'wow', get_template_directory_uri().'/assets/js/wow.js', array('jquery'), false, true );
	wp_enqueue_script( 'odometer', get_template_directory_uri().'/assets/js/odometer.js', array('jquery'), false, true );
	wp_enqueue_script( 'mixitup', get_template_directory_uri().'/assets/js/mixitup.js', array('jquery'), false, true );
	wp_enqueue_script( 'lightcase', get_template_directory_uri().'/assets/js/lightcase.js', array('jquery'), false, true );
	wp_enqueue_script( 'backtotop', get_template_directory_uri().'/assets/js/backToTop.js', array('jquery'), false, true );
	wp_enqueue_script( 'cursor-script', get_template_directory_uri().'/assets/js/cursor-script.js', array('jquery'), false, true );
	wp_enqueue_script( 'nav-tool', get_template_directory_uri().'/assets/js/nav-tool.js', array('jquery'), false, true );
	wp_enqueue_script( 'knob', get_template_directory_uri().'/assets/js/knob.js', array('jquery'), false, true );
	wp_enqueue_script( 'roonix-color-settings', get_template_directory_uri().'/assets/js/color-settings.js', array('jquery'), false, true );
	wp_enqueue_script( 'roonix-main-script', get_template_directory_uri().'/assets/js/script.js', array('jquery'), false, true );
	if( is_singular() ) wp_enqueue_script('comment-reply');
}
add_action( 'wp_enqueue_scripts', 'roonix_enqueue_scripts' );

/*---------- Enqueue styles and scripts ends ----------*/

/*---------- Google fonts ----------*/

function roonix_fonts_url() {
	
	$fonts_url = '';
	
		$font_families['Jost']     = 'Jost:wght@0,300,400,500,600,700,800,900&display=swap';
		$font_families['DM+Sans']     = 'DM Sans:wght@0,400,500,700&display=swap';
		$font_families['Roboto']      	= 'Roboto:wght@0,300,400,500,700,900&display=swap';

		$font_families = apply_filters( 'ROONIX/includes/classes/header_enqueue/font_families', $font_families );

		$query_args = array(
			'family' => urlencode( implode( '|', $font_families ) ),
			'subset' => urlencode( 'latin,latin-ext' ),
		);

		$protocol  = is_ssl() ? 'https' : 'http';
		$fonts_url = add_query_arg( $query_args, $protocol . '://fonts.googleapis.com/css' );

		return esc_url_raw($fonts_url);

}

function roonix_theme_styles() {
    wp_enqueue_style( 'roonix-theme-fonts', roonix_fonts_url(), array('jquery'), null );
}

add_action( 'wp_enqueue_scripts', 'roonix_theme_styles' );
add_action( 'admin_enqueue_scripts', 'roonix_theme_styles' );

/*---------- Google fonts ends ----------*/

/*---------- More functions ----------*/

// 1) roonix_set function

/**
 * [roonix_set description]
 *
 * @param  array $data [description]
 *
 * @return [type]       [description]
 */
if ( ! function_exists( 'roonix_set' ) ) {
	function roonix_set( $var, $key, $def = '' ) {

		if ( is_object( $var ) && isset( $var->$key ) ) {
			return $var->$key;
		} elseif ( is_array( $var ) && isset( $var[ $key ] ) ) {
			return $var[ $key ];
		} elseif ( $def ) {
			return $def;
		} else {
			return false;
		}
	}
}

// 2) roonix_add_editor_styles function

function roonix_add_editor_styles() {
    add_editor_style( 'editor-style.css' );
}
add_action( 'admin_init', 'roonix_add_editor_styles' );

// 3) Add specific CSS class by filter body class.

$options = roonix_WSH()->option(); 
if( roonix_set($options, 'boxed_wrapper') ){

add_filter( 'body_class', function( $classes ) {
    $classes[] = 'boxed_wrapper';
    return $classes;
} );
}


@ini_set( 'upload_max_size' , '256M' );
@ini_set( 'post_max_size', '256M');
@ini_set( 'max_execution_time', '300' );