<?php
namespace App\Http\Controllers\Portal;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
    public function index()
    {
        $user = auth()->user();

        $consignments = $user->consignments()
            ->with(['shipment'])
            ->orderByDesc('created_at')
            ->get();

        $active = $consignments->whereNotIn('status', ['delivered'])
                               ->values();

        $delivered = $consignments->where('status', 'delivered')
                                  ->values();

        $pendingPickup = $consignments->where('status', 'ready_for_pickup')
                                      ->values();

        return view('portal.dashboard', compact(
            'consignments',
            'active',
            'delivered',
            'pendingPickup'
        ));
    }
}