<?php
/**
 * The header for our theme
 *
 * Displays the <head>, skip-link, navbar with custom logo, primary nav,
 * search widget, dark-mode toggle, and back-to-top button.
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package CyyWordpress
 */

?>
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="profile" href="https://gmpg.org/xfn/11">
	<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<?php wp_body_open(); ?>

<div id="page" class="site">

	<a class="skip-link screen-reader-text" href="#primary">
		<?php esc_html_e( '跳到内容', 'cyywordpress' ); ?>
	</a>

	<!-- Back-to-top button (hidden until scrolled 300px) -->
	<button
		id="back-to-top"
		class="back-to-top"
		aria-label="<?php esc_attr_e( '返回顶部', 'cyywordpress' ); ?>"
		hidden
	>
		<i class="fa-solid fa-arrow-up" aria-hidden="true"></i>
	</button>

	<nav
		id="site-navigation"
		class="navbar is-spaced site-navbar"
		role="navigation"
		aria-label="<?php esc_attr_e( '主导航', 'cyywordpress' ); ?>"
	>
		<div class="navbar-brand">
			<?php if ( has_custom_logo() ) : ?>
				<a class="navbar-item navbar-logo" href="<?php echo esc_url( home_url( '/' ) ); ?>">
					<?php the_custom_logo(); ?>
				</a>
			<?php else : ?>
				<a class="navbar-item navbar-site-name" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
					<span class="site-title-initial">
						<?php echo esc_html( mb_substr( get_bloginfo( 'name' ), 0, 1 ) ); ?>
					</span>
					<span class="site-title-text"><?php bloginfo( 'name' ); ?></span>
				</a>
			<?php endif; ?>

			<button
				class="navbar-burger"
				id="navbar-burger"
				aria-label="<?php esc_attr_e( '菜单', 'cyywordpress' ); ?>"
				aria-expanded="false"
				aria-controls="navbar-menu"
			>
				<span aria-hidden="true"></span>
				<span aria-hidden="true"></span>
				<span aria-hidden="true"></span>
			</button>
		</div><!-- .navbar-brand -->

		<div id="navbar-menu" class="navbar-menu">
			<div class="navbar-start">
				<?php
				wp_nav_menu(
					array(
						'theme_location' => 'menu-1',
						'menu_id'        => 'primary-menu',
						'depth'          => 3,
						'container'      => false,
						'menu_class'     => 'navbar-nav-list',
						'fallback_cb'    => array( 'Bulmapress_Navwalker', 'fallback' ),
						'walker'         => new Bulmapress_Navwalker(),
					)
				);
				?>
			</div><!-- .navbar-start -->

			<div class="navbar-end">
				<!-- Expandable search -->
				<div class="navbar-item navbar-search-wrap">
					<button
						class="navbar-search-toggle"
						aria-label="<?php esc_attr_e( '搜索', 'cyywordpress' ); ?>"
						aria-expanded="false"
						aria-controls="navbar-search-form"
					>
						<i class="fa-solid fa-magnifying-glass" aria-hidden="true"></i>
					</button>
					<form
						id="navbar-search-form"
						class="navbar-search-form"
						role="search"
						method="get"
						action="<?php echo esc_url( home_url( '/' ) ); ?>"
						hidden
					>
						<label class="screen-reader-text" for="navbar-search-input">
							<?php esc_html_e( '搜索', 'cyywordpress' ); ?>
						</label>
						<input
							id="navbar-search-input"
							class="input is-small"
							type="search"
							name="s"
							placeholder="<?php esc_attr_e( '搜索…', 'cyywordpress' ); ?>"
							value="<?php echo esc_attr( get_search_query() ); ?>"
						>
					</form>
				</div>

				<!-- Dark-mode toggle -->
				<div class="navbar-item">
					<button
						id="theme-toggle"
						class="theme-toggle"
						aria-label="<?php esc_attr_e( '切换深色模式', 'cyywordpress' ); ?>"
					>
						<i class="fa-solid fa-moon theme-toggle__dark-icon" aria-hidden="true"></i>
						<i class="fa-solid fa-sun  theme-toggle__light-icon" aria-hidden="true"></i>
					</button>
				</div>

				<?php if ( is_active_sidebar( 'sidebar-header' ) ) : ?>
					<?php dynamic_sidebar( 'sidebar-header' ); ?>
				<?php endif; ?>

				<?php if ( is_user_logged_in() ) : ?>
					<div class="navbar-item">
						<a class="button is-link is-light is-small" href="<?php echo esc_url( admin_url() ); ?>">
							<strong><?php esc_html_e( '后台', 'cyywordpress' ); ?></strong>
						</a>
					</div>
				<?php endif; ?>
			</div><!-- .navbar-end -->
		</div><!-- #navbar-menu -->
	</nav><!-- #site-navigation -->

	<div id="content" class="site-content container">

