<header id="masthead" class="site-header site-header-1">
    <?php get_template_part('template-parts/banner/ticker'); ?>
    <div class="site-header-branding">
        <div class="wrapper header-wrapper">
            <div class="site-header-area site-header-center">
                <div class="site-branding">
                    <?php
                    // Site title or logo.
                    united_blog_site_logo();
                    // Site description.
                    united_blog_site_description();
                    ?>
                </div>
            </div>
        </div>
    </div>
    <div class="site-header-navbar">
        <div class="wrapper header-wrapper-grid">
            <div class="site-header-area site-header-left">
                <button class="toggle nav-toggle mobile-nav-toggle" data-toggle-target=".menu-modal"
                        data-toggle-body-class="showing-menu-modal" aria-expanded="false"
                        data-set-focus=".close-nav-toggle">
                    <span class="screen-reader-text"><?php echo esc_html__('Menu', 'united-blog'); ?></span>
                    <span class="hamburger">
                        <span></span>
                        <span></span>
                        <span></span>
                    </span>
                </button><!-- .nav-toggle -->
            </div>
            <div class="site-header-area site-header-center hide-on-tablet hide-on-mobile">
                <div class="header-navigation-wrapper">
                    <?php
                    if (has_nav_menu('primary')) {
                        ?>
                        <nav class="primary-menu-wrapper"
                             aria-label="<?php echo esc_attr_x('Horizontal', 'menu', 'united-blog'); ?>">
                            <ul class="primary-menu reset-list-style">
                                <?php
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'primary',
                                    )
                                );
                                ?>
                            </ul>
                        </nav><!-- .primary-menu-wrapper -->
                        <?php
                    } else {
                        ?>
                        <nav class="primary-menu-wrapper"
                             aria-label="<?php echo esc_attr_x('Horizontal', 'menu', 'united-blog'); ?>">
                            <ul class="primary-menu reset-list-style">
                                <?php
                                wp_list_pages(
                                    array(
                                        'match_menu_classes' => true,
                                        'show_toggles' => true,
                                        'title_li' => false,
                                        'walker' => new United_Walker_Page(),
                                    )
                                );
                                ?>
                            </ul>
                        </nav><!-- .primary-menu-wrapper -->
                        <?php
                    }
                    ?>
                </div>
            </div>
            <div class="site-header-area site-header-right">
                <?php
                $enable_header_favorites = united_blog_get_option('enable_header_favorites');
                if ($enable_header_favorites && class_exists( 'Favorites' )) {
                    ?>
                    <a href="<?php echo get_home_url() . '/favorites'; ?>" class="toggle site-button-favorites">
                        <span class="screen-reader-text"><?php echo esc_html__('Favorites', 'united-blog'); ?></span>
                        <?php united_blog_the_theme_svg('collection'); ?>
                    </a>
                <?php } ?>


                <?php
                $enable_random_post = united_blog_get_option('enable_random_post');
                if ($enable_random_post) {
                    $random_post_category = united_blog_get_option('random_post_category');
                    $rand_posts_arg = array(
                        'posts_per_page' => 1,
                        'orderby' => 'rand'
                    );
                    if ($random_post_category) {
                        $rand_posts_arg['cat'] = absint($random_post_category);
                    }
                    $rand_posts = get_posts($rand_posts_arg);
                    if ($rand_posts) {
                        ?>
                        <a href="<?php echo esc_url(get_permalink($rand_posts[0]->ID)); ?>"
                           class="toggle site-button-random">
                            <span class="screen-reader-text"><?php echo esc_html__('Shuffle', 'united-blog'); ?></span>
                            <?php united_blog_the_theme_svg('random'); ?>
                        </a>
                        <?php
                    }
                }
                ?>
                <?php
                $show_light_dark_switch = united_blog_get_option('show_light_dark_switch');
                $force_dark_mode = united_blog_get_option('force_dark_mode');
                if ($show_light_dark_switch) : ?>
                    <button class="toggle site-button-mode" aria-expanded="false">
                        <span class="screen-reader-text"><?php echo esc_html__('Switch color mode', 'united-blog'); ?></span>
                        <span id="colormode-switch-area">
                           <span id="mode-icon-switch"></span>
                           <span class="mode-icon-change"></span>
                       </span>
                    </button>
                <?php endif; ?>
                <?php
                // Check whether the header search is activated in the customizer.
                $enable_header_search = united_blog_get_option('enable_header_search');
                if ($enable_header_search) {
                    ?>
                    <button class="toggle search-toggle" data-toggle-target=".search-modal"
                            data-toggle-body-class="showing-search-modal"
                            data-set-focus=".search-modal .search-field" aria-expanded="false">
                        <?php united_blog_the_theme_svg('search'); ?>
                        <span class="screen-reader-text"><?php _ex('Search', 'toggle text', 'united-blog'); ?></span>
                    </button><!-- .search-toggle -->
                <?php } ?>

            </div>
        </div>
    </div>
</header>
