<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\AdminUser;

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

    public function login(Request $request) {
        $admin = AdminUser::where('username', $request->username)
            ->where('password', $request->password)
            ->first();

        if (!$admin) {
            return back()->with('error', 'Invalid credentials');
        }

        session(['admin_id' => $admin->id]);
        return redirect('/admin/dashboard');
    }

    public function logout() {
        session()->forget('admin_id');
        return redirect('/admin/login');
    }
}
