<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class AuthController extends Controller
{
    public function showLoginForm()
    {
        return view('auth.login');
    }

    public function login(Request $request)
{
    $credentials = $request->only(['nomorinduk', 'password']);

    if (Auth::attempt($credentials)) {
        $user = Auth::user();

        if ($user->role === 'wakil_kepala') {
            return redirect()->intended('/wakil_kepala/dashboard');
        } elseif ($user->role === 'siswa') {
            return redirect()->intended('/siswa/dashboard');
        }
    }

    return redirect('/login')->with('error', 'Login gagal. Periksa kembali NIS/NIP dan password Anda.');
    }
}
