<?php
/**
 * Theme functions and definitions
 *
 * @package Yoga Coach
 */

// enque files
if ( ! function_exists( 'yoga_coach_enqueue_styles' ) ) :
	/**
	 * Load assets.
	 *
	 * @since 1.0.0
	 */
	function yoga_coach_enqueue_styles() {
		wp_enqueue_style( 'yoga-studio-style-parent', get_template_directory_uri() . '/style.css' );
		wp_enqueue_style( 'yoga-coach-style', get_stylesheet_directory_uri() . '/style.css', array( 'yoga-studio-style-parent' ), '1.0.0' );
		// Theme Customize CSS.
		require get_parent_theme_file_path( 'inc/extra_customization.php' );
		wp_add_inline_style( 'yoga-coach-style',$yoga_studio_custom_style );
		require get_theme_file_path( 'inc/extra_customization.php' );
		wp_add_inline_style( 'yoga-coach-style',$yoga_studio_custom_style );

		// blocks css
        wp_enqueue_style( 'yoga-coach-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'yoga-coach-style' ), '1.0' );
	}
endif;
add_action( 'wp_enqueue_scripts', 'yoga_coach_enqueue_styles', 99 );

// theme setuo
function yoga_coach_setup() {
	load_theme_textdomain( 'yoga-coach', get_template_directory() . '/languages' );
	add_theme_support( 'align-wide' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( "responsive-embeds" );
	add_theme_support( "wp-block-styles" );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );
	add_theme_support('custom-background',array(
		'default-color' => 'ffffff',
	));
	add_image_size( 'yoga-coach-featured-image', 2000, 1200, true );
	add_image_size( 'yoga-coach-thumbnail-avatar', 100, 100, true );

	$GLOBALS['content_width'] = 525;
	register_nav_menus( array(
		'primary' => __( 'Primary Menu', 'yoga-coach' ),
	) );

	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,
		'flex-width'  => true,
	) );

	/*
	* This theme styles the visual editor to resemble the theme style,
	* specifically font, colors, and column width.
	*/
	add_editor_style( array( 'assets/css/editor-style.css', yoga_studio_fonts_url() ) );

	if ( ! defined( 'YOGA_STUDIO_SUPPORT' ) ) {
			define('YOGA_STUDIO_SUPPORT',__('https://wordpress.org/support/theme/yoga-studio/','yoga-studio'));
		}
		if ( ! defined( 'YOGA_STUDIO_REVIEW' ) ) {
			define('YOGA_STUDIO_REVIEW',__('https://wordpress.org/support/theme/yoga-studio/reviews/','yoga-studio'));
		}
		if ( ! defined( 'YOGA_STUDIO_LIVE_DEMO' ) ) {
			define('YOGA_STUDIO_LIVE_DEMO',__('https://trial.ovationthemes.com/yoga-studio-pro/','yoga-studio'));
		}
		if ( ! defined( 'YOGA_STUDIO_BUY_PRO' ) ) {
			define('YOGA_STUDIO_BUY_PRO',__('https://www.ovationthemes.com/products/yoga-wordpress-theme','yoga-studio'));
		}
		if ( ! defined( 'YOGA_STUDIO_PRO_DOC' ) ) {
			define('YOGA_STUDIO_PRO_DOC',__('https://trial.ovationthemes.com/docs/ot-yoga-studio-pro-doc/','yoga-studio'));
		}
		if ( ! defined( 'YOGA_STUDIO_FREE_DOC' ) ) {
		define('YOGA_STUDIO_FREE_DOC',__('https://trial.ovationthemes.com/docs/ot-yoga-studio-free-doc/','yoga-studio'));
		}
		if ( ! defined( 'YOGA_STUDIO_THEME_NAME' ) ) {
			define('YOGA_STUDIO_THEME_NAME',__('Premium Yoga Studio Theme','yoga-studio'));
		}
}
add_action( 'after_setup_theme', 'yoga_coach_setup' );

// widgets
function yoga_coach_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Sidebar', 'yoga-coach' ),
		'id'            => 'sidebar-1',
		'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'yoga-coach' ),
		'before_widget' => '<section id="%1$s" class="widget wow zoomIn %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<div class="widget_container"><h3 class="widget-title">',
		'after_title'   => '</h3></div>',
	) );

	register_sidebar( array(
		'name'          => __( 'Page Sidebar', 'yoga-coach' ),
		'id'            => 'sidebar-2',
		'description'   => __( 'Add widgets here to appear in your pages and posts', 'yoga-coach' ),
		'before_widget' => '<section id="%1$s" class="widget wow zoomIn %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<div class="widget_container"><h3 class="widget-title">',
		'after_title'   => '</h3></div>',
	) );
	
	register_sidebar( array(
		'name'          => __( 'Sidebar 3', 'yoga-coach' ),
		'id'            => 'sidebar-3',
		'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'yoga-coach' ),
		'before_widget' => '<section id="%1$s" class="widget wow zoomIn %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<div class="widget_container"><h3 class="widget-title">',
		'after_title'   => '</h3></div>',
	) );

	register_sidebar( array(
		'name'          => __( 'Footer 1', 'yoga-coach' ),
		'id'            => 'footer-1',
		'description'   => __( 'Add widgets here to appear in your footer.', 'yoga-coach' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Footer 2', 'yoga-coach' ),
		'id'            => 'footer-2',
		'description'   => __( 'Add widgets here to appear in your footer.', 'yoga-coach' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Footer 3', 'yoga-coach' ),
		'id'            => 'footer-3',
		'description'   => __( 'Add widgets here to appear in your footer.', 'yoga-coach' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Footer 4', 'yoga-coach' ),
		'id'            => 'footer-4',
		'description'   => __( 'Add widgets here to appear in your footer.', 'yoga-coach' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
}
add_action( 'widgets_init', 'yoga_coach_widgets_init' );

// remove sections
function yoga_coach_customize_register() {
  	global $wp_customize;

  	$wp_customize->remove_section( 'yoga_studio_pro' );

	$wp_customize->remove_setting( 'yoga_studio_top_text' );
	$wp_customize->remove_control( 'yoga_studio_top_text' );

	$wp_customize->remove_setting('yoga_studio_slider_content_alignment');
	$wp_customize->remove_control('yoga_studio_slider_content_alignment');

	$wp_customize->remove_setting('yoga_studio_primary_color');
	$wp_customize->remove_control('yoga_studio_primary_color');

	$wp_customize->remove_setting('yoga_studio_heading_color');
	$wp_customize->remove_control('yoga_studio_heading_color');

	$wp_customize->remove_setting('yoga_studio_text_color');
	$wp_customize->remove_control('yoga_studio_text_color');

	$wp_customize->remove_setting('yoga_studio_primary_fade');
	$wp_customize->remove_control('yoga_studio_primary_fade');

	$wp_customize->remove_setting('yoga_studio_footer_bg');
	$wp_customize->remove_control('yoga_studio_footer_bg');

	$wp_customize->remove_setting('yoga_studio_slider_opacity');
	$wp_customize->remove_control('yoga_studio_slider_opacity');

	$wp_customize->remove_setting('yoga_studio_slider_overlay');
	$wp_customize->remove_control('yoga_studio_slider_overlay');

	$wp_customize->remove_setting('yoga_studio_slider_design_color');
	$wp_customize->remove_control('yoga_studio_slider_design_color');

}
add_action( 'customize_register', 'yoga_coach_customize_register', 11 );

// customizer
function yoga_coach_customize( $wp_customize ) {

	wp_enqueue_style('customizercustom_css', esc_url( get_stylesheet_directory_uri() ). '/assets/css/customizer.css');

	require get_theme_file_path( 'inc/custom-control.php' );

	// pro section
	$wp_customize->add_section('yoga_coach_pro', array(
		'title'    => __('🔒 Unlock Premium Features', 'yoga-coach'),
		'priority' => 1,
	));
	$wp_customize->add_setting('yoga_coach_pro', array(
		'default'           => null,
		'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control(new Yoga_Coach_Pro_Control($wp_customize, 'yoga_coach_pro', array(
		'label'    => __('YOGA COACH PREMIUM', 'yoga-coach'),
		'section'  => 'yoga_coach_pro',
		'settings' => 'yoga_coach_pro',
		'priority' => 1,
	)));

	// header section
    $wp_customize->add_setting('yoga_coach_email',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('yoga_coach_email',array(
		'label' => esc_html__('Add Email Address','yoga-coach'),
		'section' => 'yoga_studio_top',
		'setting' => 'yoga_coach_email',
		'type'    => 'text',
	));
	$wp_customize->selective_refresh->add_partial( 'yoga_coach_email', array(
		'selector' => '.top_bar i',
		'render_callback' => 'yoga_coach_customize_partial_yoga_coach_email',
	) );

	$wp_customize->add_setting('yoga_coach_slider_heading_color', array(
	    'default' => '#18192c',
	    'sanitize_callback' => 'sanitize_hex_color',
	    'transport' => 'refresh',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'yoga_coach_slider_heading_color', array(
	    'section' => 'yoga_studio_slider_section',
	    'label' => esc_html__('Slider Title Color', 'yoga-coach'),
	 	'priority'    => 2,
	)));

	$wp_customize->add_setting('yoga_coach_slider_excerpt_color', array(
	    'default' => '#18192c',
	    'sanitize_callback' => 'sanitize_hex_color',
	    'transport' => 'refresh',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'yoga_coach_slider_excerpt_color', array(
	    'section' => 'yoga_studio_slider_section',
	    'label' => esc_html__('Slider excerpt Color', 'yoga-coach'),
	 	'priority'    => 3,
	)));

	// slider content alignment
    $wp_customize->add_setting('yoga_coach_slider_content_alignment',array(
        'default' => 'LEFT-ALIGN',
        'sanitize_callback' => 'yoga_studio_sanitize_choices'
    ));
    $wp_customize->add_control('yoga_coach_slider_content_alignment',array(
        'type' => 'radio',
        'label'     => __('Slider Content Alignment', 'yoga-coach'),
        'section' => 'yoga_studio_slider_section',
        'type' => 'select',
        'choices' => array(
            'LEFT-ALIGN' => __('LEFT','yoga-coach'),
            'CENTER-ALIGN' => __('CENTER','yoga-coach'),
            'RIGHT-ALIGN' => __('RIGHT','yoga-coach'),
        ),
        'priority'   => 5,
    ) );

    $wp_customize->add_setting('yoga_coach_slider_overlay', array(
	    'default' => '#ffffff',
	    'sanitize_callback' => 'sanitize_hex_color',
	    'transport' => 'refresh',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'yoga_coach_slider_overlay', array(
	    'section' => 'yoga_studio_slider_section',
	    'label' => esc_html__('Slider Overlay', 'yoga-coach'),
	 	'priority'    => 6,
	)));

    $wp_customize->add_setting('yoga_coach_slider_opacity',array(
        'default' => '0.6',
        'sanitize_callback' => 'yoga_studio_sanitize_choices'
    ));
    $wp_customize->add_control('yoga_coach_slider_opacity',array(
        'type' => 'radio',
        'label'     => __('Slider Opacity', 'yoga-coach'),
        'section' => 'yoga_studio_slider_section',
        'type' => 'select',
        'choices' => array(
            '0' => __('0','yoga-coach'),
            '0.1' => __('0.1','yoga-coach'),
            '0.2' => __('0.2','yoga-coach'),
            '0.3' => __('0.3','yoga-coach'),
            '0.4' => __('0.4','yoga-coach'),
            '0.5' => __('0.5','yoga-coach'),
            '0.6' => __('0.6','yoga-coach'),
            '0.7' => __('0.7','yoga-coach'),
            '0.8' => __('0.8','yoga-coach'),
            '0.9' => __('0.9','yoga-coach'),
            '1' => __('1','yoga-coach')
        ),
    ) );

	// About
	$wp_customize->add_section( 'yoga_coach_about_section' , array(
    	'title'      => __( 'About Settings', 'yoga-coach' ),
		'priority'   => 5,
		'panel' => 'yoga_studio_custompage_panel',
	) );
	$wp_customize->add_setting( 'yoga_coach_about_heading', array(
		'default'           => '',
		'transport'         => 'refresh',
		'sanitize_callback' => 'sanitize_text_field',
	) );
	$wp_customize->add_control( new Yoga_Coach_Customizer_Customcontrol_Section_Heading( $wp_customize, 'yoga_coach_about_heading', array(
		'label'       => esc_html__( 'About Settings', 'yoga-coach' ),		
		'section'     => 'yoga_coach_about_section',
		'settings'    => 'yoga_coach_about_heading',
	) ) );
	$wp_customize->add_setting(
		'yoga_coach_about_enable',
		array(
			'type'                 => 'option',
			'capability'           => 'edit_theme_options',
			'theme_supports'       => '',
			'default'              => '1',
			'transport'            => 'refresh',
			'sanitize_callback'    => 'yoga_studio_callback_sanitize_switch',
		)
	);
	$wp_customize->add_control(
		new Yoga_Coach_Customizer_Customcontrol_Switch(
			$wp_customize,
			'yoga_coach_about_enable',
			array(
				'settings'        => 'yoga_coach_about_enable',
				'section'         => 'yoga_coach_about_section',
				'label'           => __( 'Check to show About settings', 'yoga-coach' ),				
				'choices'		  => array(
					'1'      => __( 'On', 'yoga-coach' ),
					'off'    => __( 'Off', 'yoga-coach' ),
				),
				'active_callback' => '',
			)
		)
	);

	$yoga_coach_args = array('numberposts' => -1);
	$post_list = get_posts($yoga_coach_args);
	$pst_sls[]= __('Select','yoga-coach');
	foreach ($post_list as $key => $p_post) {
		$pst_sls[$p_post->ID]=$p_post->post_title;
	}

	$wp_customize->add_setting('yoga_coach_about_post_setting',array(
		'sanitize_callback' => 'yoga_studio_sanitize_select',
	));
	$wp_customize->add_control('yoga_coach_about_post_setting',array(
		'type'    => 'select',
		'choices' => $pst_sls,
		'label' => __('Select post','yoga-coach'),
		'section' => 'yoga_coach_about_section',
	));
	$wp_customize->selective_refresh->add_partial( 'yoga_coach_about_post_setting', array(
		'selector' => '.about-box h2 a',
		'render_callback' => 'yoga_coach_top_customize_partial_yoga_coach_about_post_setting',
	) );

	wp_reset_postdata();

	$wp_customize->add_setting('yoga_coach_primary_color', array(
	    'default' => '#878aec',
	    'sanitize_callback' => 'sanitize_hex_color',
	    'transport' => 'refresh',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'yoga_coach_primary_color', array(
	    'section' => 'colors',
	    'label' => esc_html__('Theme Color', 'yoga-coach'),
	 
	)));

	$wp_customize->add_setting('yoga_coach_heading_color', array(
	    'default' => '#18192c',
	    'sanitize_callback' => 'sanitize_hex_color',
	    'transport' => 'refresh',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'yoga_coach_heading_color', array(
	    'section' => 'colors',
	    'label' => esc_html__('Theme Heading Color', 'yoga-coach'),
	 
	)));

	$wp_customize->add_setting('yoga_coach_text_color', array(
	    'default' => '#82828c',
	    'sanitize_callback' => 'sanitize_hex_color',
	    'transport' => 'refresh',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'yoga_coach_text_color', array(
	    'section' => 'colors',
	    'label' => esc_html__('Theme Text Color', 'yoga-coach'),
	 
	)));

	$wp_customize->add_setting('yoga_coach_primary_fade', array(
	    'default' => '#d8d9ff',
	    'sanitize_callback' => 'sanitize_hex_color',
	    'transport' => 'refresh',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'yoga_coach_primary_fade', array(
	    'section' => 'colors',
	    'label' => esc_html__('theme Color Light', 'yoga-coach'),
	 
	)));

	$wp_customize->add_setting('yoga_coach_footer_bg', array(
	    'default' => '#18192c',
	    'sanitize_callback' => 'sanitize_hex_color',
	    'transport' => 'refresh',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'yoga_coach_footer_bg', array(
	    'section' => 'colors',
	    'label' => esc_html__('Footer Bg color', 'yoga-coach'),
	)));
}
add_action( 'customize_register', 'yoga_coach_customize' );

// comments
function yoga_coach_enqueue_comments_reply() {
  if( is_singular() && comments_open() && ( get_option( 'thread_comments' ) == 1) ) {
    // Load comment-reply.js (into footer)
    wp_enqueue_script( 'comment-reply', '/wp-includes/js/comment-reply.min.js', array(), false, true );
  }
}
add_action(  'wp_enqueue_scripts', 'yoga_coach_enqueue_comments_reply' );

// Footer Text
function yoga_coach_copyright_link() {
    $yoga_coach_footer_text = get_theme_mod('yoga_studio_footer_text', esc_html__('Yoga WordPress Theme', 'yoga-coach'));
    $yoga_coach_credit_link = esc_url('https://www.ovationthemes.com/products/free-yoga-coach-wordpress-theme');

    echo '<a href="' . $yoga_coach_credit_link . '" target="_blank">' . esc_html($yoga_coach_footer_text) . '<span class="footer-copyright">' . esc_html__(' By Ovation Themes', 'yoga-coach') . '</span></a>';
}

/* Pro control */
if (class_exists('WP_Customize_Control') && !class_exists('Yoga_Coach_Pro_Control')):
    class Yoga_Coach_Pro_Control extends WP_Customize_Control{

    public function render_content(){?>
        <div style="background: linear-gradient(135deg, #2B136B 0%, #A47AE2 100%); padding: 20px; border-radius: 8px; text-align: center; color: #fff;">
			
			<h3 style="margin-top: 0; color: #fff;">
				<?php esc_html_e('Unlock Advanced Features', 'yoga-studio'); ?>
			</h3>
	
			<p style="margin: 15px 0;">
				<?php esc_html_e('Upgrade to Pro to get:', 'yoga-studio'); ?>
			</p>
	
			<ul style="list-style: none; padding: 0; text-align: left; max-width: 300px; margin: 20px auto;">
				<li>✓ <?php esc_html_e('12+ Premium Header Layouts', 'yoga-studio'); ?></li>
				<li>✓ <?php esc_html_e('Advanced Footer Builder', 'yoga-studio'); ?></li>
				<li>✓ <?php esc_html_e('Typography Controls', 'yoga-studio'); ?></li>
				<li>✓ <?php esc_html_e('WooCommerce Styling Options', 'yoga-studio'); ?></li>
				<li>✓ <?php esc_html_e('Priority Support', 'yoga-studio'); ?></li>
				<li>✓ <?php esc_html_e('One-Click Demo Import', 'yoga-studio'); ?></li>
			</ul>
	
			<a href="<?php echo esc_url(admin_url('themes.php?page=yoga-studio-pro')); ?>"
				style="display:inline-block;background:#fff;color:#667eea;padding:12px 30px;text-decoration:none;border-radius:4px;font-weight:600;margin:10px 5px;">
				<?php esc_html_e('View All Features', 'yoga-studio'); ?>
			</a>
	
			<a href="<?php echo esc_url( YOGA_STUDIO_BUY_PRO ); ?>" target="_blank"
				style="display:inline-block;background:#ffc107;color:#333;padding:12px 30px;text-decoration:none;border-radius:4px;font-weight:600;margin:10px 5px;">
				<?php esc_html_e('Upgrade Now 🚀', 'yoga-studio'); ?>
			</a>

			<a href="<?php echo esc_url( YOGA_STUDIO_BUNDLE_LINK ); ?>" target="_blank"
				style="display: inline-block; background: #28a745; color: #fff; padding: 12px 30px; text-decoration: none; border-radius: 4px; font-weight: 600; margin: 10px 5px;">
				<?php esc_html_e('WordPress Bundle 🎁', 'yoga-studio'); ?>
			</a>
	
		</div>
    <?php } }
endif;
