<?php
/**
 * Theme functions and definitions
 *
 * @package minimal_education
 */

//enque files
if ( ! function_exists( 'minimal_education_enqueue_styles' ) ) :
	/**
	 * Load assets.
	 *
	 * @since 1.0.0
	 */
	function minimal_education_enqueue_styles() {
		wp_enqueue_style( 'education-insight-style-parent', get_template_directory_uri() . '/style.css' );
		wp_enqueue_style( 'minimal-education-style', get_stylesheet_directory_uri() . '/style.css', array( 'education-insight-style-parent' ), '1.0.0' );

    // Theme Customize CSS.
    require get_parent_theme_file_path( 'inc/extra_customization.php' );
    wp_add_inline_style( 'minimal-education-style',$education_insight_custom_style );

    require get_theme_file_path( 'inc/extra_customization.php' );
    wp_add_inline_style( 'minimal-education-style',$education_insight_custom_style );

    // blocks css
    wp_enqueue_style( 'minimal-education-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'minimal-education-style' ), '1.0' );
	}
endif;
add_action( 'wp_enqueue_scripts', 'minimal_education_enqueue_styles', 99 );

//theme setup
function minimal_education_setup() {
	load_theme_textdomain( 'minimal-education', get_template_directory() . '/languages' );
  add_theme_support( "align-wide" );
  add_theme_support( "wp-block-styles" );
  add_theme_support( 'responsive-embeds' );
  add_theme_support( 'automatic-feed-links' );
  add_theme_support( 'post-thumbnails' );
  add_theme_support( 'title-tag' );
  add_theme_support('custom-background',array(
    'default-color' => 'ffffff',
  ));

  $GLOBALS['content_width'] = 525;

  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', education_insight_fonts_url() ) );

  if ( ! defined( 'MINIMAL_EDUCATION_PRO_LINK' ) ) {
  define('MINIMAL_EDUCATION_PRO_LINK',__('https://www.ovationthemes.com/products/education-coach-wordpress-theme','minimal-education'));
    }
    if ( ! defined( 'EDUCATION_INSIGHT_SUPPORT' ) ) {
      define('EDUCATION_INSIGHT_SUPPORT',__('https://wordpress.org/support/theme/minimal-education/','minimal-education'));
    }
    if ( ! defined( 'EDUCATION_INSIGHT_REVIEW' ) ) {
      define('EDUCATION_INSIGHT_REVIEW',__('https://wordpress.org/support/theme/minimal-education/reviews/','minimal-education'));
    }
    if ( ! defined( 'EDUCATION_INSIGHT_LIVE_DEMO' ) ) {
    define('EDUCATION_INSIGHT_LIVE_DEMO',__('https://trial.ovationthemes.com/education-insight/','minimal-education'));
    }
    if ( ! defined( 'EDUCATION_INSIGHT_BUY_PRO' ) ) {
    define('EDUCATION_INSIGHT_BUY_PRO',__('https://www.ovationthemes.com/products/education-wordpress-theme','minimal-education'));
    }
    if ( ! defined( 'EDUCATION_INSIGHT_PRO_DOC' ) ) {
    define('EDUCATION_INSIGHT_PRO_DOC',__('https://trial.ovationthemes.com/docs/ot-education-insight-pro/','minimal-education'));
    }
    if ( ! defined( 'EDUCATION_INSIGHT_FREE_DOC' ) ) {
    define('EDUCATION_INSIGHT_FREE_DOC',__('https://trial.ovationthemes.com/docs/ot-minimal-education-free-doc/','minimal-education'));
    }
    if ( ! defined( 'EDUCATION_INSIGHT_THEME_NAME' ) ) {
    define('EDUCATION_INSIGHT_THEME_NAME',__('Premium Education Theme','minimal-education'));
    }
}
add_action( 'after_setup_theme', 'minimal_education_setup' );

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

// remove sections
function minimal_education_customize_register() {
    global $wp_customize;
  $wp_customize->remove_section( 'education_insight_pro' );
  $wp_customize->remove_setting( 'education_insight_slider_content_alignment' );
  $wp_customize->remove_control( 'education_insight_slider_content_alignment' );
  //color
  $wp_customize->remove_setting( 'education_insight_primary_color' );
  $wp_customize->remove_control( 'education_insight_primary_color' );
  $wp_customize->remove_setting( 'education_insight_primary_fade' );
  $wp_customize->remove_control( 'education_insight_primary_fade' );
  $wp_customize->remove_setting( 'education_insight_secondary_color' );
  $wp_customize->remove_control( 'education_insight_secondary_color' );
  $wp_customize->remove_setting( 'education_insight_third_color' );
  $wp_customize->remove_control( 'education_insight_third_color' );
  $wp_customize->remove_setting( 'education_insight_fourth_color' );
  $wp_customize->remove_control( 'education_insight_fourth_color' );
  $wp_customize->remove_setting( 'education_insight_slider_heading_color' );
  $wp_customize->remove_control( 'education_insight_slider_heading_color' );
}
add_action( 'customize_register', 'minimal_education_customize_register', 11 );

// remove themelocation
function minimal_education_remove_parent_theme_locations(){
    unregister_nav_menu( 'primary-1' );
    unregister_nav_menu( 'primary-2' );
 }
 add_action( 'after_setup_theme', 'minimal_education_remove_parent_theme_locations', 20 );

// comments
function minimal_education_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', 'minimal_education_enqueue_comments_reply' );

// Footer Text
function minimal_education_copyright_link() {
    $minimal_education_footer_text = get_theme_mod('education_insight_footer_text', esc_html__('Education WordPress Theme', 'minimal-education'));
    $minimal_education_credit_link = esc_url('https://www.ovationthemes.com/products/free-minimal-education-wordpress-theme');

    echo '<a href="' . $minimal_education_credit_link . '" target="_blank">' . esc_html($minimal_education_footer_text) . '<span class="footer-copyright">' . esc_html__(' By Ovation Themes', 'minimal-education') . '</span></a>';
}

// customizer
function minimal_education_customize( $wp_customize ) {

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

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

  // pro control
  $wp_customize->add_section('minimal_education_pro', array(
    'title'    => __('🔒 Unlock Premium Features', 'minimal-education'),
    'priority' => 1,
  ));
  $wp_customize->add_setting('minimal_education_pro', array(
    'default'           => null,
    'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control(new Minimal_Education_Pro_Control($wp_customize, 'minimal_education_pro', array(
    'label'    => __('EDUCATION PREMIUM', 'minimal-education'),
    'section'  => 'minimal_education_pro',
    'settings' => 'minimal_education_pro',
    'priority' => 1,
  )));

  $wp_customize->add_setting('minimal_education_slider_heading_color', array(
      'default' => '#2c2c2c',
      'sanitize_callback' => 'sanitize_hex_color',
      'transport' => 'refresh',
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'minimal_education_slider_heading_color', array(
      'section' => 'education_insight_slider_section',
      'label' => esc_html__('Slider Title Color', 'minimal-education'),
    'priority'    => 2,
  )));

  // slider content alignment
  $wp_customize->add_setting('minimal_education_slider_content_alignment',array(
        'default' => 'LEFT-ALIGN',
        'sanitize_callback' => 'education_insight_sanitize_choices'
  ));
  $wp_customize->add_control('minimal_education_slider_content_alignment',array(
    'type' => 'radio',
    'label'     => __('Slider Content Alignment', 'minimal-education'),
    'section' => 'education_insight_slider_section',
    'type' => 'select',
    'choices' => array(
      'LEFT-ALIGN' => __('LEFT','minimal-education'),
      'CENTER-ALIGN' => __('CENTER','minimal-education'),
      'RIGHT-ALIGN' => __('RIGHT','minimal-education'),
    ),
    'priority'    => 7,
  ) );

  // admission btn
  $wp_customize->add_setting('education_insight_admission_text',array(
    'default' => '',
    'sanitize_callback'  => 'sanitize_text_field'
  ));
  $wp_customize->add_control('education_insight_admission_text',array(
    'type' => 'text',
    'label' => __('Button Text','minimal-education'),
    'section' => 'education_insight_top',
  ));
  $wp_customize->selective_refresh->add_partial( 'education_insight_admission_text', array(
    'selector' => '.admision-btn a',
    'render_callback' => 'education_insight_customize_partial_education_insight_admission_text',
  ) );
  $wp_customize->add_setting('education_insight_admission_link',array(
    'default' => '',
    'sanitize_callback'  => 'esc_url_raw'
  ));
  $wp_customize->add_control('education_insight_admission_link',array(
    'type' => 'url',
    'label' => __('Button Link','minimal-education'),
    'section' => 'education_insight_top',
  ));

  //color
  $wp_customize->add_setting('minimal_education_primary_color', array(
      'default' => '#01b509',
      'sanitize_callback' => 'sanitize_hex_color',
      'transport' => 'refresh',
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'minimal_education_primary_color', array(
      'section' => 'colors',
      'label' => esc_html__('Theme Color', 'minimal-education'),
   
  )));
  
  $wp_customize->add_setting('minimal_education_primary_fade', array(
      'default' => '#e5f7e6',
      'sanitize_callback' => 'sanitize_hex_color',
      'transport' => 'refresh',
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'minimal_education_primary_fade', array(
      'section' => 'colors',
      'label' => esc_html__('Theme Color Fade', 'minimal-education'),
   
  )));
  $wp_customize->add_setting('minimal_education_secondary_color', array(
      'default' => '#e98401',
      'sanitize_callback' => 'sanitize_hex_color',
      'transport' => 'refresh',
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'minimal_education_secondary_color', array(
      'section' => 'colors',
      'label' => esc_html__('Second Color', 'minimal-education'),
   
  )));
  $wp_customize->add_setting('minimal_education_third_color', array(
      'default' => '#238fbb',
      'sanitize_callback' => 'sanitize_hex_color',
      'transport' => 'refresh',
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'minimal_education_third_color', array(
      'section' => 'colors',
      'label' => esc_html__('third Color', 'minimal-education'),
   
  )));
  $wp_customize->add_setting('minimal_education_fourth_color', array(
      'default' => '#ed5927',
      'sanitize_callback' => 'sanitize_hex_color',
      'transport' => 'refresh',
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'minimal_education_fourth_color', array(
      'section' => 'colors',
      'label' => esc_html__('fourth Color', 'minimal-education'),
   
  )));
}
add_action( 'customize_register', 'minimal_education_customize' );


/* Pro control */
if (class_exists('WP_Customize_Control') && !class_exists('Minimal_Education_Pro_Control')):
    class Minimal_Education_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', 'education-insight'); ?>
          </h3>
      
          <p style="margin: 15px 0;">
            <?php esc_html_e('Upgrade to Pro to get:', 'education-insight'); ?>
          </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', 'education-insight'); ?></li>
            <li>✓ <?php esc_html_e('Advanced Footer Builder', 'education-insight'); ?></li>
            <li>✓ <?php esc_html_e('Typography Controls', 'education-insight'); ?></li>
            <li>✓ <?php esc_html_e('WooCommerce Styling Options', 'education-insight'); ?></li>
            <li>✓ <?php esc_html_e('Priority Support', 'education-insight'); ?></li>
            <li>✓ <?php esc_html_e('One-Click Demo Import', 'education-insight'); ?></li>
          </ul>
      
          <a href="<?php echo esc_url(admin_url('themes.php?page=education-insight-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', 'education-insight'); ?>
          </a>
      
          <a href="<?php echo esc_url( EDUCATION_INSIGHT_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 🚀', 'education-insight'); ?>
          </a>

          <a href="<?php echo esc_url( EDUCATION_INSIGHT_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 🎁', 'education-insight'); ?>
          </a>
      
        </div>
    <?php } }
endif;