@props([
    'pageTitle' => null,
    'pageIcon' => 'fe fe-home',
    'breadcrumbs' => [],
])

@php
    $resolvedPageTitle = $pageTitle ?? __('common.dashboard');
    $ancestors = [];
    $count = count($breadcrumbs);

    foreach ($breadcrumbs as $i => $item) {
        if ($i === $count - 1 && empty($item['url'] ?? null)) {
            continue;
        }
        $ancestors[] = $item;
    }
@endphp

<nav class="topnav-bar erp-context-subbar" id="topnav">
    <div class="container-fluid erp-app-chrome__inner erp-context-subbar__inner px-2 px-md-3 px-lg-4">
        <div class="d-flex flex-wrap align-items-center justify-content-between gap-2">
            <div class="topnav-context flex-grow-1 min-w-0">
                <x-ui.layout.context-trail
                    :ancestors="$ancestors"
                    :page-title="$resolvedPageTitle"
                    :page-icon="$pageIcon"
                />
            </div>
            @isset($toolbar)
                @if (trim((string) $toolbar) !== '')
                    <div class="topnav-context-toolbar d-flex flex-wrap align-items-center gap-2 flex-shrink-0">
                        {{ $toolbar }}
                    </div>
                @endif
            @endisset
        </div>
    </div>
</nav>
