<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

function farm_store_theme_setup(){

    // Make theme available for translation.
    load_theme_textdomain( 'farm-store', get_stylesheet_directory_uri() . '/languages' );
    
    add_theme_support( 'custom-header', apply_filters( 'farm_store_custom_header_args', array(
        'default-image' => get_stylesheet_directory_uri() . '/image/custom-header.jpg',
        'default-text-color'     => '000000',
        'width'                  => 1000,
        'height'                 => 350,
        'flex-height'            => true,
        'wp-head-callback'       => 'grocery_store_header_style',
    ) ) );
    
    register_default_headers( array(
        'default-image' => array(
        'url' => '%s/image/custom-header.jpg',
        'thumbnail_url' => '%s/image/custom-header.jpg',
        'description' => esc_html__( 'Default header image', 'farm-store' ),
        ),
    ));

}
add_action( 'after_setup_theme', 'farm_store_theme_setup' );


if ( !function_exists( 'farm_store_enqueue_child_styles' ) ):
    function farm_store_enqueue_child_styles() {
        wp_enqueue_style( 'farm_store_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'bootstrap','rd-navbar','icofont','owl-carousel','aos-next','grocery-store-common' ) );

        $custom_css = ':root{--secondary-color: '.esc_attr( get_theme_mod('__secondary_color','#D8C149') ).'!important; --nav-bg:'.esc_attr( get_theme_mod('__secondary_color','#D8C149') ).'!important; --secondary-color-deep:'.esc_attr( get_theme_mod('__quaternary_color','#BF9D37') ).'!important;  --nav-deep:'.esc_attr( get_theme_mod('__quaternary_color','#BF9D37') ).'!important;}';

        wp_add_inline_style( 'farm_store_parent', $custom_css );
    }
endif;
add_action( 'wp_enqueue_scripts', 'farm_store_enqueue_child_styles', 999 );

if ( !function_exists( 'farm_store_default_options' ) ):

function farm_store_default_options( $defaults ) {

        
        /*Posts Layout*/
     
        $defaults['single_post_layout']             = 'no-sidebar';
        $defaults['blog_loop_content_type']         = 'excerpt';
        
        /*Posts Layout*/
        $defaults['page_layout']                    = 'full-container';
        
    
    
    return $defaults;
}
add_filter( 'grocery_store_default_theme_options_filter', 'farm_store_default_options',999 );

endif;


add_action('init','farm_store_disable_from_parent',50);
function farm_store_disable_from_parent(){
    
    global $grocery_store_header;
    remove_action( 'grocery_store_site_header', array( $grocery_store_header, 'site_header_layout_1' ), 20 );

    global $grocery_store_post_related;
    remove_action( 'grocery_store_site_content_type', array( $grocery_store_post_related, 'site_loop_heading' ), 10 );
    
    
}

/**
 * Web Site heading
 *
 * @since 1.0.0
 */
function farm_store_loop_heading() {
    
    if( !is_singular() ) { 

        the_title( '<h3 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h3>' );
    }
    
    
}
add_action( 'grocery_store_site_content_type', 'farm_store_loop_heading', 20 );

/**
* Get the Site logo
*
* @return HTML
*/
if ( !function_exists( 'farm_store_header_layout' ) ):
add_action('grocery_store_site_header','farm_store_header_layout', 20 );
function farm_store_header_layout(){
    
?>
<header id="masthead" class="site-header">
        <div class="container">
        <div class="row align-items-center ">
            <div class="site-branding col-lg-5 col-sm-12">
                  <?php 

                    if ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) {
                        echo get_custom_logo();
                    }
                    if (display_header_text()==true){
                        echo '<h4><a href="'.esc_url( home_url( '/' ) ).'" rel="home" class="site-title">';
                        echo get_bloginfo( 'name' );
                        echo '</a></h4>';
                        $description = get_bloginfo( 'description', 'display' );
                        if ( $description ) :
                            echo  '<div class="site-description">'.esc_html($description).'</div>';
                        endif;
                    }
                ?>
                <button class="grocery-store-rd-navbar-toggle" ><i class="icofont-navigation-menu"></i></button>
            </div><!-- .site-branding -->
            <div class="col-lg-7 col-sm-12 text-right"> 
                <?php 
                if ( is_active_sidebar( 'logo-sidebar' ) ) : 
                    dynamic_sidebar( 'logo-sidebar' ); 
                else:
                    if ( class_exists( 'WooCommerce' ) ) {
                        echo '<div class="aspw-widgets-wrap-class">';   
                        do_action('apsw_search_bar_preview', 1 );
                        echo '</div>';
                    }
                endif;
                ?>
           </div>
        </div>
        </div>
        <?php if( function_exists('farm_store_site_main_menu') ): farm_store_site_main_menu(); endif;?>
    </header>
<?php
   
}
endif;

if ( !function_exists( 'farm_store_site_main_menu' ) ):
    /**
    * Get the Site logo
    *
    * @return HTML
    */
function farm_store_site_main_menu(){
    ?>
        <div class="nav_wrap">
            <nav class="rd-navbar navbar-header-style-1" data-rd-navbar-lg="rd-navbar-static">
   
                <div class="rd-navbar-outer">
                    <div class="rd-navbar-inner">
                    
                        <div class="rd-navbar-subpanel">
                        
                         <div class="rd-navbar-nav-wrap">
                          <button class="rd-navbar-toggle toggle-original" data-rd-navbar-toggle=".rd-navbar-nav-wrap"><i class="icofont-ui-close"></i></button>
                            <?php
                                wp_nav_menu( array(
                                    'theme_location'    => 'primary',
                                    'depth'             => 3,
                                    'menu_class'        => 'farm-store-main-menu rd-navbar-nav',
                                    'container'         => 'ul',
                                    'walker'            => new grocery_store_navwalker(),
                                    'fallback_cb'       => 'grocery_store_navwalker::fallback',
                                ) );
                            ?>
                            </div>
                            
                           
                                <?php if ( function_exists( 'grocery_store_woocommerce_header_cart' ) ) {
                                    grocery_store_woocommerce_header_cart();
                                }?>
                          
                           
                        </div>
                    </div>
                </div>
            </nav>
           </div> 
        <?php
}
endif;