<?php

namespace App\Http\Controllers;

use App\Models\Category;
use App\Models\InventoryItem;
use App\Models\Room;
use App\Models\ScanActivity;

class ReportController extends Controller
{
    public function index()
    {
        $summary = [
            'total_items' => InventoryItem::count(),
            'total_rooms' => Room::count(),
            'good' => InventoryItem::where('status_barang', 'good')->count(),
            'maintenance' => InventoryItem::where('status_barang', 'maintenance')->count(),
            'broken' => InventoryItem::where('status_barang', 'broken')->count(),
            'replace' => InventoryItem::where('status_barang', 'replace')->count(),
            'scan_today' => ScanActivity::whereDate('dipindai_pada', today())->count(),
        ];

        $categories = Category::withCount('inventoryItems')->orderBy('nama_kategori')->get();
        $rooms = Room::withCount('inventoryItems')->orderByDesc('inventory_items_count')->get();
        $latestScans = ScanActivity::with(['room', 'inventoryItem'])->latest('dipindai_pada')->limit(10)->get();

        return view('reports.index', compact('summary', 'categories', 'rooms', 'latestScans'));
    }
}
