@props([ 'mode' => 'auto', // 'auto' | 'tabs' | 'context' 'primaryLabel' => null, 'primaryOnclick' => null, 'primaryHref' => null, 'leftOnclick' => null, 'leftHref' => null, 'ariaLabel' => null, ]) @php $pathname = '/'.ltrim(request()->path(), '/'); $hide = in_array($pathname, ['/onboarding', '/login', '/register', '/forgot-password', '/reset-password', '/welcome'], true); $isTopTab = in_array($pathname, ['/', '/groups', '/activity', '/account', '/insights'], true); $computedMode = $mode; $computedPrimaryLabel = $primaryLabel; $computedPrimaryHref = $primaryHref; $computedPrimaryOnclick = $primaryOnclick; $computedLeftHref = $leftHref; $computedLeftOnclick = $leftOnclick; $plusHref = route('app.add-expense'); $plusAria = 'Add expense'; if ($mode === 'auto') { $computedMode = $isTopTab ? 'tabs' : 'context'; if (! $isTopTab) { // Default left action is Back (history.back()). $computedLeftOnclick = $computedLeftOnclick ?: "window.WeShareNav?.back?.('/') || history.back()"; // Route-aware primary actions. if (str_starts_with($pathname, '/group/') && ! str_contains($pathname, '/expense/') && ! str_ends_with($pathname, '/members')) { // Group detail $groupId = request()->route('id'); if ($groupId) { $computedPrimaryLabel = $computedPrimaryLabel ?: 'Add expense'; $computedPrimaryHref = $computedPrimaryHref ?: route('app.add-expense', ['group' => $groupId]); } } elseif (str_contains($pathname, '/expense/')) { // Expense detail (group or list) $groupId = request()->route('groupId') ?: request()->route('id'); if ($groupId) { $computedPrimaryLabel = $computedPrimaryLabel ?: 'Settle'; $computedPrimaryHref = $computedPrimaryHref ?: route('app.settle-up', ['id' => $groupId]); } } elseif (str_starts_with($pathname, '/settle/')) { // Group settle screen $computedPrimaryLabel = $computedPrimaryLabel ?: 'Record payment'; $computedPrimaryOnclick = $computedPrimaryOnclick ?: "window.scrollTo({top: 0, behavior: 'smooth'})"; } elseif (str_starts_with($pathname, '/shared-lists/') && str_ends_with($pathname, '/settle')) { // Shared list settle screen $computedPrimaryLabel = $computedPrimaryLabel ?: 'Record payment'; $computedPrimaryOnclick = $computedPrimaryOnclick ?: "window.scrollTo({top: 0, behavior: 'smooth'})"; } elseif (str_starts_with($pathname, '/shared-lists/') && str_ends_with($pathname, '/members')) { $computedPrimaryLabel = $computedPrimaryLabel ?: 'Add someone'; $computedPrimaryOnclick = $computedPrimaryOnclick ?: "window.scrollTo({top: 0, behavior: 'smooth'})"; } elseif ($pathname === '/shared-lists/intro') { $computedPrimaryLabel = $computedPrimaryLabel ?: 'New list'; $computedPrimaryHref = $computedPrimaryHref ?: route('app.shared-lists.new'); } elseif ($pathname === '/shared-lists/new') { $computedPrimaryLabel = $computedPrimaryLabel ?: 'Create list'; $computedPrimaryOnclick = $computedPrimaryOnclick ?: "document.getElementById('create-shared-list-form')?.requestSubmit?.()"; } elseif (str_starts_with($pathname, '/shared-purchases/') && $pathname !== '/shared-purchases/intro' && $pathname !== '/shared-purchases/new') { $computedPrimaryLabel = $computedPrimaryLabel ?: 'Save'; $computedPrimaryOnclick = $computedPrimaryOnclick ?: "document.querySelector('form')?.requestSubmit?.()"; } elseif ($pathname === '/shared-purchases/intro') { $computedPrimaryLabel = $computedPrimaryLabel ?: 'New purchase'; $computedPrimaryHref = $computedPrimaryHref ?: route('app.shared-purchases.new'); } elseif ($pathname === '/shared-purchases/new') { $computedPrimaryLabel = $computedPrimaryLabel ?: 'Create purchase'; $computedPrimaryOnclick = $computedPrimaryOnclick ?: "document.getElementById('create-shared-purchase-form')?.requestSubmit?.()"; } elseif ($pathname === '/create-group') { $computedPrimaryLabel = $computedPrimaryLabel ?: 'Create group'; $computedPrimaryOnclick = $computedPrimaryOnclick ?: "document.querySelector('form')?.requestSubmit?.()"; } elseif ($pathname === '/add-expense') { $computedPrimaryLabel = $computedPrimaryLabel ?: 'Add expense'; $computedPrimaryOnclick = $computedPrimaryOnclick ?: "document.getElementById('add-expense-form')?.requestSubmit?.()"; } elseif (str_starts_with($pathname, '/shared-lists/') && $pathname !== '/shared-lists/intro' && $pathname !== '/shared-lists/new') { // Shared list detail already overrides; keep fallback in case $computedPrimaryLabel = $computedPrimaryLabel ?: 'Add item'; $computedPrimaryOnclick = $computedPrimaryOnclick ?: "(function(){ const el=document.getElementById('addItemInput'); if(el){ el.scrollIntoView({behavior:'smooth', block:'center'}); el.focus(); el.select(); } })()"; } } else { // Tabs mode: make the + button match the current tab. if ($pathname === '/groups') { $plusHref = route('app.create-group'); $plusAria = 'Create group'; } elseif ($pathname === '/account' || $pathname === '/insights') { $plusHref = route('app.account.profile.edit'); $plusAria = 'Edit profile'; } else { // Home + Activity default to Add expense $plusHref = route('app.add-expense'); $plusAria = 'Add expense'; } } } @endphp @if (!$hide) @endif