<?php

namespace App\Support;

use App\Models\User;
use Illuminate\Http\Request;

final class PortalNavigationContext
{
    public function resolve(Request $request): array
    {
        $webUser = auth('web')->user();
        $earnMember = auth('earn')->user();
        $isEarnContext = $request->routeIs('earn.*');

        if ($isEarnContext && $earnMember) {
            return ['kind' => 'earn', 'user' => $earnMember, 'panel_url' => route('earn.dashboard'), 'panel_label' => __('earn_portal.dashboard'), 'logout_route' => route('earn.logout')];
        }

        if (! $isEarnContext && $webUser instanceof User) {
            $admin = $webUser->canAccessAdminPortal();

            return ['kind' => 'web', 'user' => $webUser, 'panel_url' => $admin ? '/admin' : route('dashboard'), 'panel_label' => $admin ? __('landing.admin_panel') : __('landing.customer_panel'), 'logout_route' => route('logout')];
        }

        return ['kind' => 'guest', 'user' => null];
    }
}
