<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Service;
use Illuminate\Support\Facades\Auth;

class CustomerController extends Controller
{
    /**
     * Menampilkan halaman home untuk customer
     */
    public function home()
    {
        $user = Auth::user();

        // Mengambil statistik layanan milik customer
        $totalServices = Service::where('user_id', $user->id)->count();
        $pendingServices = Service::where('user_id', $user->id)
            ->where('status', 'Menunggu')
            ->count();
        $processedServices = Service::where('user_id', $user->id)
            ->where('status', 'Diproses')
            ->count();
        $completedServices = Service::where('user_id', $user->id)
            ->where('status', 'Selesai')
            ->count();
        $rejectedServices = Service::where('user_id', $user->id)
            ->where('status', 'Ditolak')
            ->count();

        // Mengambil layanan terbaru milik customer
        $latestServices = Service::where('user_id', $user->id)
            ->latest()
            ->take(5)
            ->get();

        return view('customer.home', compact(
            'user',
            'totalServices',
            'pendingServices',
            'processedServices',
            'completedServices',
            'rejectedServices',
            'latestServices'
        ));
    }
}