<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\PrescriptionController;
use App\Http\Controllers\PatientController;

// Public routes
Route::get('/', function () {
    return view('auth.login');
})->name('home');

// Authentication routes
Route::get('/', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('/', [AuthController::class, 'login']);
Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('/login', [AuthController::class, 'login'])->name('login.process');
Route::get('/register', [AuthController::class, 'showRegisterForm'])->name('register');
Route::post('/register', [AuthController::class, 'register'])->name('register.process');
Route::get('/forgot-pw', [AuthController::class, 'showForgotForm'])->name('password.request');
Route::post('/forgot-pw', [AuthController::class, 'sendResetLink'])->name('password.email');

// Protected routes (require authentication)
Route::middleware(['auth'])->group(function () {
    // Dashboard
    Route::get('/dashboard', function () {
        return view('dashboard');
    })->name('dashboard');
    
    // Prescription routes
    Route::get('/prescription/new', [PrescriptionController::class, 'create'])->name('prescription.create');
    Route::post('/prescription', [PrescriptionController::class, 'store'])->name('prescription.store');
    Route::get('/prescription/{id}', [PrescriptionController::class, 'show'])->name('prescription.show');
    Route::get('/prescription/{id}/print', [PrescriptionController::class, 'print'])->name('prescription.print');
    
    // Patient routes
    Route::get('/patients/search', [PatientController::class, 'search'])->name('patients.search');
    Route::resource('patients', PatientController::class);
});

// Logout
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');