<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

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

    public function login(Request $request)
{
    $credentials = $request->validate([
        'email' => 'required|email',
        'password' => 'required',
    ]);

    if (Auth::guard('admin')->attempt($credentials, $request->remember)) {
        return redirect()->route('admin.dashboard');
    }

    // kalau gagal login → balik ke home + flag untuk buka modal
    return redirect('/')
        ->with('loginError', 'Email atau password salah')
        ->with('openModal', true);
}

    public function logout()
    {
        Auth::guard('admin')->logout();
        return redirect('/'); // langsung ke home
    }
}
