<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Models\TimeLog;
use Illuminate\Http\Request;
use Illuminate\View\View;

class LiveTrackingController extends Controller
{
    public function index(): View
    {
        $onlineEmployees = User::with(['employeeProfile', 'roles'])
            ->where('status', 'active')
            ->get()
            ->map(function($user) {
                $user->current_timer = TimeLog::with('task')
                    ->where('user_id', $user->id)
                    ->where('status', 'running')
                    ->first();
                return $user;
            });

        return view('admin.live-tracking.index', [
            'employees' => $onlineEmployees,
        ]);
    }
}
