<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    // Hapus atau komentar $redirectTo karena akan pakai function

    // protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Arahkan user setelah login sesuai role
     *
     * @return string
     */
    protected function redirectTo()
    {
        if (auth()->user()->role == 'admin') {
            return '/admin/home';
        } elseif (auth()->user()->role == 'user') {
            return '/user/home';
        } else {
            return '/home';
        }
    }

    public function logout()
    {
        Auth::logout();
        return redirect('/');
    }
}
