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

// enque files
if ( ! function_exists( 'yoga_meditation_enqueue_styles' ) ) :
	/**
	 * Load assets.
	 *
	 * @since 1.0.0
	 */
	function yoga_meditation_enqueue_styles() {
		wp_enqueue_style( 'yoga-studio-style-parent', get_template_directory_uri() . '/style.css' );
		wp_enqueue_style( 'yoga-meditation-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-meditation-style',$yoga_studio_custom_style );
		require get_theme_file_path( 'inc/extra_customization.php' );
		wp_add_inline_style( 'yoga-meditation-style',$yoga_studio_custom_style );

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

// theme setup
function yoga_meditation_setup() {
	load_theme_textdomain( 'yoga-meditation', 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-meditation-featured-image', 2000, 1200, true );
	add_image_size( 'yoga-meditation-thumbnail-avatar', 100, 100, true );

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

	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-height' => 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_meditation_setup' );

// header setup
function yoga_meditation_custom_header_setup() {
	add_theme_support( 'custom-header', apply_filters( 'yoga_meditation_custom_header_args', array(
		'default-image'          => get_parent_theme_file_uri( '/assets/images/header-img-2.png' ),
		'default-text-color'     => 'fff',
		'header-text' 			 =>	false,
		'width'                  => 1600,
		'height'                 => 100,
		'flex-width'			 => true,
		'flex-height'			 => true,
		'wp-head-callback'       => 'yoga_studio_header_style',
	) ) );
}
add_action( 'after_setup_theme', 'yoga_meditation_custom_header_setup' );

// widgets
function yoga_meditation_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Sidebar', 'yoga-meditation' ),
		'id'            => 'sidebar-1',
		'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'yoga-meditation' ),
		'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-meditation' ),
		'id'            => 'sidebar-2',
		'description'   => __( 'Add widgets here to appear in your pages and posts', 'yoga-meditation' ),
		'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-meditation' ),
		'id'            => 'sidebar-3',
		'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'yoga-meditation' ),
		'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-meditation' ),
		'id'            => 'footer-1',
		'description'   => __( 'Add widgets here to appear in your footer.', 'yoga-meditation' ),
		'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-meditation' ),
		'id'            => 'footer-2',
		'description'   => __( 'Add widgets here to appear in your footer.', 'yoga-meditation' ),
		'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-meditation' ),
		'id'            => 'footer-3',
		'description'   => __( 'Add widgets here to appear in your footer.', 'yoga-meditation' ),
		'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-meditation' ),
		'id'            => 'footer-4',
		'description'   => __( 'Add widgets here to appear in your footer.', 'yoga-meditation' ),
		'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_meditation_widgets_init' );

// remove sections
function yoga_meditation_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_footer_text');
	$wp_customize->remove_control('yoga_studio_footer_text');

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

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

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

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

	$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_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_meditation_customize_register', 11 );

// customizer
function yoga_meditation_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_meditation_pro', array(
		'title'    => __('🔒 Unlock Premium Features', 'yoga-meditation'),
		'priority' => 1,
	));
	$wp_customize->add_setting('yoga_meditation_pro', array(
		'default'           => null,
		'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control(new Yoga_Meditation_Pro_Control($wp_customize, 'yoga_meditation_pro', array(
		'label'    => __('YOGA MEDITATION PREMIUM', 'yoga-meditation'),
		'section'  => 'yoga_meditation_pro',
		'settings' => 'yoga_meditation_pro',
		'priority' => 1,
	)));

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

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

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

	// About
	$wp_customize->add_section( 'yoga_meditation_about_section' , array(
    	'title'      => __( 'About Settings', 'yoga-meditation' ),
		'priority'   => 5,
		'panel' => 'yoga_studio_custompage_panel',
	) );
	$wp_customize->add_setting( 'yoga_meditation_about_heading', array(
		'default'           => '',
		'transport'         => 'refresh',
		'sanitize_callback' => 'sanitize_text_field',
	) );
	$wp_customize->add_control( new Yoga_Meditation_Customizer_Customcontrol_Section_Heading( $wp_customize, 'yoga_meditation_about_heading', array(
		'label'       => esc_html__( 'About Settings', 'yoga-meditation' ),		
		'section'     => 'yoga_meditation_about_section',
		'settings'    => 'yoga_meditation_about_heading',
	) ) );
	$wp_customize->add_setting(
		'yoga_meditation_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_Meditation_Customizer_Customcontrol_Switch(
			$wp_customize,
			'yoga_meditation_about_enable',
			array(
				'settings'        => 'yoga_meditation_about_enable',
				'section'         => 'yoga_meditation_about_section',
				'label'           => __( 'Check to show About settings', 'yoga-meditation' ),				
				'choices'		  => array(
					'1'      => __( 'On', 'yoga-meditation' ),
					'off'    => __( 'Off', 'yoga-meditation' ),
				),
				'active_callback' => '',
			)
		)
	);

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

	$wp_customize->add_setting('yoga_meditation_about_post_setting',array(
		'sanitize_callback' => 'yoga_studio_sanitize_select',
	));
	$wp_customize->add_control('yoga_meditation_about_post_setting',array(
		'type'    => 'select',
		'choices' => $pst_sls,
		'label' => __('Select post','yoga-meditation'),
		'section' => 'yoga_meditation_about_section',
	));

	$wp_customize->selective_refresh->add_partial( 'yoga_meditation_about_post_setting', array(
	'selector' => '.about-box h2 a',
	'render_callback' => 'yoga_meditation_customize_partial_yoga_meditation_about_post_setting',
	) );

	wp_reset_postdata();

	$wp_customize->add_setting('yoga_meditation_footer_text',array(
        'default'   => 'Meditation WordPress Theme',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('yoga_meditation_footer_text',array(
        'label' => esc_html__('Copyright Text','yoga-meditation'),
        'section'   => 'yoga_studio_footer_copyright',
        'type'      => 'textarea'
    ));
    $wp_customize->selective_refresh->add_partial( 'yoga_meditation_footer_text', array(
      'selector' => '.site-info a',
      'render_callback' => 'yoga_studio_customize_partial_yoga_meditation_footer_text',
    ) );

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

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

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

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

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

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

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

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

// comments
function yoga_meditation_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_meditation_enqueue_comments_reply' );

// Footer Text
function yoga_meditation_copyright_link() {
    $yoga_meditation_footer_text = get_theme_mod('yoga_meditation_footer_text', esc_html__('Meditation WordPress Theme', 'yoga-meditation'));
    $yoga_meditation_credit_link = esc_url('https://www.ovationthemes.com/products/free-meditation-wordpress-theme');

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

/* Pro control */
if (class_exists('WP_Customize_Control') && !class_exists('Yoga_Meditation_Pro_Control')):
    class Yoga_Meditation_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;


