<?php

namespace App\Http\Controllers\Landlord;

use App\Http\Controllers\Controller;
use App\Modules\Core\Models\Tenant;
use Inertia\Inertia;

class DashboardController extends Controller
{
    public function index()
    {
        $stats = [
            'totalTenants' => Tenant::count(),
            'activeTenants' => Tenant::whereJsonContains('data->is_active', true)->count(),
            'recentTenants' => Tenant::latest()->take(5)->get()->map(function ($tenant) {
                return [
                    'id' => $tenant->id,
                    'name' => $tenant->name ?? $tenant->id,
                    'is_active' => $tenant->is_active ?? true,
                    'created_at' => $tenant->created_at->format('Y-m-d H:i'),
                    'domains' => $tenant->domains->pluck('domain')->toArray(),
                ];
            }),
        ];

        return Inertia::render('Landlord/Dashboard', $stats);
    }
}
