<?php
/**
 * IS-Medify functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package IS-Medify
 * 
 * @since 1.0.0
 * 
*/

/**
 * Implement the Custom Header feature...
 */
require get_template_directory() . '/inc/custom-header.php';

/**
 * Custom template tags for this theme...
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Functions which enhance the theme by hooking into WordPress...
 */
require get_template_directory() . '/inc/template-functions.php';

/**
 * Customizer additions...
 */
require get_template_directory() . '/inc/customizer.php';
/**
 * Customizer theme option...
 */
require( get_template_directory() . '/customizer.php' );

/**
 * Load Jetpack compatibility file...
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require get_template_directory() . '/inc/jetpack.php';
}

/**
	* Theme Enqueue script And style...
*/
require get_template_directory() . '/inc/enqueue-script-style.php';

/**
	* Theme Sidebar...
*/
require get_template_directory() . '/inc/widgets-sidebar.php';

/**
   * Initialize Theme...
*/
require get_template_directory() . '/inc/theme-setup.php';

/**
   * File For IS-Medify Theme Header Default Menu Walker...
*/
require( get_template_directory(). '/inc/menu/default_menu_walker.php' );

/**
   * File For IS-Medify Theme Header Nav Walker...
*/
require( get_template_directory(). '/inc/menu/is_medify_nav_walker.php' );

/**
   * File For Comment List Function...
*/
require( get_template_directory() . '/inc/comment-function.php' );

/**
   * File For Content 404 Page...
*/
require( get_template_directory() . '/inc/views/content_404_page.php' );

/**
   * File For Content Page...
*/
require( get_template_directory() . '/inc/views/content_page.php' );

/**
   * File For Content Index Blog Page...
*/
require( get_template_directory() . '/inc/views/content_index_page.php' );

/**
   * File For Content Single Page / Blog / Post...
*/
require( get_template_directory() . '/inc/views/content_single_page.php' );

/**
   * File For Content Archive Page...
*/
require( get_template_directory() . '/inc/views/content_archive_page.php' );

/**
   * File For Content Search Page...
*/
require( get_template_directory() . '/inc/views/content_search_page.php' );

/**
   * File For Menu Header...
*/
require( get_template_directory() . '/inc/views/content_menu_header.php' );

/**
   * File For Menu Header...
*/
require( get_template_directory() . '/inc/views/content_footer.php' );

/**
   * File For Full Width Template
*/
require( get_template_directory() . '/inc/views/content_full_width.php' );

/* left sidebar */
require( get_template_directory() . '/inc/views/content_left_sidebar.php' );

if ( is_admin() ) {
	require_once('core/admin/admin-themes.php');
	
}



/* theme style */
function is_medify_theme_style(){
		
		/* Web Fonts Typography Settings code start */		

        wp_enqueue_style('ismedify-google-fonts',esc_url(is_medify2()));
		
		$font_var          = '300,400,600,700,900,300italic,400italic,600italic,700italic,900italic';
        $http              = ( ! empty( $_SERVER['HTTPS'] ) ) ? "https" : "http";
        $main_heading_font = str_replace( ' ' , '+', get_theme_mod( 'main_heading_font', 'Open Sans' ) );
        $menu_font         = str_replace( ' ' , '+', get_theme_mod( 'menu_font', 'Open Sans' ) );
        $theme_title       = str_replace( ' ' , '+', get_theme_mod( 'theme_title', 'Open Sans' ) );
        $desc_font_all     = str_replace( ' ' , '+', get_theme_mod( 'desc_font_all', 'Open Sans' ) );

        wp_enqueue_style('main_heading_font', $http . '://fonts.googleapis.com/css?family=' . $main_heading_font . ':' . $font_var);	
        wp_enqueue_style('menu_font', $http . '://fonts.googleapis.com/css?family=' . $menu_font . ':' . $font_var);	
        wp_enqueue_style('theme_title', $http . '://fonts.googleapis.com/css?family=' . $theme_title . ':' . $font_var);
        wp_enqueue_style('desc_font_all', $http . '://fonts.googleapis.com/css?family=' . $desc_font_all . ':' . $font_var);
		
}
add_action( 'wp_enqueue_scripts', 'is_medify_theme_style' );







// Register Sidebars (Widgets Areas)
function is_medify_widgets_init() {
    // Register Sidebar (Primary Sidebar)
    register_sidebar( array(
        'name'          => __( 'Sidebar', 'is_medify' ),
        'id'            => 'is_medify-sidebar', // Unique ID for the sidebar
        'description'   => __( 'The Sidebar Widget Area', 'is_medify' ),
        'before_widget' => '<div id="%1$s" class="row w_sidebar %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2>',
        'after_title'   => '</h2>',
    ) );

    // Register Footer Widget Area
    register_sidebar( array(
        'name'          => __( 'Footer Widget Area', 'is_medify' ),
        'id'            => 'is_medify-footer', // Unique ID for the footer
        'description'   => __( 'Footer Widget Area', 'is_medify' ),
        'before_widget' => '<div id="%1$s" class="col-md-3 col-sm-6 footer-widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<div class="col-md-12 widget-heading"><h1>',
        'after_title'   => '</h1></div>',
    ) );             
}
add_action( 'widgets_init', 'is_medify_widgets_init' );




// Set Default Theme Settings
function is_medify_default_settings() {
    // Check if the theme options already exist
    if ( get_option( 'is_medify_theme_options' ) === false ) {
        $is_medify_theme_options = array(
            // Default Footer Setting
            'is_medify_footer_areas' => 'on',
        );

        // Save these options to the database using set_theme_mod
        set_theme_mod( 'is_medify_theme_options', $is_medify_theme_options );
    }
}
add_action( 'after_setup_theme', 'is_medify_default_settings' );




/* Add Typography Settings code start */	
add_action('wp_enqueue_scripts', 'is_medify_custom_css');
function is_medify_custom_css()
{
    $output = '';
	
	$output .= '.logo, .site-title, .site-description {
		font-family: ' . get_theme_mod('main_heading_font', 'Open Sans') . '!important;
		}
		.navbar-nav, .navbar-nav > li > .dropdown-menu {
			font-family: ' . get_theme_mod('menu_font', 'Open Sans') . '!important ;
		}
		h1, h2, h3, h4, h5, h6{
			font-family: ' . get_theme_mod('theme_title', 'Open Sans') . ';
		}
       
		
		html, body, p, table, caption, tbody, tfoot, thead, tr, th, td, input, button, select, textarea {
			font-family: ' . get_theme_mod('desc_font_all', 'Open Sans') . ';
		}';

    
    $output     .='
    .logo img{
        height:'.esc_attr(get_theme_mod('logo_height','100')).'px;
        width:'.esc_attr(get_theme_mod('logo_width','100')).'px;
    }';
    //custom css
    $custom_css = get_theme_mod('custom_css') ; 
    if (!empty ($custom_css)) {
        $output .= get_theme_mod('custom_css') . "\n";
    }

    wp_register_style('custom-header-style', false);
    wp_enqueue_style('custom-header-style', get_template_directory_uri() . '/css/custom-header-style.css');
    wp_add_inline_style('custom-header-style', $output);
}
/* Add Typography Settings code end */



function is_medify2() {
	// Include google webfont locally Typography Settings //
	require_once get_theme_file_path( 'inc/wptt-webfont-loader.php' );
	
	$font_families = array(
		'Open Sans:wght@300;400;600;700;900'
	);

	$fonts_url = add_query_arg( array(
		'family' => implode( '&family=', $font_families ),
		'display' => 'swap',
		'subset' => 'latin,latin-ext',
	), 'https://fonts.googleapis.com/css2' );
	
	$contents = wptt_get_webfont_url( esc_url_raw( $fonts_url ) );
	
	// Load the webfont.
	wp_enqueue_style(
		'Open Sans',
		$contents,
		array(),
		'1.0'
	);}
/* Web Fonts Typography Settings code end */