<?php

namespace App\Components\Admin\Users;

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

class ImpersonateUser extends Component {
    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');
    }
}
