<?php

/**
 * The file for header all actions
 *
 *
 * @package  News Axis
 */

// Fallback menu: Home + 5 pages
function news_axis_fallback_menu() {
	echo '<ul id="news-axis-menu" class="news-axis-menu">';
	echo '<li><a href="' . esc_url(home_url('/')) . '">' . esc_html__('Home', 'news-axis') . '</a></li>';
	$pages = get_pages(array('number' => 7, 'sort_column' => 'menu_order,post_title'));
	foreach ($pages as $page) {
		echo '<li><a href="' . esc_url(get_permalink($page->ID)) . '">' . esc_html($page->post_title) . '</a></li>';
	}
	echo '</ul>';
}

function news_axis_header_menu_output()
{
?>
	<nav id="site-navigation" class="main-navigation">
		<?php
		wp_nav_menu(array(
			'theme_location' => 'main-menu',
			'menu_id'        => 'news-axis-menu',
			'menu_class'        => 'news-axis-menu',
			'fallback_cb'    => 'news_axis_fallback_menu',
		));
		?>
	</nav><!-- #site-navigation -->
<?php
}
add_action('news_axis_main_menu', 'news_axis_header_menu_output');


function news_axis_header_logo_output()
{
	$news_axis_site_tagline_hide = get_theme_mod('news_axis_site_tagline_hide', 1);

?>

	<?php if (has_custom_logo()) : ?>
		<div class="site-branding brand-logo">
			<?php
			the_custom_logo();
			?>
		</div>
	<?php else : ?>
		<?php
		if (display_header_text() == true || (display_header_text() == true && is_customize_preview())) : ?>
			<div class="site-branding brand-text">
				<?php if (display_header_text() == true || (display_header_text() == true && is_customize_preview())) : ?>
					<h1 class="site-title"><a href="<?php echo esc_url(home_url('/')); ?>" rel="home"><?php bloginfo('name'); ?></a></h1>
					<?php
					$news_axis_description = get_bloginfo('description', 'display');
					if (($news_axis_description || is_customize_preview()) && empty($news_axis_site_tagline_hide)) :
					?>
						<p class="site-description">
							<?php echo esc_html($news_axis_description); ?></p>
					<?php endif; ?>
				<?php endif; ?>

			</div><!-- .site-branding -->
		<?php endif; ?>
	<?php endif; ?>

<?php
}
add_action('news_axis_header_logo', 'news_axis_header_logo_output');




// header style one
function news_axis_header_style_one()
{
?>
	<div class="pxm-style1">
		<div class="navigation">
			<div class="container">
				<div class="d-flex">
					<div class="pxms1-logo">
						<?php do_action('news_axis_header_logo'); ?>
					</div>
					<div class="pxms1-ticker">
						<?php do_action('article_axis_post_ticker'); ?>
					</div>
				</div>
			</div>
			<div class="main-nav1">
				<div class="container">
					<div class="pxms1-menu text-center">
						<?php do_action('news_axis_main_menu'); ?>
					</div>
				</div>
			</div>
		</div>
	</div>


<?php
}
add_action('news_axis_header_style_one', 'news_axis_header_style_one');

// header style one
function news_axis_header_style_two()
{

?>
	<div class="news-axis-logo-section">
		<div class="container">

			<div class="head-logo-sec">
				<?php do_action('news_axis_header_logo'); ?>
			</div>
			<div class="ticker-style2">
				<?php do_action('article_axis_post_ticker'); ?>
			</div>
		</div>
	</div>

	<div class="menu-bar text-center">
		<div class="container">
			<div class="news-axis-container menu-inner">
				<?php do_action('news_axis_main_menu'); ?>
			</div>
		</div>
	</div>
<?php
}
add_action('news_axis_header_style_two', 'news_axis_header_style_two');


//News Axis mobile menu
function news_axis_mobile_menu_output()
{
?>
	<div class="mobile-menu-bar">
		<div class="container">
			<nav id="mobile-navigation" class="mobile-navigation">
				<div class="mlogo-sec">
					<div class="mlogo">
						<?php do_action('news_axis_header_logo'); ?>
					</div>
					<button id="mmenu-btn" class="menu-btn" aria-expanded="false">
						<span class="mopen"><?php esc_html_e('Menu', 'news-axis'); ?></span>
						<span class="mclose"><?php esc_html_e('Close', 'news-axis'); ?></span>
					</button>
				</div>
				<?php
				wp_nav_menu(array(
					'theme_location' => 'main-menu',
					'menu_id'        => 'wsm-menu',
					'menu_class'        => 'wsm-menu',
					'fallback_cb'    => 'news_axis_fallback_menu',
				));
				?>
			</nav><!-- #site-navigation -->
		</div>
	</div>

	<?php
}
add_action('news_axis_mobile_menu', 'news_axis_mobile_menu_output');



function news_axis_post_ticker_output()
{
	// Arguments to query the latest posts
	$args = array(
		'posts_per_page' => 10, // Number of posts to display
		'post_status'    => 'publish', // Only show published posts
		'orderby'        => 'date',    // Order by post date
		'order'          => 'DESC',    // Descending order to get the newest post
	);

	// The Query
	$query = new WP_Query($args);

	if ($query->have_posts()) :
	?>
		<div class="ax-ticker-container">
			<div class="ax-new-text">
				<span><?php esc_html_e('New', 'news-axis'); ?></span>
			</div>
			<div class="ax-ticker" id="ax-ticker">
				<?php while ($query->have_posts()) : $query->the_post(); ?>
					<div class="ax-post">
						<?php if (has_post_thumbnail()) : ?>
							<img src="<?php echo esc_url(get_the_post_thumbnail_url(get_the_ID(), 'thumbnail')); ?>" alt="<?php echo esc_attr(get_the_title()); ?>">
						<?php endif; ?>
						<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
					</div>
				<?php endwhile; ?>
			</div>
		</div>
<?php
	endif;

	// Restore original Post Data
	wp_reset_postdata();
}
add_action('article_axis_post_ticker', 'news_axis_post_ticker_output');