<?php
/**
 * Web Startup Agency functions and definitions
 *
 * @package Web Startup Agency
 */

if ( ! function_exists( 'web_startup_agency_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which runs
 * before the init hook. The init hook is too late for some features, such as indicating
 * support post thumbnails.
 */
function web_startup_agency_setup() {
	global $web_startup_agency_content_width;
	if ( ! isset( $web_startup_agency_content_width ) )
		$web_startup_agency_content_width = 680;

	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'wp-block-styles');
	add_theme_support( 'align-wide' );
	add_theme_support( 'woocommerce' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'custom-logo', array(
		'height'      => 100,
		'width'       => 100,
		'flex-height' => true,
	) );
	add_theme_support( 'custom-background', array(
		'default-color' => 'ffffff'
	) );
	add_theme_support( 'html5', array(
		'search-form',
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );

	add_editor_style( 'editor-style.css' );
}
endif; // smallbiz_startup_setup
add_action( 'after_setup_theme', 'web_startup_agency_setup' );

function web_startup_agency_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'web-startup-agency' ),
		'description'   => __( 'Appears on blog page sidebar', 'web-startup-agency' ),
		'id'            => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	$smallbiz_startup_widget_areas = get_theme_mod('smallbiz_startup_footer_widget_areas', '4');
	for ($smallbiz_startup_i=1; $smallbiz_startup_i<=$smallbiz_startup_widget_areas; $smallbiz_startup_i++) {
		register_sidebar( array(
			'name'          => __( 'Footer Widget ', 'web-startup-agency' ) . $smallbiz_startup_i,
			'id'            => 'footer-' . $smallbiz_startup_i,
			'description'   => '',
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );
	}
}
add_action( 'widgets_init', 'web_startup_agency_widgets_init' );

add_action( 'wp_enqueue_scripts', 'web_startup_agency_enqueue_styles' );

function web_startup_agency_enqueue_styles() {
    $parenthandle = 'web-startup-agency-style'; 
    $theme = wp_get_theme();
    wp_enqueue_style( $parenthandle, esc_url(get_template_directory_uri()) . '/style.css',
        array(),  // if the parent theme code has a dependency, copy it to here
        $theme->parent()->get('Version')
    );
    wp_enqueue_style( 'web-startup-agency-child-style', get_stylesheet_uri(),
        array( $parenthandle ),
        $theme->get('Version') // this only works if you have Version in the style header
    );
	require get_theme_file_path( 'inc/color-scheme/custom-color-control.php' );
	wp_add_inline_style( 'web-startup-agency-style',$web_startup_agency_color_scheme_css );

}

// customizer css
function web_startup_agency_enqueue_customizer_css() {
    wp_enqueue_style( 'web_startup_agency-customizer-css', get_stylesheet_directory_uri() . '/css/customize-controls.css' );
}
add_action( 'customize_controls_print_styles', 'web_startup_agency_enqueue_customizer_css' );

// script 
function web_startup_agency_scripts() {

    wp_enqueue_script( 'owl.carousel-js', esc_url(get_theme_file_uri()). '/js/owl.carousel.js', array('jquery') );
    wp_enqueue_script( 'theme-js', esc_url(get_theme_file_uri()). '/js/theme.js', array('jquery') );
	wp_enqueue_style( 'owl.carousel-css', esc_url(get_theme_file_uri())."/css/owl.carousel.css" );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	// font-family
	$smallbiz_startup_headings_font = esc_html(get_theme_mod('smallbiz_startup_headings_fonts'));
	$smallbiz_startup_body_font = esc_html(get_theme_mod('smallbiz_startup_body_fonts'));

	if ($smallbiz_startup_headings_font) {
	    wp_enqueue_style('smallbiz-startup-headings-fonts', 'https://fonts.googleapis.com/css?family=' . urlencode($smallbiz_startup_headings_font));
	} else {
	    wp_enqueue_style('poppins-headings', 'https://fonts.googleapis.com/css?family=Poppins:0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900');
	}

	if ($smallbiz_startup_body_font) {
	    wp_enqueue_style('smallbiz-startup-body-fonts', 'https://fonts.googleapis.com/css?family=' . urlencode($smallbiz_startup_body_font));
	} else {
	    wp_enqueue_style('poppins-body', 'https://fonts.googleapis.com/css?family=Poppins:0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900');
	}
}
	add_action( 'wp_enqueue_scripts', 'web_startup_agency_scripts' );

	add_action( 'customize_register', 'web_startup_agency_customize_register', 11 );

	function web_startup_agency_customize_register() {
		global $wp_customize;

		$wp_customize->remove_section( 'smallbiz_startup_one_cols_section' );

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

		$wp_customize->remove_setting( 'smallbiz_startup_color_scheme_gradiant1' );
		$wp_customize->remove_control( 'smallbiz_startup_color_scheme_gradiant1' );	
		$wp_customize->remove_setting( 'smallbiz_startup_color_scheme_gradiant2' );
		$wp_customize->remove_control( 'smallbiz_startup_color_scheme_gradiant2' );		

	}

// Customizer Section
function web_startup_agency_customizer ( $wp_customize ) {

	// Global Color	
	$wp_customize->add_setting('web_startup_agency_color_scheme_gradiant1', array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_hex_color',
	));
	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'web_startup_agency_color_scheme_gradiant1', array(
		'label'    => __('Theme Color', 'web-startup-agency'),
		'section'  => 'smallbiz_startup_global_color',
		'settings' => 'web_startup_agency_color_scheme_gradiant1',	
	)));

	$wp_customize->add_setting('web_startup_agency_color_scheme_gradiant2', array(
	'default'           => '',
	'sanitize_callback' => 'sanitize_hex_color',
	));
	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'web_startup_agency_color_scheme_gradiant2', array(
		'label'    => __('Theme Color', 'web-startup-agency'),
		'section'  => 'smallbiz_startup_global_color',
		'settings' => 'web_startup_agency_color_scheme_gradiant2',	
	)));

	// Home Category Dropdown Section
	$wp_customize->add_section('web_startup_agency_one_cols_section',array(
		'title'	=> __('Manage Slider Section','web-startup-agency'),
		'description'	=> __('Select Category from the Dropdowns for slider, Also use the given image dimension (1600 x 600).','web-startup-agency'),
		'priority'	=> null,
		'panel' => 'smallbiz_startup_panel_area'
	));

	//Hide Section
	$wp_customize->add_setting('web_startup_agency_hide_categorysec',array(
		'default' => false,
		'sanitize_callback' => 'smallbiz_startup_sanitize_checkbox',
		'capability' => 'edit_theme_options',
	));
	$wp_customize->add_control( 'web_startup_agency_hide_categorysec', array(
	   'settings' => 'web_startup_agency_hide_categorysec',
	   'section'   => 'web_startup_agency_one_cols_section',
	   'label'     => __('Check To Enable This Section','web-startup-agency'),
	   'type'      => 'checkbox'
	));

	// Add a category dropdown Slider Coloumn
	$wp_customize->add_setting( 'web_startup_agency_pageboxes', array(
		'default'	=> '0',	
		'sanitize_callback'	=> 'absint'
	) );
	$wp_customize->add_control( new web_startup_agency_Category_Dropdown_Custom_Control( $wp_customize, 'web_startup_agency_pageboxes', array(
		'section' => 'web_startup_agency_one_cols_section',
	   'label' => __('Select Category to display Slider', 'web-startup-agency'),
		'settings'   => 'web_startup_agency_pageboxes',
	) ) );

	$wp_customize->add_setting('web_startup_agency_button_text',array(
		'default' => '',
		'sanitize_callback' => 'sanitize_text_field',
		'capability' => 'edit_theme_options',
	));
	$wp_customize->add_control( 'web_startup_agency_button_text', array(
	   'settings' => 'web_startup_agency_button_text',
	   'section'   => 'web_startup_agency_one_cols_section',
	   'label' => __('Add Button Text', 'web-startup-agency'),
	   'type'      => 'text'
	));

	$wp_customize->add_setting('web_startup_agency_button_link_slider',array(
        'default'=> '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('web_startup_agency_button_link_slider',array(
        'label' => esc_html__('Add Button Link','web-startup-agency'),
        'section'=> 'web_startup_agency_one_cols_section',
        'type'=> 'url'
    ));

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

	$wp_customize->add_control('web_startup_agency_slider_settings_upgraded_features', array(
	    'type'=> 'hidden',
	    'description' => "<span class='customizer-upgraded-features'>Unlock Premium Customization Features:
	        <a target='_blank' href='". esc_url('https://www.theclassictemplates.com/products/startup-company-wordpress-theme') ." '>Upgrade to Pro</a></span>",
	    'section' => 'web_startup_agency_one_cols_section'
	));

}

add_action( 'customize_register', 'web_startup_agency_customizer' );

function web_startup_agency_setup_theme() {
	if ( ! defined( 'SMALLBIZ_STARTUP_PRO_NAME' ) ) {
		define( 'SMALLBIZ_STARTUP_PRO_NAME', __( 'About Web Startup Agency', 'web-startup-agency' ));
	}
	if ( ! defined( 'SMALLBIZ_STARTUP_THEME_PAGE' ) ) {
	define('SMALLBIZ_STARTUP_THEME_PAGE',__('https://www.theclassictemplates.com/collections/best-wordpress-templates','web-startup-agency'));
	}
	if ( ! defined( 'SMALLBIZ_STARTUP_SUPPORT' ) ) {
	define('SMALLBIZ_STARTUP_SUPPORT',__('https://wordpress.org/support/theme/web-startup-agency/','web-startup-agency'));
	}
	if ( ! defined( 'SMALLBIZ_STARTUP_REVIEW' ) ) {
	define('SMALLBIZ_STARTUP_REVIEW',__('https://wordpress.org/support/theme/web-startup-agency/reviews/','web-startup-agency'));
	}
	if ( ! defined( 'SMALLBIZ_STARTUP_PRO_DEMO' ) ) {
	define('SMALLBIZ_STARTUP_PRO_DEMO',__('https://live.theclassictemplates.com/demo/smallbiz-startup/','web-startup-agency'));
	}
	if ( ! defined( 'SMALLBIZ_STARTUP_PREMIUM_PAGE' ) ) {
	define('SMALLBIZ_STARTUP_PREMIUM_PAGE',__('https://www.theclassictemplates.com/products/startup-company-wordpress-theme','web-startup-agency'));
	}
	if ( ! defined( 'SMALLBIZ_STARTUP_THEME_DOCUMENTATION' ) ) {
	define('SMALLBIZ_STARTUP_THEME_DOCUMENTATION',__('https://live.theclassictemplates.com/demo/docs/web-startup-agency-free/','web-startup-agency'));
	}
}
add_action( 'after_setup_theme', 'web_startup_agency_setup_theme' );

get_template_part('/inc/select/category-dropdown-custom-control');

if ( ! function_exists( 'smallbiz_startup_the_custom_logo' ) ) :
	/**
	 * Displays the optional custom logo.
	 *
	 * Does nothing if the custom logo is not available.
	 *
	 * @since web-startup-agency
	 */
	function smallbiz_startup_the_custom_logo() {
		if ( function_exists( 'the_custom_logo' ) ) {
			// Check if custom logo is set via the customizer
			if ( has_custom_logo() ) {
				the_custom_logo();
			} else {
				// If no custom logo, display the logo from the child theme directory
				echo "<a href='" . esc_url( home_url() ) . "' rel='home'>
						<img src='" . esc_url( get_stylesheet_directory_uri() ) . "/images/Logo.png' alt='" . esc_attr__( 'Web Startup Agency logo', 'web-startup-agency' ) . "' />
					  </a>";
			}
		}
	}
endif;

// Redirect to a custom page after theme activation in the child theme
function web_startup_agency_options() {
    global $pagenow;

    if ( is_admin() && 'themes.php' === $pagenow && isset( $_GET['activated'] ) && current_user_can( 'manage_options' ) ) {
        // Theme activated — future actions can go here, like setting theme mods or showing notices.
    }
}
add_action( 'admin_init', 'web_startup_agency_options' );

add_filter( 'smallbiz_startup_demo_content_path', function( $web_startup_agency_default_path ) {
    $web_startup_agency_child_path = get_stylesheet_directory() . '/inc/demo-content.php';

    if ( file_exists( $web_startup_agency_child_path ) ) {
        return $web_startup_agency_child_path;
    }

    return $web_startup_agency_default_path; 
});

// Load additional admin styles for the child theme
function web_startup_agency_admin_enqueue_scripts() {
    wp_enqueue_style( 'web-startup-agency-admin-style', get_stylesheet_directory_uri() . '/css/addon.css' );
}
add_action( 'admin_enqueue_scripts', 'web_startup_agency_admin_enqueue_scripts' );
?>