<?php

namespace App\Modules\Admin\Tenancy\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Admin\Tenancy\Models\Module;
use App\Modules\Admin\Tenancy\Models\Plan;
use App\Modules\Admin\Tenancy\Models\Subscription;
use App\Modules\Admin\Tenancy\Models\Tenant;
use Illuminate\View\View;

class DashboardController extends Controller
{
    public function index(): View
    {
        $stats = [
            'modules' => Module::query()->count(),
            'plans' => Plan::query()->count(),
            'tenants' => Tenant::query()->count(),
            'active_subscriptions' => Subscription::query()->active()->count(),
        ];

        $latestTenants = Tenant::query()
            ->with('plan')
            ->latest()
            ->limit(5)
            ->get();

        return view('pages.admin.dashboard.index', [
            'stats' => $stats,
            'latestTenants' => $latestTenants,
        ]);
    }
}
