@props(['shellPlayer' => null, 'notificationCount' => 0])

<header class="arena-header" role="banner" aria-label="Application header">
    <button class="header-toggle" id="sidebarToggle" aria-label="Toggle sidebar" aria-expanded="true" aria-controls="arenaSidebar">
        <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v18"/></svg>
    </button>

    <div class="header-search">
        <svg class="search-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>
        <input type="search" id="headerSearch" placeholder="Search players, teams, events..." aria-label="Search" aria-keyshortcuts="Control+K" readonly>
        <div class="search-kbd" aria-hidden="true">
            <span class="kbd">Ctrl</span>
            <span class="kbd">K</span>
        </div>
    </div>

    <div class="header-actions">
        <div class="lang-switcher d-none d-md-flex" role="group" aria-label="Language">
            <button type="button" class="lang-btn {{ app()->getLocale() === 'en' ? 'active' : '' }}" data-lang="en" aria-label="English">EN</button>
            <button type="button" class="lang-btn {{ app()->getLocale() === 'ar' ? 'active' : '' }}" data-lang="ar" aria-label="العربية">AR</button>
        </div>

        <a href="{{ route('preview.chat') }}" class="header-btn" aria-label="Messages">
            <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
        </a>

        <div style="position:relative;">
            <button type="button" class="header-btn" id="notificationTrigger" aria-label="Notifications" aria-haspopup="true" aria-expanded="false">
                <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
                @if($notificationCount > 0)
                    <span class="badge-count">{{ $notificationCount > 9 ? '9+' : $notificationCount }}</span>
                @endif
            </button>
            <div class="dropdown-arena" id="notificationPanel" role="region" aria-label="Notifications">
                <div style="padding:12px 16px; border-bottom:1px solid var(--arena-border); display:flex; justify-content:space-between; align-items:center;">
                    <span class="section-title" style="font-size:0.8rem;">Notifications</span>
                    @auth
                        <a href="{{ route('notifications.index') }}" class="panel-link">View all</a>
                    @endauth
                </div>
                <div style="padding:16px; color:var(--arena-text-muted); font-size:0.8rem;">
                    @if($notificationCount > 0)
                        You have {{ $notificationCount }} unread notification{{ $notificationCount === 1 ? '' : 's' }}.
                    @else
                        You're all caught up.
                    @endif
                </div>
            </div>
        </div>

        <div style="position:relative;">
            <button type="button" class="header-profile" id="profileTrigger" aria-haspopup="true" aria-expanded="false" aria-label="Account menu">
                <img
                    src="{{ $shellPlayer['avatar'] ?? asset('assets/images/generated/players/player-1.webp') }}"
                    alt=""
                    class="avatar"
                    width="34"
                    height="34"
                >
                <div class="d-none d-lg-block">
                    <div class="profile-name">{{ $shellPlayer['display_name'] ?? 'Guest' }}</div>
                    <div class="profile-rank">
                        @if($shellPlayer)
                            Level {{ $shellPlayer['level'] ?? 1 }}
                        @else
                            Sign in
                        @endif
                    </div>
                </div>
                <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="d-none d-lg-block" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg>
            </button>
            <div class="dropdown-arena" id="profileDropdown">
                @auth
                    <div style="padding:14px 16px; border-bottom:1px solid var(--arena-border);">
                        <div style="font-family:var(--font-display); font-weight:700; color:#fff;">{{ $shellPlayer['display_name'] ?? auth()->user()->display_name }}</div>
                        <div style="font-size:0.7rem; color:var(--arena-text-muted);">{{ auth()->user()->email }}</div>
                    </div>
                    <a class="dropdown-item-arena" href="{{ $shellPlayer['profile_url'] ?? route('settings') }}">View Profile</a>
                    <a class="dropdown-item-arena" href="{{ route('settings') }}">Settings</a>
                    <div class="dropdown-divider"></div>
                    <form method="POST" action="{{ route('logout') }}">
                        @csrf
                        <button type="submit" class="dropdown-item-arena danger" style="width:100%; border:none; background:transparent; text-align:start; cursor:pointer;">Sign Out</button>
                    </form>
                @else
                    <a class="dropdown-item-arena" href="{{ route('login') }}">Sign In</a>
                    <a class="dropdown-item-arena" href="{{ route('register') }}">Create Account</a>
                @endauth
            </div>
        </div>
    </div>
</header>
