<?php

namespace App\Livewire\Dashboard;

use App\Models\Appointment;
use App\Models\JobCard;
use Livewire\Component;

class DailySchedule extends Component
{
    public function render()
    {
        $today = now()->startOfDay();
        
        $schedule = [
            'appointments' => Appointment::whereDate('scheduled_datetime', $today)
                ->with(['customer', 'vehicle'])
                ->orderBy('scheduled_datetime')
                ->get(),
            'pickups' => JobCard::where('status', 'completed')
                ->whereDate('expected_completion_date', $today)
                ->with(['customer', 'vehicle'])
                ->get(),
            'overdue' => JobCard::where('expected_completion_date', '<', now())
                ->whereNotIn('status', ['completed', 'delivered', 'cancelled'])
                ->with(['customer', 'vehicle'])
                ->limit(5)
                ->get(),
        ];

        return view('livewire.dashboard.daily-schedule', compact('schedule'));
    }
}
