<?php

namespace App\Livewire;

use App\Models\User;
use App\Services\FinanceRepository;
use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('layouts.app')]
class AdminUserProfilePage extends Component
{
    public User $user;

    public function mount(User $user): void
    {
        $this->user = $user;
    }

    public function render()
    {
        $finance = app(FinanceRepository::class);
        $transactionsCount = $this->user->transactions()->count();
        $budgetsCount = $this->user->budgets()->count();
        $goalsCount = $this->user->goals()->count();
        $debtsCount = $this->user->debts()->count();
        $subscriptionsCount = $this->user->subscriptions()->count();

        return view('livewire.admin-user-profile-page', [
            'transactionsCount' => $transactionsCount,
            'budgetsCount' => $budgetsCount,
            'goalsCount' => $goalsCount,
            'debtsCount' => $debtsCount,
            'subscriptionsCount' => $subscriptionsCount,
            'hasPremium' => $this->user->activeSaasSubscription()->exists(),
            'recentUsers' => collect($finance->users())->take(5)->all(),
        ])->title($this->user->name.' · '.(string) __('budgets.users_page.profile_title_suffix'));
    }
}
