<?php

if ( ! function_exists( 'ginevra_core_is_custom_cursor_enabled' ) ) {
	/**
	 * Function that check is module enabled
	 *
	 * @return bool
	 */
	function ginevra_core_is_custom_cursor_enabled() {
		return ginevra_core_get_post_value_through_levels( 'qodef_custom_cursor' ) !== 'no';
	}
}

if ( ! function_exists( 'ginevra_core_add_custom_cursor_body_classes' ) ) {
	/**
	 * Function that add additional class name into global class list for body tag
	 *
	 * @param array $classes
	 *
	 * @return array
	 */
	function ginevra_core_add_custom_cursor_body_classes( $classes ) {
		$classes[] = ginevra_core_is_custom_cursor_enabled() ? 'qodef-custom-cursor--enabled' : '';
		
		return $classes;
	}
	
	add_filter( 'body_class', 'ginevra_core_add_custom_cursor_body_classes' );
}

if ( ! function_exists( 'ginevra_core_load_custom_cursor' ) ) {
	/**
	 * Loads Back To Top HTML
	 */
	function ginevra_core_load_custom_cursor() {
		
		if ( ginevra_core_is_custom_cursor_enabled() ) {
			$parameters = array();

            ginevra_core_template_part( 'custom-cursor', 'templates/custom-cursor', '', $parameters );
		}
	}
	
	add_action( 'ginevra_action_before_wrapper_close_tag', 'ginevra_core_load_custom_cursor' );
}

if ( ! function_exists( 'ginevra_core_set_page_custom_cursor_styles' ) ) {
	/**
	 * Function that generates module inline styles
	 *
	 * @param string $style
	 *
	 * @return string
	 */
	function ginevra_core_set_page_custom_cursor_styles( $style ) {
		if ( ginevra_core_is_custom_cursor_enabled() ) {
			$cursor_styles = array();
			
			$cursor_color = ginevra_core_get_post_value_through_levels( 'qodef_custom_cursor_color' );
			
			if ( ! empty( $cursor_color ) ) {
				$cursor_styles['background-color'] = $cursor_color . '!important';
			}
			
			if ( ! empty( $cursor_styles ) ) {
				$style .= qode_framework_dynamic_style( '#qodef-custom-cursor .qodef-cursor-dot', $cursor_styles );
			}
			
			return $style;
		}
	}
	
	add_filter( 'ginevra_filter_add_inline_style', 'ginevra_core_set_page_custom_cursor_styles' );
}
