<?php
//
// Recommended way to include parent theme styles.
//  (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
//  
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array('parent-style')
    );
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    
    wp_enqueue_style( 'slick-css', get_stylesheet_directory_uri() . '/slick.css' );
    wp_enqueue_script( 'slick', get_stylesheet_directory_uri() . '/slick.min.js', array( 'jquery' ), '1.8.1', true );
    wp_enqueue_script( 'custom', get_stylesheet_directory_uri() . '/scripts.js', array( 'jquery' ), '1.0.0', true );
}
//
// Your code goes below
//

function sre_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'CTA', 'jakdigital' ),
		'id'            => 'cta',
		'description'   => esc_html__( 'Add widgets here.', 'jakdigital' ),
		'before_widget' => '<section class="cta-widget">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="cta-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footer Widgets', 'jakdigital' ),
		'id'            => 'widgets',
		'description'   => esc_html__( 'Add widgets here.', 'jakdigital' ),
		'before_widget' => '<section class="footer-widget col-xs-4">',
		'after_widget'  => '</section>',
		'before_title'  => '<h1 class="title">',
		'after_title'   => '</h1>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Front Hero', 'jakdigital' ),
		'id'            => 'fronthero',
		'description'   => esc_html__( 'Add widgets here.', 'jakdigital' ),
		'before_widget' => '<section class="hero-widget">',
		'after_widget'  => '</section>',
		'before_title'  => '<h1 class="title">',
		'after_title'   => '</h1>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Front Contact', 'jakdigital' ),
		'id'            => 'frontcontact',
		'description'   => esc_html__( 'Add widgets here.', 'jakdigital' ),
		'before_widget' => '<section class="contact-widget">',
		'after_widget'  => '</section>',
		'before_title'  => '<div class="contact-title">',
		'after_title'   => '</div>',
	) );
}
add_action( 'widgets_init', 'sre_widgets_init' );

if( function_exists('acf_add_options_page') ) {
	acf_add_options_page(array(
		'page_title' 	=> 'Contact Details',
		'menu_title'	=> 'Contact Details',
		'menu_slug' 	=> 'contact-details',
		'capability'	=> 'edit_posts',
		'redirect'		=> false
	));
}

/*
 * Add shortcode to render Contact Details on the front end
 */
function contact_details_func( $atts ) {
	ob_start();
	$atts = shortcode_atts(
		array(),
		$atts,
		'contact_details'
	);
	include( ABSPATH . "wp-content/themes/southern-ridge-electrical/shortcodes/contact-details.php" );

	$output = ob_get_contents();
	ob_end_clean();
	return $output;
}
add_shortcode( 'contact_details', 'contact_details_func' );

/*
 * Add shortcode to render Team on the front end
 */
function our_team_func( $atts ) {
	ob_start();
	$atts = shortcode_atts(
		array(),
		$atts,
		'our_team'
	);
	include( ABSPATH . "wp-content/themes/southern-ridge-electrical/shortcodes/team.php" );

	$output = ob_get_contents();
	ob_end_clean();
	return $output;
}
add_shortcode( 'our_team', 'our_team_func' );

/*
 * Add shortcode to render Testimonials on the front end
 */
function testimonials_func( $atts ) {
	ob_start();
	$atts = shortcode_atts(
		array(),
		$atts,
		'testimonials'
	);
	include( ABSPATH . "wp-content/themes/southern-ridge-electrical/shortcodes/testimonials.php" );

	$output = ob_get_contents();
	ob_end_clean();
	return $output;
}
add_shortcode( 'testimonials', 'testimonials_func' );

add_filter( 'gform_next_button', 'input_to_button', 10, 2 );
add_filter( 'gform_previous_button', 'input_to_button', 10, 2 );
add_filter( 'gform_submit_button', 'input_to_button', 10, 2 );
function input_to_button( $button, $form ) {
    $dom = new DOMDocument();
    $dom->loadHTML( $button );
    $input = $dom->getElementsByTagName( 'input' )->item(0);
    $new_button = $dom->createElement( 'button' );
    $new_button->appendChild( $dom->createTextNode( $input->getAttribute( 'value' ) ) );
    $input->removeAttribute( 'value' );
    foreach( $input->attributes as $attribute ) {
        $new_button->setAttribute( $attribute->name, $attribute->value );
    }
    $input->parentNode->replaceChild( $new_button, $input );
 
    return $dom->saveHtml( $new_button );
}