<?php
/**
 * Enqueue scripts and styles.
 */
function intimate_scripts() {

	/*google font  */
	global $intimate_theme_options;
	/*
	 * Fonts are served from the theme rather than from Google. A remote font
	 * request hands the visitor's IP address to a third party before they
	 * have consented to anything.
	 *
	 * Lora and Playfair Display are bundled here as well. style.css sets them
	 * on blockquotes, pull quotes, verse blocks, the search field and the
	 * calendar, but nothing ever loaded them, so they had been falling back
	 * to a generic serif.
	 */
	wp_enqueue_style( 'intimate-fonts', get_template_directory_uri() . '/assets/fonts/fonts.css', array(), INTIMATE_VERSION );
    
	//*Font-Awesome-master*/
    wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/css/font-awesome.min.css', array(), '4.7.0' );

    wp_enqueue_style( 'grid-css', get_template_directory_uri() . '/css/grid.css', array(), INTIMATE_VERSION );
    
    /*Slick CSS*/
    wp_enqueue_style( 'slick', get_template_directory_uri() . '/assets/css/slick.css', array(), '1.8.0' );

   /*Main CSS*/
    wp_enqueue_style( 'intimate-style', get_stylesheet_uri(), array(), INTIMATE_VERSION );

	/*RTL CSS*/
	wp_style_add_data( 'intimate-style', 'rtl', 'replace' );

    $intimate_pagination_option =  esc_attr($intimate_theme_options['intimate-pagination-options']);
    
    if( 'ajax' == $intimate_pagination_option )  {
    	
    	wp_enqueue_script( 'intimate-custom-pagination', get_template_directory_uri() . '/assets/js/custom-infinte-pagination.js', array( 'jquery' ), INTIMATE_VERSION, true );
    }

	wp_enqueue_script( 'intimate-navigation', get_template_directory_uri() . '/js/navigation.js', array(), INTIMATE_VERSION, true );

	/*Slick JS*/
    wp_enqueue_script( 'slick', get_template_directory_uri() . '/assets/js/slick.js', array( 'jquery' ), '1.8.0', true );
    
    $offcanvas =  absint($intimate_theme_options['intimate_enable_offcanvas']);
    if( 1  == $offcanvas )  {
        wp_enqueue_script( 'offcanvas-custom', get_template_directory_uri() . '/assets/js/canvas-custom.js', array( 'jquery' ), INTIMATE_VERSION, true );
    }
    
    
    /*Custom Script JS*/
	wp_enqueue_script( 'intimate-script', get_template_directory_uri() . '/assets/js/script.js', array(), INTIMATE_VERSION, true );
    
	/*Custom Scripts*/
	wp_enqueue_script( 'intimate-custom', get_template_directory_uri() . '/assets/js/custom.js', array( 'jquery' ), INTIMATE_VERSION, true );
    
	global $wp_query;
    $paged = ( get_query_var( 'paged' ) > 1 ) ? get_query_var( 'paged' ) : 1;
    $max_num_pages = $wp_query->max_num_pages;

    wp_localize_script( 'intimate-custom', 'intimate_ajax', array(
        'ajaxurl' => esc_url(admin_url( 'admin-ajax.php' )),
        'paged'     => absint($paged),
        'max_num_pages'      => absint($max_num_pages),
        'next_posts'      => next_posts( $max_num_pages, false ),
        'show_more'      => __( 'View More', 'intimate' ),
        'no_more_posts'        => __( 'No More', 'intimate' ),
    ));

	wp_enqueue_script( 'intimate-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), INTIMATE_VERSION, true );

	/*Sticky Sidebar*/
	global $intimate_theme_options;
	if( 1 == absint($intimate_theme_options['intimate-enable-sticky-sidebar'])) {
		wp_enqueue_script( 'theia-sticky-sidebar', get_template_directory_uri() . '/assets/js/theia-sticky-sidebar.js', array(), '20200412', true );
        wp_enqueue_script( 'intimate-sticky-sidebar', get_template_directory_uri() . '/assets/js/custom-sticky-sidebar.js', array(), INTIMATE_VERSION, true );
	}
    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script('comment-reply');
    }
}
add_action( 'wp_enqueue_scripts', 'intimate_scripts' );

/**
 * Enqueue fonts for the editor style
 */
function intimate_block_styles() {
    wp_enqueue_style( 'intimate-editor-styles', get_theme_file_uri( 'css/editor-styles.css' ), array(), INTIMATE_VERSION );

    /*
     * The same local fonts the front end uses. This previously re-registered
     * the handles 'intimate-body' and 'intimate-heading', which the front end
     * already owns, and requested them from Google.
     */
    wp_enqueue_style( 'intimate-fonts', get_template_directory_uri() . '/assets/fonts/fonts.css', array(), INTIMATE_VERSION );

    $intimate_custom_css = '
    .edit-post-visual-editor.editor-styles-wrapper{ font-family: Muli;}

    .editor-post-title__block .editor-post-title__input,
    .editor-styles-wrapper h1,
    .editor-styles-wrapper h2,
    .editor-styles-wrapper h3,
    .editor-styles-wrapper h4,
    .editor-styles-wrapper h5,
    .editor-styles-wrapper h6{font-family:Roboto;} 
    ';

    wp_add_inline_style( 'intimate-editor-styles', $intimate_custom_css );
}

add_action( 'enqueue_block_editor_assets', 'intimate_block_styles' );

