<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PageController;

Route::get('/', [PageController::class, 'home'])->name('home');
Route::get('/about', [PageController::class, 'about'])->name('about');
Route::get('/services', [PageController::class, 'services'])->name('services');
Route::get('/services/{slug}', [PageController::class, 'serviceDetail'])->name('service.detail');
Route::get('/why-laparoscopy', [PageController::class, 'whyLaparoscopy'])->name('why-laparoscopy');
Route::get('/contact', [PageController::class, 'contact'])->name('contact');
Route::post('/contact', [PageController::class, 'submitContact'])->name('contact.submit');
Route::get('/gallery', [PageController::class, 'gallery'])->name('gallery');
Route::post('/testimonials/submit', [PageController::class, 'submitTestimonial'])->name('testimonial.submit');
Route::get('/appointment', [PageController::class, 'appointment'])->name('appointment');
Route::post('/appointment', [PageController::class, 'submitAppointment'])->name('appointment.submit');
Route::get('/blogs', [\App\Http\Controllers\BlogController::class, 'index'])->name('blogs.index');
Route::get('/blogs/{slug}', [\App\Http\Controllers\BlogController::class, 'show'])->name('blogs.show');
// Auth Routes
Route::get('/login', [\App\Http\Controllers\AuthController::class, 'showLogin'])->name('login')->middleware('guest');
Route::post('/login', [\App\Http\Controllers\AuthController::class, 'login'])->middleware('guest');
Route::post('/logout', function (\Illuminate\Http\Request $request) {
    auth()->logout();
    $request->session()->invalidate();
    $request->session()->regenerateToken();
    return redirect()->route('login');
})->name('logout')->middleware('auth');

// Admin Routes
Route::get('/admin', function () {
    return redirect()->route('admin.dashboard');
});

Route::prefix('admin')->name('admin.')->middleware('auth')->group(function () {
    Route::get('/dashboard', [\App\Http\Controllers\Admin\DashboardController::class, 'index'])->name('dashboard');
    Route::post('/upload-image', [\App\Http\Controllers\Admin\ImageUploadController::class, 'upload'])->name('upload.image');
    Route::resource('gallery', \App\Http\Controllers\Admin\GalleryController::class);
    Route::resource('blogs', \App\Http\Controllers\Admin\BlogController::class);
    
    // Services
    Route::resource('services', \App\Http\Controllers\Admin\ServiceController::class);
    
    // Homepage Content
    Route::get('homepage', [\App\Http\Controllers\Admin\HomepageContentController::class, 'edit'])->name('homepage.edit');
    Route::post('homepage', [\App\Http\Controllers\Admin\HomepageContentController::class, 'update'])->name('homepage.update');

    // About Page Content
    Route::get('about-content', [\App\Http\Controllers\Admin\AboutContentController::class, 'edit'])->name('about.edit');
    Route::post('about-content', [\App\Http\Controllers\Admin\AboutContentController::class, 'update'])->name('about.update');

    // Testimonials & Features
    Route::resource('testimonials', \App\Http\Controllers\Admin\TestimonialController::class)->except(['show']);
    Route::resource('features', \App\Http\Controllers\Admin\FeatureController::class)->except(['show']);

    // Site Settings
    Route::get('settings', [\App\Http\Controllers\Admin\SiteSettingController::class, 'index'])->name('settings.index');
    Route::post('settings', [\App\Http\Controllers\Admin\SiteSettingController::class, 'update'])->name('settings.update');
    
    // Appointments
    Route::resource('appointments', \App\Http\Controllers\Admin\AppointmentController::class)->only(['index', 'show', 'update', 'destroy']);
    
    // Contact Messages
    Route::resource('messages', \App\Http\Controllers\Admin\ContactMessageController::class)->only(['index', 'show', 'destroy']);
    Route::post('messages/{message}/read', [\App\Http\Controllers\Admin\ContactMessageController::class, 'markAsRead'])->name('messages.read');
});
