<?php

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

// ============ Storefront Pages ============
Route::get('/',             [PageController::class, 'home'])->name('home');
Route::get('/shop',         [PageController::class, 'shop'])->name('shop');
Route::get('/product/{id}', [PageController::class, 'productDetails'])->name('product.details');
Route::get('/specials',     [PageController::class, 'specials'])->name('specials');
Route::get('/cart',         [PageController::class, 'cart'])->name('cart');
Route::get('/checkout',     [PageController::class, 'checkout'])->name('checkout');
Route::get('/about',        [PageController::class, 'about'])->name('about');
Route::get('/contact',      [PageController::class, 'contact'])->name('contact');
Route::get('/blog',         [PageController::class, 'blog'])->name('blog');
Route::get('/brands',       [PageController::class, 'brands'])->name('brands');
Route::get('/site-map',     [PageController::class, 'sitemap'])->name('sitemap');

// ============ Auth (Guest) ============
Route::middleware('guest')->group(function () {
    Route::get('/auth',     [AuthController::class, 'showAuth'])->name('auth');
    Route::post('/login',   [AuthController::class, 'login'])->name('login');
    Route::post('/register',[AuthController::class, 'register'])->name('register');
});

// ============ Auth (Protected) ============
Route::middleware('auth')->group(function () {
    Route::get('/dashboard', [PageController::class, 'dashboard'])->name('dashboard');
    Route::post('/logout',   [AuthController::class, 'logout'])->name('logout');
});

// ============ Admin Dashboard (Protected) ============
Route::middleware(['auth', 'is_admin'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/', [\App\Http\Controllers\AdminController::class, 'dashboard'])->name('dashboard');
    Route::resource('products', \App\Http\Controllers\Admin\AdminProductController::class);
    
    // Settings
    Route::get('/settings', [\App\Http\Controllers\Admin\SettingController::class, 'index'])->name('settings');
    Route::post('/settings', [\App\Http\Controllers\Admin\SettingController::class, 'update'])->name('settings.update');
});
