<?php

namespace App\Http\Controllers;

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

class SecurityAuthController extends Controller
{
    public function showLoginForm()
    {
        return view('auth.security-login'); // pastikan ada di resources/views/auth/security-login.blade.php
    }

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

        if (Auth::guard('security')->attempt($credentials)) {
            $request->session()->regenerate();

            // Arahkan langsung ke index security
            return redirect()->route('izin_tamu.index_security');
        }

        return back()->withErrors([
            'username' => 'Username atau password salah.',
        ]);
    }

    public function logout(Request $request)
    {
        Auth::guard('security')->logout();
        $request->session()->invalidate();
        $request->session()->regenerateToken();

        return redirect()->route('security.login');
    }
}
