<?php

namespace App\Http\Controllers\Customer;

use App\Http\Controllers\Controller;
use App\Models\Pesanan;
use Illuminate\Support\Facades\Auth;

class DashboardController extends Controller
{
    public function index()
    {
        $userId = Auth::id();

        // Data statistik yang dibutuhkan view
        $stats = [
            'aktif' => Pesanan::where('user_id', $userId)->whereIn('status', ['pending', 'dijadwalkan', 'dikirim'])->count(),
            'total_transaksi' => Pesanan::where('user_id', $userId)->where('status', 'selesai')->sum('total_harga'),
            'riwayat_count' => Pesanan::where('user_id', $userId)->where('status', 'selesai')->count(),
        ];

        $latestOrder = Pesanan::where('user_id', $userId)->latest()->first();

        return view('customer.dashboard', compact('stats', 'latestOrder'));
    }
}