<?php

namespace App\Livewire\CustomerPortal;

use App\Models\JobCard;
use App\Services\WorkflowService;
use Livewire\Component;

class JobStatus extends Component
{
    public JobCard $jobCard;
    public $workflowProgress;

    public function mount(JobCard $jobCard)
    {
        $this->jobCard = $jobCard->load([
            'customer',
            'vehicle',
            'serviceAdvisor',
            'vehicleInspections',
            'diagnoses',
            'estimates',
            'workOrders.tasks',
            'timesheets'
        ]);

        $workflowService = app(WorkflowService::class);
        $this->workflowProgress = $workflowService->getWorkflowProgress($this->jobCard);
    }

    public function refreshStatus()
    {
        $this->jobCard->refresh();
        $workflowService = app(WorkflowService::class);
        $this->workflowProgress = $workflowService->getWorkflowProgress($this->jobCard);
        
        session()->flash('message', 'Status updated!');
    }

    public function render()
    {
        return view('livewire.customer-portal.job-status');
    }
}
