<?php

// Enqueue styles and scripts
add_action('wp_enqueue_scripts', 'nonprofit_give_my_theme_enqueue_styles');
function nonprofit_give_my_theme_enqueue_styles() {
    $nonprofit_give_parent_style = 'expert-ngo-volunteer-main'; // Style handle of parent theme
    wp_enqueue_style($nonprofit_give_parent_style, get_template_directory_uri() . '/assets/css/main.css');
    wp_enqueue_style('nonprofit_give-style', get_stylesheet_uri(), array($nonprofit_give_parent_style));
}

add_action('wp_enqueue_scripts', 'nonprofit_give_script');
function nonprofit_give_script() {
    $nonprofit_give_parent_script_handle = 'expert-ngo-volunteer-theme-js'; // Script handle of parent theme
    wp_enqueue_script($nonprofit_give_parent_script_handle, get_theme_file_uri('/assets/js/theme.js'), array(), null, true);
}

// Theme setup
if (!function_exists('nonprofit_give_setup')) :
    function nonprofit_give_setup() {
        add_theme_support('automatic-feed-links');
        add_theme_support('title-tag');
        add_theme_support('custom-header');
        add_theme_support('responsive-embeds');
        add_theme_support('post-thumbnails');
        add_theme_support('align-wide');
        add_editor_style(array('assets/css/editor-style.css'));
        add_theme_support('custom-background', apply_filters('nonprofit_give_custom_background_args', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        )));

        if ( ! defined( 'EXPERT_NGO_VOLUNTEER_DEMO_IMPORT_URL' ) ) {
            define( 'EXPERT_NGO_VOLUNTEER_DEMO_IMPORT_URL', esc_url( admin_url( 'themes.php?page=nonprofitgive-wizard' ) ) );
        }
        if ( ! defined( 'EXPERT_NGO_VOLUNTEER_WELCOME_MESSAGE' ) ) {
            define( 'EXPERT_NGO_VOLUNTEER_WELCOME_MESSAGE', __( 'Welcome! Thank you for choosing Cafe Coffee Charm', 'nonprofit-give' ) );
        }
        if ( ! defined( 'COFFEE_TEA_DEMO_IMPORT_URL' ) ) {
            define( 'COFFEE_TEA_DEMO_IMPORT_URL', esc_url( admin_url( 'themes.php?page=nonprofitgive-wizard' ) ) );
        }

    }
endif;
add_action('after_setup_theme', 'nonprofit_give_setup');

// Set content width
function nonprofit_give_content_width() {
    $GLOBALS['content_width'] = apply_filters('nonprofit_give_content_width', 1170);
}
add_action('after_setup_theme', 'nonprofit_give_content_width', 0);

// Register widget areas
function nonprofit_give_widgets_init() {
    register_sidebar(array(
        'name' => __('Sidebar Widget Area', 'nonprofit-give'),
        'id' => 'expert-ngo-volunteer-sidebar-primary',
        'description' => __('The Primary Widget Area', 'nonprofit-give'),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h4 class="widget-title">',
        'after_title' => '</h4><div class="title"><span class="shap"></span></div>',
    ));
    register_sidebar( array(
        'name' => __( 'Footer Widget Area', 'nonprofit-give' ),
        'id' => 'expert-ngo-volunteer-footer-widget-area',
        'description' => __( 'The Footer Widget Area', 'nonprofit-give' ),
        'before_widget' => '<div class="footer-widget col-lg-3 col-sm-6 wow fadeIn" data-wow-delay="0.2s"><aside id="%1$s" class="widget %2$s">',
        'after_widget' => '</aside></div>',
        'before_title' => '<h5 class="widget-title w-title">',
        'after_title' => '</h5><span class="shap"></span>',
    ) );
}
add_action('widgets_init', 'nonprofit_give_widgets_init');

// Remove customizer settings
function nonprofit_give_remove_custom($wp_customize) {

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

    $wp_customize->remove_section('sticky_header_section_setting');
    
    $wp_customize->remove_section('expert_ngo_volunteer_slider_section');
    
    $wp_customize->remove_section('expert_ngo_volunteer_topbar');

}
add_action('customize_register', 'nonprofit_give_remove_custom', 1000);

function nonprofit_give_sanitize_dropdown_pages( $nonprofit_give_page_id, $nonprofit_give_setting ) {
  // Ensure $nonprofit_give_input is an absolute integer.
  $nonprofit_give_page_id = absint( $nonprofit_give_page_id );
  // If $nonprofit_give_page_id is an ID of a published page, return it; otherwise, return the default.
  return ( 'publish' == get_post_status( $nonprofit_give_page_id ) ? $nonprofit_give_page_id : $nonprofit_give_setting->default );
}

function nonprofit_give_child_customize_register( $wp_customize ) {

    /*=========================================
    Slider Section
    =========================================*/
    $wp_customize->add_section(
        'nonprofit_give_slider_section', array(
            'title' => esc_html__( 'Slider Section', 'nonprofit-give' ),
            'priority' => 3,
            'panel' => 'expert_ngo_volunteer_frontpage_sections',
        )
    );

    // Slider Hide/ Show Setting // 
    $wp_customize->add_setting( 
        'nonprofit_give_slider_setting' , 
            array(
            'default' => true,
            'sanitize_callback' => 'expert_ngo_volunteer_sanitize_checkbox',
            'capability' => 'edit_theme_options',
            'priority' => 2,
        ) 
    );
    
    $wp_customize->add_control(
    'nonprofit_give_slider_setting', 
        array(
            'label'       => esc_html__( 'Hide / Show Section', 'nonprofit-give' ),
            'section'     => 'nonprofit_give_slider_section',
            'settings'    => 'nonprofit_give_slider_setting',
            'type'        => 'checkbox'
        ) 
    );
    
    // Add color scheme setting and control.
    $wp_customize->add_setting( 'nonprofit_give_slider_page', array(
        'default'           => get_page_id_by_slug('banner-pages'),
        'sanitize_callback' => 'expert_ngo_volunteer_sanitize_dropdown_pages'
    ) );

    $wp_customize->add_control( 'nonprofit_give_slider_page', array(
        'label'    => __( 'Select Slide Image Page', 'nonprofit-give' ),
        'section'  => 'nonprofit_give_slider_section',
        'type'     => 'dropdown-pages'
    ) );

    // Slider Text
    $wp_customize->add_setting( 
        'nonprofit_give_slider_short_heading',
        array(
            'capability'        => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field',
            'priority'      => 1,
        )
    );  

    $wp_customize->add_control( 
        'nonprofit_give_slider_short_heading',
        array(
            'label'         => __('Slider Top Text','nonprofit-give'),
            'section'       => 'nonprofit_give_slider_section',
            'type'          => 'text',
        )
    );

    $wp_customize->add_setting(
        'nonprofit_give_slider_btn_text',
        array(
            'default' => 'Join Us',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );
    $wp_customize->add_control(
        'nonprofit_give_slider_btn_text',
        array(
            'label'         => __('Slider Button Text 2','nonprofit-give'),
            'section'       => 'nonprofit_give_slider_section',
            'type'          => 'text',
        )  
    );

    $wp_customize->add_setting(
        'nonprofit_give_slider_btn_link',
        array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );
    $wp_customize->add_control( 
        'nonprofit_give_slider_btn_link',
        array(
            'label'         => __('Slider Button Link 2','nonprofit-give'),
            'section'       => 'nonprofit_give_slider_section',
            'type'          => 'url',
        )
    );

    $wp_customize->add_setting('nonprofit_give_slider_below_call_text',array(
        'default'=> '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('nonprofit_give_slider_below_call_text',array(
        'label' => __('Add Appointment Text','nonprofit-give'),
        'section'=> 'nonprofit_give_slider_section',
        'type'=> 'text'
    ));


    $wp_customize->add_setting( 'nonprofit_give_total_goal', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
    ) );

    $wp_customize->add_control( 'nonprofit_give_total_goal', array(
        'label'   => __( 'Total Goal', 'nonprofit-give' ),
        'section' => 'nonprofit_give_slider_section',
        'type'    => 'text',
    ) );

    $wp_customize->add_setting( 'nonprofit_give_total_raised', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
    ) );

    $wp_customize->add_control( 'nonprofit_give_total_raised', array(
        'label'   => __( 'Total Donations Raised', 'nonprofit-give' ),
        'section' => 'nonprofit_give_slider_section',
        'type'    => 'text',
    ) );

    $wp_customize->add_setting( 'nonprofit_give_total_supporters', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
    ) );

    $wp_customize->add_control( 'nonprofit_give_total_supporters', array(
        'label'   => __( 'Total Supporters', 'nonprofit-give' ),
        'section' => 'nonprofit_give_slider_section',
        'type'    => 'text',
    ) );

    $wp_customize->add_setting('nonprofit_give_dynamic_sec_color', array(
        'default'           => '#FD8565',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'nonprofit_give_dynamic_sec_color', array(
        'label'    => __('Second Dynamic Color', 'nonprofit-give'),
        'section'  => 'expert_ngo_volunteer_dynamic_color_settings',
    )));


}

add_action( 'customize_register', 'nonprofit_give_child_customize_register', 20 );

function nonprofit_give_customize_css() {
    $expert_ngo_volunteer_dynamic_color = get_theme_mod( 'expert_ngo_volunteer_dynamic_color_one', '#FB6563' );
    $nonprofit_give_dynamic_sec_color   = get_theme_mod( 'nonprofit_give_dynamic_sec_color', '#FD8565' );
    $nonprofit_give_slider_setting      = get_theme_mod( 'nonprofit_give_slider_setting', false );

    $nonprofit_give_custom_css  = ':root {';
    $nonprofit_give_custom_css .= '--color-primary1: ' . esc_attr( $expert_ngo_volunteer_dynamic_color ) . ';';
    $nonprofit_give_custom_css .= '--color-primary2: ' . esc_attr( $nonprofit_give_dynamic_sec_color ) . ';';
    $nonprofit_give_custom_css .= '}';

    if ( false == $nonprofit_give_slider_setting ) {
        $nonprofit_give_custom_css .= '
        .page-template-template-frontpage .middle-header-area{
            position: static !important;
            background: var(--color-primary1);
        }
        .page-template-template-frontpage h1.site-title a, .page-template-template-frontpage p.site-title a, .page-template-template-frontpage p.site-description{
           Color: #fff;
        }
        .page-template-template-frontpage .navbar-menubar .main-navigation .menu > li > a:hover, 
        .page-template-template-frontpage .navbar-menubar .page_item a:hover{
           Color: #fff;
        }
        .page-template-template-frontpage .main-navigation li.current_page_item > a, .page-template-template-frontpage .main-navigation li.current-menu-item > a{
            Color:#ffffff
        }';

    }

    echo '<style type="text/css">' . $nonprofit_give_custom_css . '</style>';
}
add_action( 'wp_head', 'nonprofit_give_customize_css' );