@php
    $pageTitle = trim($__env->yieldContent('page_title') ?: $__env->yieldContent('title') ?: 'CRM');
@endphp
<header class="portal-topbar">
    <div class="portal-topbar-left">
        <button type="button" class="portal-topbar-menu-btn d-lg-none" id="portalSidebarOpen" aria-label="Open menu">
            <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 12h18M3 6h18M3 18h18"/></svg>
        </button>
        <div class="portal-topbar-titles">
            @hasSection('breadcrumbs')
                <nav class="portal-breadcrumb" aria-label="Breadcrumb">
                    @yield('breadcrumbs')
                </nav>
            @else
                <nav class="portal-breadcrumb" aria-label="Breadcrumb">
                    <a href="{{ default_home_url() }}">Home</a>
                    @if(!request()->routeIs('leads.dashboard', 'home', 'crm.home'))
                        <span class="portal-breadcrumb-sep">/</span>
                        <span class="portal-breadcrumb-current">{{ $pageTitle }}</span>
                    @endif
                </nav>
            @endif
            <h1 class="portal-topbar-title">{{ $pageTitle }}</h1>
        </div>
    </div>
    <div class="portal-topbar-right">
        <div class="dropdown">
            <button class="portal-topbar-user dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                <span class="portal-topbar-avatar">{{ strtoupper(substr(auth()->user()->name, 0, 1)) }}</span>
                <span class="portal-topbar-user-text d-none d-sm-inline">
                    <span class="portal-topbar-user-name">{{ auth()->user()->name }}</span>
                    <span class="portal-topbar-user-email">{{ auth()->user()->email }}</span>
                </span>
            </button>
            <ul class="dropdown-menu dropdown-menu-end portal-user-dropdown">
                <li class="dropdown-header">
                    <div class="fw-semibold">{{ auth()->user()->name }}</div>
                    <div class="small text-muted">{{ auth()->user()->email }}</div>
                    @if(optional(auth()->user()->department)->name)
                        <div class="small text-muted mt-1">{{ auth()->user()->department->name }}</div>
                    @endif
                </li>
                <li><hr class="dropdown-divider"></li>
                <li>
                    <form method="POST" action="{{ route('logout') }}" class="px-2">
                        @csrf
                        <button type="submit" class="dropdown-item text-danger rounded">Logout</button>
                    </form>
                </li>
            </ul>
        </div>
    </div>
</header>
