<?php
/**
 * The header for our theme
 *
 * @package Nihongo
 */

$current_lang = nihongo_get_current_language();
?>
<!DOCTYPE html>
<html lang="<?php echo $current_lang === 'jp' ? 'ja' : 'en'; ?>">
<head>
    <meta charset="<?php bloginfo('charset'); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="<?php bloginfo('description'); ?>">
    <meta name="keywords" content="Japanese learning,online lessons,Japanese courses,JLPT preparation,foreign talent,Japanese culture">
    <?php wp_head(); ?>
    
    <!-- App name (force Japanese label for this section) -->
    <meta name="application-name" content="J-Bridge（外国人材マッチング）">
    <meta name="apple-mobile-web-app-title" content="J-Bridge（外国人材マッチング）">

    <!-- Site Icons (use logo image) -->
    <link rel="icon" type="image/png" sizes="32x32" href="<?php echo get_template_directory_uri(); ?>/assets/img/logo.png">
    <link rel="icon" type="image/png" sizes="192x192" href="<?php echo get_template_directory_uri(); ?>/assets/img/logo.png">
    <link rel="apple-touch-icon" href="<?php echo get_template_directory_uri(); ?>/assets/img/logo.png">
    
    <!-- Open Graph -->
    <meta property="og:title" content="<?php wp_title('|', true, 'right'); bloginfo('name'); ?>">
    <meta property="og:description" content="<?php bloginfo('description'); ?>">
    <meta property="og:type" content="website">
    <meta property="og:url" content="<?php echo home_url(); ?>">
    <meta property="og:image" content="<?php echo get_template_directory_uri(); ?>/assets/img/og-image.jpg">
    
    <!-- Language Switcher JavaScript moved to assets/js/main.js -->

</head>
<body class="<?php echo ($current_page === 'home') ? 'page-bg ' : ''; ?>lang-<?php echo $current_lang; ?>">
    <!-- Header -->
    <header class="header">
        <div class="container">
            <div class="header-content">
                <!-- Logo -->
                <div class="logo">
                    <a href="<?php echo home_url(); ?>">
                        <?php if (has_custom_logo()) : ?>
                            <?php the_custom_logo(); ?>
                        <?php else : ?>
                            <img src="<?php echo get_template_directory_uri(); ?>/assets/img/logo.png" alt="<?php echo nihongo_translate('logo_alt'); ?>" class="logo-img">
                        <?php endif; ?>
                    </a>
                </div>
                
                <!-- Header Right Section -->
                <div class="header-right">
                    <!-- Navigation -->
                    <nav class="nav">
                        <?php
                        // Check if primary menu exists, otherwise use fallback
                        if (has_nav_menu('primary')) {
                            wp_nav_menu(array(
                                'theme_location' => 'primary',
                                'menu_class' => 'nav-list',
                                'container' => false,
                                'fallback_cb' => false,
                            ));
                        } else {
                            // Use our custom navigation function
                            echo nihongo_render_navigation();
                        }
                        ?>
                    </nav>
                    
                    <!-- Language Switcher (Inline) -->
                    <div class="language-switcher inline-lang">
                        <a href="<?php echo add_query_arg('lang', 'jp', get_current_url()); ?>" class="lang-inline <?php echo $current_lang === 'jp' ? 'active' : ''; ?>">JA</a>
                        <span class="lang-sep" style="color:rgb(158, 160, 165);">/</span>
                        <a href="<?php echo add_query_arg('lang', 'en', get_current_url()); ?>" class="lang-inline <?php echo $current_lang === 'en' ? 'active' : ''; ?>">EN</a>
                        <span class="lang-active-indicator" aria-hidden="true"></span>
                    </div>
                    
                    <!-- Mobile Menu Toggle -->
                    <button class="mobile-menu-toggle" aria-label="<?php echo nihongo_translate('open_menu'); ?>">
                        <span></span>
                        <span></span>
                        <span></span>
                    </button>
                </div>
            </div>
        </div>
    </header>
    
    <!-- Mobile Navigation -->
    <div class="mobile-nav">
        <div class="mobile-nav-content">
            <?php
            // Check if primary menu exists, otherwise use fallback
            if (has_nav_menu('primary')) {
                wp_nav_menu(array(
                    'theme_location' => 'primary',
                    'menu_class' => 'mobile-nav-list',
                    'container' => false,
                    'fallback_cb' => false,
                ));
            } else {
                // Use our custom navigation function for mobile
                echo nihongo_render_navigation(null, 'mobile-nav-list');
            }
            ?>
            
            <div class="mobile-language-switcher">
                <a href="<?php echo add_query_arg('lang', 'jp', get_current_url()); ?>" class="mobile-lang-btn <?php echo $current_lang === 'jp' ? 'active' : ''; ?>" data-lang="jp">
                    <span class="lang-flag">🇯🇵</span>
                    <span class="lang-text">日本語</span>
                </a>
                <a href="<?php echo add_query_arg('lang', 'en', get_current_url()); ?>" class="mobile-lang-btn <?php echo $current_lang === 'en' ? 'active' : ''; ?>" data-lang="en">
                    <span class="lang-flag">🇺🇸</span>
                    <span class="lang-text">English</span>
                </a>
            </div>
        </div>
    </div>
    
    <!-- Breadcrumbs -->
    <?php if (!is_front_page()) : ?>
        <div class="breadcrumbs-container">
            <div class="container">
                <?php echo nihongo_breadcrumbs(); ?>
            </div>
        </div>
    <?php endif; ?>

    <!-- Main Content -->
    <main class="main">
