<?php

namespace App\Components\Admin\Users;

use App\Models\User\User;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;

class ImpersonateUser extends Component {
    use AuthorizesRequests;
    public User $user;

    public function impersonate() {
        $this->authorize('impersonate', $this->user);

        session([
            'impersonator_id' => Auth::id(),
        ]);

        Auth::login($this->user);

        return redirect()->route('dashboard');
    }

    public function render() {
        return view('components.admin.users.impersonate-user');
    }
}
