<?php 
    /**
     * newshit Site Branding Hook 
     */
    if( ! function_exists( 'newshit_site_branding' ) ) :
        /**
         * Site Branding
         *
         * @since 1.0.0 
         */
        function newshit_site_branding(){
            get_template_part( 'inc/header/header-'.''. get_theme_mod( 'select_header', 'one' ) .'' );
        } 
    endif;
    add_action( 'newshit_action_before_header', 'newshit_site_branding', 10 );


    
    /**
     * newshit Footer Contents Hook 
     */
    if ( ! function_exists( 'newshit_footer_contents' ) ) :

        /**
         *  Footer Content
         *
         * @since 1.0.0
         */
        function newshit_footer_contents() {
            get_template_part( 'inc/footer/footer-'.''. get_theme_mod( 'select_footer', 'one' ) .'' );
        }
    endif;
    add_action( 'newshit_action_before_footer', 'newshit_footer_contents', 10 );


    /**
     * newshit breadcrumb Hook 
     */
    if ( ! function_exists( 'newshit_breadcrumb_hook' ) ) :

        /**
         * breadcrumb
         *
         * @since 1.0.0
         */
        function newshit_breadcrumb_hook() {  ?>
            <div class="page-title-wrapper">
                <div class="container">
                    <div class="page-title-inner">
                        <?php newshit_breadcrumb(); ?>
                    </div>
                </div>
            </div>
        <?php  }
    endif;
    add_action( 'newshit_action_breadcrumb', 'newshit_breadcrumb_hook' );
    
    /**
     * newshit Author Section Hook 
     */
    if ( ! function_exists( 'newshit_author_section_hook' ) ) :

        /**
         * breadcrumb
         *
         * @since 1.0.0
         */
        function newshit_author_section_hook() {  ?>
            <div class="author-info-wrapper">
                <div class="author-info-box">
                    <div class="author-image">
                        <?php echo get_avatar( get_the_author_meta( 'ID' )); ?>
                    </div>
                    <div class="author-info">
                        <h2><?php the_author_posts_link(); ?></h2>
                        <p><?php the_author_meta('description'); ?></p>
                        <ul>
                            <?php
                                $newshit_user_cm = wp_get_user_contact_methods();
                                foreach ($newshit_user_cm as $newshit_ucm_key => $newshit_ucm_value) :
                                    $newshit_cm_link = get_user_meta(get_the_author_meta('ID'), $newshit_ucm_key, true);
                                    ?>
                                    <?php if($newshit_cm_link) : ?>
                                        <li>
                                            <a data-toggle="tooltip" data-placement="top" data-original-title="<?php echo esc_attr($newshit_ucm_key) ?>" href="<?php echo esc_url($newshit_cm_link); ?>"><span class="fab fa-<?php echo esc_attr($newshit_ucm_key) ?>"></span>
                                            </a>
                                        </li>
                                    <?php endif; ?>
                                    <?php
                                endforeach;
                            ?>
                        </ul>
                    </div>
                </div>
            </div>
        <?php  }
    endif;
    add_action( 'newshit_action_author_section', 'newshit_author_section_hook' );


    // demo import 

    function newshit_ocdi_import_files() {
        $url = 'https://demo.themeuniver.com/demo-data/newshit/';
        $demo = 'https://newshit.themeuniver.com/';
        return array(
            array(
                'import_file_name'  => esc_html__('Default Demo','newshit' ),
                'categories'        => [ 'Default' ],
                'import_file_url' =>  $url . 'default/demo.xml',
                'import_widget_file_url'  => $url . 'default/widget.wie',
                'import_customizer_file_url'  => $url . 'default/customizer.dat',
                'import_preview_image_url'   => $url . 'default-demo.jpg',
                'preview_url'   => $demo,
            ),
            array(
                'import_file_name'  => esc_html__('Sports Demo','newshit' ),
                'categories'        => [ 'Sports' ],
                'import_file_url' =>  $url . 'sports/demo.xml',
                'import_widget_file_url'  => $url . 'sports/widget.wie',
                'import_customizer_file_url'  => $url . 'sports/customizer.dat',
                'import_preview_image_url'   => $url . 'sports-demo.jpg',
                'preview_url'   => $demo . 'newshit-sports/',
            ),
            array(
                'import_file_name'  => esc_html__('Politics Demo','newshit' ),
                'categories'        => [ 'Politics' ],
                'import_file_url' =>  $url . 'politics/demo.xml',
                'import_widget_file_url'  => $url . 'politics/widget.wie',
                'import_customizer_file_url'  => $url . 'politics/customizer.dat',
                'import_preview_image_url'   => $url . 'politics-demo.jpg',
                'preview_url'   => $demo . 'newshit-politics/',
            ),
        );
    }
    add_filter( 'ocdi/import_files', 'newshit_ocdi_import_files' );

    function ocdi_after_import_setup() {
        // Assign menus to their locations.
        $top_menu = get_term_by( 'name', 'Header Top', 'nav_menu' );
        $main_menu = get_term_by( 'name', 'Main Menu', 'nav_menu' );
        $footer_menu = get_term_by( 'name', 'Footer Menu', 'nav_menu' );
        set_theme_mod( 'nav_menu_locations', array(
                'headertop' => $top_menu->term_id,
                'primary' => $main_menu->term_id, // replace 'main-menu' here with the menu location identifier from register_nav_menu() function
                'footer' => $footer_menu->term_id, // replace 'main-menu' here with the menu location identifier from register_nav_menu() function
            )
        );
    }
    add_action( 'ocdi/after_import', 'ocdi_after_import_setup' );


    /**
    * newshit Navication Hook 
    */
    if ( ! function_exists( 'newshit_navication_hook' ) ) :

        /**
        * Navication
        *
        * @since 1.0.0
        */
        function newshit_navication_hook() {  ?>
            <div class="header-menu-wrapper" id="<?php echo esc_attr( true === get_theme_mod( 'sticky_header_enable', false ) ? 'sticky-header' : 'sticky-header-no' ); ?>">
                <div class="container">
                    <nav class="navbar navbar-expand-lg navbar-light main-navigation" id="site-navigation">
                        <div class="navbar-collapse nav-menu">
                            <?php
                                wp_nav_menu(
                                array(
                                    'container' 		  => false,
                                    'theme_location' 	=> 'primary',
                                    'menu_id'        	=> 'primary-menu',
                                    'menu_class'      => 'sf-menu',
                                    'fallback_cb'     => 'newshit_primary_navigation_fallback',
                                )
                                );
                            ?>
                        </div>
                        <div class="right-section">

                            <?php if( get_theme_mod( 'header_dark_mode_enalbe', true ) ) : ?>
                                <div class="switch-dark-lite">
                                    <label class="switch" for="darkswitch">
                                        <input type="checkbox" id="darkswitch" class="theme-dark-lite">
                                        <span class="slider"></span>
                                        <input type="hidden" name="theme_mode" value="<?php echo esc_attr( get_theme_mod( 'theme_mode', 'light' ) ); ?>">
                                    </label>
                                </div>
                            <?php endif; ?>

                            <?php if( get_theme_mod( 'header_notification', true ) ) : ?>
                                <div class="notification-icon">
                                    <a href="<?php echo esc_url( get_theme_mod( 'header_notification_link' ) ); ?>" target="<?php echo esc_attr( get_theme_mod( 'header_notification_open_new' ) === true ? '_blank' : '_self' ); ?>"><i class="fas fa-bell"></i></a>
                                </div>
                            <?php endif; ?>

                            <?php if( get_theme_mod( 'header_search_enable', true ) ) : ?>
                                <div class="header-search-box search-open">
                                <a href="#"><i class="fas fa-search"></i></a>
                                </div>
                            <?php endif; ?>

                        </div>
                        <div id="mobile"></div>

                    </nav>
                </div>
            </div>
        <?php  }
    endif;
    add_action( 'newshit_action_navication_menu', 'newshit_navication_hook' );



    /**
     * BRAKING NEWS HOOK
     */

    if ( ! function_exists( 'newshit_braking_news_hook' ) ) :

        /**
         * BRAKING NEWS
         *
         * @since 1.0.0
         */
        function newshit_braking_news_hook() { 

        if( is_plugin_active( 'web-stories/web-stories.php' ) && 'web-story' === get_theme_mod('sticker_post_type', 'post' ) ){
            $post_type = 'web-story';
        }else{
            $post_type = 'post';
        }
        
        if( 'web-story' == $post_type && true === get_theme_mod('enable_sticker_story_filter', false ) && !empty( get_theme_mod( 'sticker_story_filter_cat', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'news_sticker_dispaly', 30 ),
                'post_type' => 'web-story',
                'orderby'        => get_theme_mod( 'news_sticker_postby' ),
                'order'          => get_theme_mod( 'news_sticker_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'web_story_category',
                        'terms'    => get_theme_mod( 'sticker_story_filter_cat' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }elseif( 'post' == $post_type && 'one' === get_theme_mod('sticker_filter_select','one' ) && !empty( get_theme_mod( 'sticker_filter_cat', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'news_sticker_dispaly', 30 ),
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'news_sticker_postby' ),
                'order'          => get_theme_mod( 'news_sticker_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'category',
                        'terms'    => get_theme_mod( 'sticker_filter_cat' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }elseif( 'post' == $post_type && 'two' === get_theme_mod('sticker_filter_select' ) && !empty( get_theme_mod( 'sticker_filter_tags', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'news_sticker_dispaly', 30 ),
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'news_sticker_postby' ),
                'order'          => get_theme_mod( 'news_sticker_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms'    => get_theme_mod( 'sticker_filter_tags' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }else{
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'news_sticker_dispaly', 30 ),
                'post_type' => $post_type,
                'orderby'   => get_theme_mod( 'news_sticker_postby' ),
                'order'     => get_theme_mod( 'news_sticker_order' ),
            ));
        }
        
        ?>
            <div class="newshit-news-sticker-wrapper">
                <div class="container">
                    <div class="acme-news-ticker">
                        <div class="acme-news-ticker-label"><?php echo esc_html( get_theme_mod( 'braking_news', 'Braking News' ) ); ?></div>
                        <div class="acme-news-ticker-box">
                            <ul class="newshit-news-ticker">
                                <?php while ( $p->have_posts() ): $p->the_post(); ?>
                                    <li class="newshit-post-item">
                                    <?php the_post_thumbnail( 'thumbnail' );?>
                                    <a href="<?php echo esc_url(the_permalink()); ?>"><?php echo newshit_words_limit( get_the_title(), get_theme_mod( 'news_sticker_title_lanth', 8 ) ); ?></a>
                                    </li>
                                <?php endwhile; wp_reset_query(); ?>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        <?php  }
    endif;
    add_action( 'newshit_action_braking_news', 'newshit_braking_news_hook' );


    /**
     * BRAKING NEWS HOOK
     */

     if ( ! function_exists( 'newshit_copyright_hook' ) ) :

        /**
         * BRAKING NEWS
         *
         * @since 1.0.0
         */
        function newshit_copyright_hook() { ?>
            <div class="copyright-info">
                <div class="site-info">
                    <?php
                        $newshit_powered_by = get_theme_mod( 'powered_by', 
                            sprintf( esc_html__( ' Theme: NewsHit by %s', 'newshit' ), '<a target="_blank" rel="dofollow" href="'. esc_url( 'https://themeuniver.com/' ) .'">Themeuniver</a>' )
                        );
                    ?>
                    <?php echo esc_html( get_theme_mod( 'copyright_text', 'Proudly powered by WordPress |') );?> <?php echo wp_kses_post( $newshit_powered_by );?>
                </div><!-- .site-info -->
            </div>
        <?php  }
    endif;
    add_action( 'newshit_copyright_action', 'newshit_copyright_hook' );


