<?php
if (!function_exists('faced_do_skip_to_content_link')) {
    /**
     * Add skip to content link before the header.
     *
     * @since 1.0.0
     */
    function faced_do_skip_to_content_link()
    {
?>
        <a class="skip-link screen-reader-text" href="#content"><?php esc_html_e('Skip to content', 'faced'); ?></a>
    <?php
    }
}
add_action('faced_before_header', 'faced_do_skip_to_content_link', 10);


if (!function_exists('faced_header_search_modal')) {
    /**
     * Add search modal before header
     *
     * @since 1.0.0
     */
    function faced_header_search_modal()
    {
        global $faced_theme_options;
        if (($faced_theme_options['faced-enable-top-header-search'] != 1) || ($faced_theme_options['faced-enable-top-header'] != 1))
            return false;
    ?>
        <section class="search-section">
            <div class="container">
                <button class="close-btn"><i class="fa fa-times"></i></button>
                <?php get_search_form(); ?>
            </div>
        </section>
    <?php

    }
}
add_action('faced_header', 'faced_header_search_modal', 10);


if (!function_exists('faced_construct_header')) {
    /**
     * Add header
     *
     * @since 1.0.0
     */
    function faced_construct_header()
    {
        global $faced_theme_options;
        $faced_enable_top_header = absint($faced_theme_options['faced-enable-top-header']);
        $faced_enable_top_social = absint($faced_theme_options['faced-enable-top-header-social']);
        $faced_enable_top_menu = absint($faced_theme_options['faced-enable-top-header-menu']);
        $faced_enable_top_search = absint($faced_theme_options['faced-enable-top-header-search']);
    ?>
        <header id="masthead" class="site-header text-center site-header-v2">
            <?php
            if (($faced_enable_top_header == 1) && (($faced_enable_top_menu == 1) || ($faced_enable_top_search == 1) || ($faced_enable_top_social == 1))) {
            ?>
                <section class="site-header-topbar">
                    <a href="#" class="top-header-toggle-btn">
                        <i class="fa fa-chevron-down" aria-hidden="true"></i>
                    </a>
                    <div class="container">
                        <div class="row">
                            <div class="col col-sm-2-3 col-md-2-3 col-lg-2-4">
                                <?php
                                /**
                                 * faced_top_left hook.
                                 *
                                 * @since 1.0.0
                                 *
                                 * @hooked faced_top_menu - 10
                                 *
                                 */
                                do_action('faced_top_left');
                                ?>
                            </div>
                            <div class="col col-sm-1-3 col-md-1-3 col-lg-1-4">
                                <div class="faced-menu-social topbar-flex-grid">
                                    <?php
                                    /**
                                     * faced_top_right hook.
                                     *
                                     * @since 1.0.0
                                     *
                                     * @hooked faced_top_search - 10
                                     * @hooked faced_top_social - 20
                                     *
                                     */
                                    do_action('faced_top_right');
                                    ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
            <?php
            }

            /**
             * faced_main_header hook.
             *
             * @since 1.0.0
             *
             * @hooked faced_construct_main_header - 10
             */
            do_action('faced_main_header');
            ?>
        </header><!-- #masthead -->
    <?php

    }
}
add_action('faced_header', 'faced_construct_header', 20);

if (!function_exists('faced_top_menu')) {
    /**
     * Add menu on top header.
     *
     * @since 1.0.0
     */
    function faced_top_menu()
    {
        global $faced_theme_options;
        if ($faced_theme_options['faced-enable-top-header-menu'] != 1)
            return false;
    ?>
        <nav class="site-header-top-nav">
            <?php
            wp_nav_menu(array(
                'theme_location' => 'top-menu',
                'container' => 'ul',
                'menu_class' => 'site-header-top-menu',
                'depth' => 1
            ));
            ?>
        </nav>
    <?php
    }
}
add_action('faced_top_left', 'faced_top_menu', 10);


if (!function_exists('faced_top_search')) {
    /**
     * Add search icon on top header.
     *
     * @since 1.0.0
     */
    function faced_top_search()
    {
        global $faced_theme_options;
        if ($faced_theme_options['faced-enable-top-header-search'] != 1)
            return false;
    ?>
        <button class="search-toggle"><i class="fa fa-search"></i></button>
    <?php
    }
}
add_action('faced_top_right', 'faced_top_search', 10);

if (!function_exists('faced_top_social')) {
    /**
     * Add social icon menu on top header.
     *
     * @since 1.0.0
     */
    function faced_top_social()
    {
        global $faced_theme_options;
        if ($faced_theme_options['faced-enable-top-header-social'] != 1)
            return false;
        faced_social_menu();
    }
}
add_action('faced_top_right', 'faced_top_social', 20);

if (!function_exists('faced_construct_main_header')) {
    /**
     * Add Main Header
     *
     * @since 1.0.0
     */
    function faced_construct_main_header()
    {

        /**
         * faced_header_default hook.
         *
         * @since 1.0.0
         *
         * @hooked faced_default_header - 10
         */
        do_action('faced_header_default');
    }
}
add_action('faced_main_header', 'faced_construct_main_header', 10);


if (!function_exists('faced_default_header')) {
    /**
     * Add Default header
     *
     * @since 1.0.0
     */
    function faced_default_header()
    {
        global $faced_theme_options;
        $faced_ad_image_url = ($faced_theme_options['faced-header-ads-image-link']);
        $faced_ad_image = ($faced_theme_options['faced-top-header-ad-section-image']);
        $enable_ad = ($faced_theme_options['faced-enable-ads-header']);
        //has header image
        $has_header_image = has_header_image();
    ?>

        <div id="site-nav-wrap">
            <section id="site-navigation" class="site-header-top header-main-bar" <?php if (!empty($has_header_image)) { ?> style="background-image: url(<?php echo header_image(); ?>);" <?php } ?>>
                <div class="container">
                    <div class="row">
                        <div class="site-branding-wrap col-1-1 col-md-1-4">
                            <?php
                            /**
                             * faced_branding hook.
                             *
                             * @since 1.0.0
                             *
                             * @hooked faced_construct_branding - 10
                             */
                            do_action('faced_branding');
                            ?>
                        </div>
                        <?php if($enable_ad): ?>
                        <div class="header-poster-wrap col-1-1 col-md-2-4">
                            <a href="<?php echo esc_url($faced_ad_image_url); ?>" target="_blank">
                                <?php if($faced_ad_image){ ?>
                                    <img src="<?php echo esc_url($faced_ad_image); ?>">
                                <?php }else{ ?>
                                    <img src="<?php  get_template_directory_uri().'/candidthemes/assets/custom/img/900x60.png' ?>">
                                <?php  } ?>
                            </a>
                        </div>
                        <?php endif; ?>

                    </div>
                </div>
            </section>

            <section class="site-header-bottom">
                <div class="container">
                    <?php
                    /**
                     * faced_main_menu hook.
                     *
                     * @since 1.0.0
                     *
                     * @hooked faced_construct_main_menu - 10
                     */
                    do_action('faced_main_menu');
                    ?>

                </div>
            </section>
        </div>
    <?php
    }
}
add_action('faced_header_default', 'faced_default_header', 10);





if (!function_exists('faced_construct_branding')) {
    /**
     * Add Branding on Header
     *
     * @since 1.0.0
     */
    function faced_construct_branding()
    {
    ?>
        <div class="site-branding">
            <?php
            the_custom_logo();
            if (is_front_page() && is_home()) :
            ?>
                <h1 class="site-title"><a href="<?php echo esc_url(home_url('/')); ?>" rel="home"><?php bloginfo('name'); ?></a></h1>
            <?php
            else :
            ?>
                <p class="site-title"><a href="<?php echo esc_url(home_url('/')); ?>" rel="home"><?php bloginfo('name'); ?></a></p>
            <?php
            endif;
            $faced_description = get_bloginfo('description', 'display');
            if ($faced_description || is_customize_preview()) :
            ?>
                <p class="site-description"><?php echo $faced_description; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                                            ?></p>
            <?php endif; ?>
        </div><!-- .site-branding -->

        <button id="menu-toggle-button" class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
            <span class="line"></span>
            <span class="line"></span>
            <span class="line"></span>
        </button>
    <?php
    }
}
add_action('faced_branding', 'faced_construct_branding', 10);



if (!function_exists('faced_construct_main_menu')) {
    /**
     * Add Main Menu on Header
     *
     * @since 1.0.0
     */
    function faced_construct_main_menu()
    {
    ?>
        <nav class="main-navigation">
            <ul id="primary-menu" class="nav navbar-nav nav-menu justify-content-center">
                <?php
                if (has_nav_menu('menu-1')) :
                    wp_nav_menu(array(
                        'theme_location' => 'menu-1',
                        'items_wrap' => '%3$s',
                        'container' => false
                    ));
                else :
                    wp_list_pages(array('depth' => 0, 'title_li' => ''));
                endif; // has_nav_menu
                ?>
                <button class="close_nav"><i class="fa fa-times"></i></button>
            </ul>
        </nav><!-- #site-navigation -->
<?php
    }
}
add_action('faced_main_menu', 'faced_construct_main_menu', 10);
