<?php
/**
 * Add style sheets here
 */
function amplifyworldwide_load_css()
{
    wp_register_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), false, 'all');
    wp_enqueue_style('bootstrap');
    
    wp_register_style('style', get_template_directory_uri() . '/style.css', array(), rand(111,9999), 'all');
    wp_enqueue_style('style');

    wp_enqueue_style('google-material-icons', 'https://fonts.googleapis.com/icon?family=Material+Icons');
}

add_action('wp_enqueue_scripts', 'amplifyworldwide_load_css');

/**
 * Add JavaScript files here
 */
function amplifyworldwide_load_js()
{   
    wp_enqueue_script('jquery');

    wp_register_script('bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', 'jquery', false, 'true');
    wp_enqueue_script('bootstrap');
    
    wp_register_script('customJs', get_template_directory_uri() . '/js/scripts.js', '', 1, 'true');
    wp_enqueue_script('customJs');
}

add_action('wp_enqueue_scripts', 'amplifyworldwide_load_js');

/**
 * Min Charcters for Forms
 */
function amplifyworldwide_wpf_dev_char_min() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            jQuery('.wpf-char-min input').prop('minLength', 3);
			jQuery('.wpf-char-min5 input').prop('minLength', 5);
            jQuery('.wpf-char-min textarea').prop('minLength', 20);
        });
    </script>
    <?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_dev_char_min' );


/**
 * Enqueue Google fonts
 */
function amplifyworldwide_font_g_style() {
    wp_enqueue_style( 'google-fonts', 'https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap', false );
}
add_action( 'wp_enqueue_scripts', 'amplifyworldwide_font_g_style' );

/**
 * Register custom navigation walker
 */
function amplifyworldwide_register_navwalker(){
	require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
}
add_action( 'after_setup_theme', 'amplifyworldwide_register_navwalker' );

//Theme support
add_theme_support('post-thumbnails'); 
add_theme_support('html5', array('search-form'));

add_image_size('amplifyworldwide_smallest', 500, 300, true);
add_image_size('amplifyworldwide_largest', 800, 800, true);

//Register menus
register_nav_menus(  
    array(
        'top-menu' => __('Top Menu', 'amplifyworldwide'),
        'footer-menu' => __('Footer Menu', 'amplifyworldwide'),
    )

);

//====================================================================
// Add WordPress theme requirements
//====================================================================

add_action('after_setup_theme', function () {
    add_theme_support('starter-content', [
    	// Starter content defined here
        // Static front page set to Home, posts page set to Blog
        'options' => [
            'show_on_front' => 'page',
            'page_on_front' => '{{home}}',
            'page_for_posts' => '{{blog}}',
        ],
        // Starter pages to include
        'posts' => [
            'home',
            'about'  ,
            'contact',
            'blog'
        ],
        // Add pages to primary navigation menu
        'nav_menus' => [
            'primary_navigation' => [
                'name' => __('Primary Navigation', 'amplifyworldwide'),
                'items' => [
                    'home_link',
                    'page_about',
                    'page_blog',
                    'page_contact',
                ],
            ]
        ],
        // Add test widgets to footer sidebar
        'widgets' => [
            'sidebar-footer' => [
                'text_business_info',
                'search'
            ]
        ]
    ]);
});

add_action( 'after_setup_theme', 'amplifyworldwide_theme_slug_setup' );

function amplifyworldwide_theme_slug_setup() {

	add_theme_support( 'title-tag' );
}


add_theme_support( 'automatic-feed-links' );

if ( ! isset( $content_width ) ) {
	$content_width = 900;
}

if ( is_singular() ) wp_enqueue_script( "comment-reply" );

function amplifyworldwide_wpdocs_theme_add_editor_styles() {
    add_editor_style( 'custom-editor-style.css' );
}
add_action( 'admin_init', 'amplifyworldwide_wpdocs_theme_add_editor_styles' );

/**
 * Add a sidebar.
 */
function amplifyworldwide_wpdocs_theme_slug_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Main Sidebar', 'amplifyworldwide' ),
        'id'            => 'dynamic_sidebar',
        'description'   => __( 'Widgets in this area will be shown on all posts and pages.', 'amplifyworldwide' ),
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => '</li>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2>',
    ) );
}
add_action( 'widgets_init', 'amplifyworldwide_wpdocs_theme_slug_widgets_init' );


//====================================================================
// Add Social Media Fields to Customizer
//====================================================================
function amplifyworldwide_mytheme_customize_register( $wp_customize ) {

    $wp_customize->add_section( 'mytheme_company_section' , array(
        'title'      => __( 'Social Media Accounts', 'amplifyworldwide' ),
        'priority'   => 30,
    ));

    $wp_customize->add_setting( 'mytheme_company-instagramAccount', array(
        'sanitize_callback' => 'wp_filter_nohtml_kses'
    ));
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'mytheme_company_control1',
            array(
                'label'      => __( 'Instagram Account', 'amplifyworldwide' ),
                'section'    => 'mytheme_company_section',
                'settings'   => 'mytheme_company-instagramAccount',
                'priority'   => 1
            )
        )
    );

    $wp_customize->add_setting( 'mytheme_company-facebookAccount', array(
        'sanitize_callback' => 'wp_filter_nohtml_kses'
    ));
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'mytheme_company_control2',
            array(
                'label'      => __( 'Facebook Account', 'amplifyworldwide' ),
                'section'    => 'mytheme_company_section',
                'settings'   => 'mytheme_company-facebookAccount',
                'priority'   => 2
            )
        )
    );

    $wp_customize->add_setting( 'mytheme_company-twitterAccount', array(
        'sanitize_callback' => 'wp_filter_nohtml_kses'
    ));
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'mytheme_company_control3',
            array(
                'label'      => __( 'Twitter Account', 'amplifyworldwide' ),
                'section'    => 'mytheme_company_section',
                'settings'   => 'mytheme_company-twitterAccount',
                'priority'   => 2
            )
        )
    );

    $wp_customize->add_setting( 'mytheme_company-linkedinAccount', array(
        'sanitize_callback' => 'wp_filter_nohtml_kses'
    ));
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'mytheme_company_control4',
            array(
                'label'      => __( 'LinkedIn Account', 'amplifyworldwide' ),
                'section'    => 'mytheme_company_section',
                'settings'   => 'mytheme_company-linkedinAccount',
                'priority'   => 2
            )
        )
    );

    // ..repeat ->add_setting() and ->add_control() for mytheme_company-division
}
add_action( 'customize_register', 'amplifyworldwide_mytheme_customize_register' );

//====================================================================
// Add New Color Option in Existing Colors Section in Customizer
//====================================================================
 
function amplifyworldwide_diwp_customizer_add_colorPicker( $wp_customize){
     
    // Add Settings 
 
     
    // Add Settings 
    $wp_customize->add_setting( 'pri_color', array(
        'default' => '#04bfbf',
        'sanitize_callback' => 'wp_filter_nohtml_kses'
    ));
 
 
    $wp_customize->add_setting( 'sec_color', array(
        'default' => '#45ace0',
        'sanitize_callback' => 'wp_filter_nohtml_kses'                        
    ));

    $wp_customize->add_setting( 'nav_color', array(
        'default' => '#45ace0',
        'sanitize_callback' => 'wp_filter_nohtml_kses'                        
    ));

 
 
    // Add Controls
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'pri_color', array(
        'label' => 'Primary Color',
        'section' => 'colors',
        'settings' => 'pri_color'
 
    )));
 
 
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'sec_color', array(
        'label' => 'Secondary Color',
        'section' => 'colors',
        'settings' => 'sec_color'
    )));


    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'nav_color', array(
        'label' => 'Nav Bar Color',
        'section' => 'colors',
        'settings' => 'nav_color'
    )));
 
}
 
add_action( 'customize_register', 'amplifyworldwide_diwp_customizer_add_colorPicker' );



//====================================================================
// Hero Image and Logos
//====================================================================

function amplifyworldwide_mytheme_customize_register_heroimagelogo( $wp_customize ) {



    $wp_customize->add_setting( 'mytheme_footerlogo', array(
        'default' => get_theme_file_uri('assets/image/logo.jpg'), // Add Default Image URL 
        'sanitize_callback' => 'esc_url_raw'
    ));
 
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'mytheme_footerlogo', array(
        /*
		'label' => 'Footer Logo',
		*/
		'label' => __( 'Footer Logo', 'amplifyworldwide' ),
        'priority' => 2,
		/*
        'section' => 'mytheme_heroimagelogo_section',
		*/
		'section' => 'title_tagline',
        'settings' => 'mytheme_footerlogo',
        'button_labels' => array(// All These labels are optional
                    'select' => 'Select Image',
                    'remove' => 'Remove Image',
                    'change' => 'Change Image',
                    )
    )));

    $wp_customize->add_setting( 'mytheme_headerlogo', array(
        'default' => get_theme_file_uri('https://beta.amplifyworldwide.com/wp-content/uploads/2021/05/screencapture-intercotradingco-wp-admin-edit-comments-php-2021-05-13-10_29_30.png'), // Add Default Image URL 
        'sanitize_callback' => 'esc_url_raw'
    ));
 
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'mytheme_headerlogo', array(
        'label' => 'Header Logo',
        'priority' => 1,
        /*
        'section' => 'mytheme_heroimagelogo_section',
		*/
		'section' => 'title_tagline',
        'settings' => 'mytheme_headerlogo',
        'button_labels' => array(// All These labels are optional
                    'select' => 'Select Image',
                    'remove' => 'Remove Image',
                    'change' => 'Change Image',
                    )
    )));

}
add_action( 'customize_register', 'amplifyworldwide_mytheme_customize_register_heroimagelogo' );