<?php

/**
 * The file for header all actions
 *
 *
 * @package Doctors Profile
 */

function doctors_profile_header_menu_output()
{
?>
	<nav id="site-navigation" class="main-navigation">
		<?php
		wp_nav_menu(array(
			'theme_location' => 'main-menu',
			'menu_id'        => 'doctors-profile-menu',
			'menu_class'        => 'doctors-profile-menu',
			'fallback_cb'    => 'doctors_profile_fallback_menu',
		));
		?>
	</nav><!-- #site-navigation -->
<?php
}
add_action('doctors_profile_main_menu', 'doctors_profile_header_menu_output');


function doctors_profile_header_logo_output()
{
	$doctors_profile_site_tagline_show = get_theme_mod('doctors_profile_site_tagline_show');

?>

	<?php if (has_custom_logo()) : ?>
		<div class="site-branding brand-logo">
			<?php
			the_custom_logo();
			?>
		</div>
	<?php endif; ?>
	<?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
				$doctors_profile_description = get_bloginfo('description', 'display');
				if (($doctors_profile_description || is_customize_preview()) && empty($doctors_profile_site_tagline_show)) :
				?>
					<p class="site-description"><?php echo $doctors_profile_description; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 
												?></p>
				<?php endif; ?>
			<?php endif; ?>

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

<?php
}
add_action('doctors_profile_header_logo', 'doctors_profile_header_logo_output');




// header style one
function doctors_profile_header_style_one()
{
?>
	<div class="container-fluid pxm-style1">
		<div class="navigation mx-4">
			<div class="d-flex">
				<div class="pxms1-logo">
					<?php do_action('doctors_profile_header_logo'); ?>
				</div>
				<div class="pxms1-menu ms-auto">
					<?php do_action('doctors_profile_main_menu'); ?>
				</div>
			</div>
		</div>
	</div>


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

// header style one
function doctors_profile_header_style_two()
{

?>
	<div class="doctors-profile-logo-section">
		<div class="container">
			<div class="head-logo-sec">
				<?php do_action('doctors_profile_header_logo'); ?>
			</div>
		</div>
	</div>

	<div class="menu-bar text-center">
		<div class="container">
			<div class="doctors-profile-container menu-inner">
				<?php do_action('doctors_profile_main_menu'); ?>
			</div>
		</div>
	</div>
<?php
}
add_action('doctors_profile_header_style_two', 'doctors_profile_header_style_two');


function doctors_profile_mobile_menu_output()
{
?>
	<div class="mobile-menu-bar">
		<div class="container">
			<nav id="mobile-navigation" class="mobile-navigation">
				<button id="mmenu-btn" class="menu-btn" aria-expanded="false">
					<span class="mopen"><?php esc_html_e('Menu', 'doctors-profile'); ?></span>
					<span class="mclose"><?php esc_html_e('Close', 'doctors-profile'); ?></span>
				</button>
				<?php
				wp_nav_menu(array(
					'theme_location' => 'main-menu',
					'menu_id'        => 'wsm-menu',
					'menu_class'        => 'wsm-menu',
					'fallback_cb'    => 'doctors_profile_fallback_menu',
				));
				?>
			</nav><!-- #site-navigation -->
		</div>
	</div>

<?php
}
add_action('doctors_profile_mobile_menu', 'doctors_profile_mobile_menu_output');

/**
 * Fallback menu function - displays Home + 6 pages (max 7 items)
 */
function doctors_profile_fallback_menu($args = array())
{
	$menu_id = isset($args['menu_id']) ? $args['menu_id'] : 'doctors-profile-menu';
	$menu_class = isset($args['menu_class']) ? $args['menu_class'] : 'doctors-profile-menu';
	
	// Get pages (limit to 6 pages)
	$pages = get_pages(array(
		'sort_column' => 'menu_order, post_title',
		'number' => 6,
	));
	
	if (!$pages && !is_home()) {
		return;
	}
	
	echo '<ul id="' . esc_attr($menu_id) . '" class="' . esc_attr($menu_class) . '">';
	
	// Home link
	$home_class = is_home() || is_front_page() ? ' class="current-menu-item"' : '';
	echo '<li' . $home_class . '><a href="' . esc_url(home_url('/')) . '">' . esc_html__('Home', 'doctors-profile') . '</a></li>';
	
	// Page links (max 6)
	foreach ($pages as $page) {
		$current_class = (is_page($page->ID)) ? ' class="current-menu-item"' : '';
		echo '<li' . $current_class . '><a href="' . esc_url(get_permalink($page->ID)) . '">' . esc_html($page->post_title) . '</a></li>';
	}
	
	echo '</ul>';
}
