<?php

use App\Http\Controllers\Admin\AdminCategoryController;
use App\Http\Controllers\Admin\AdminDashboardController;
use App\Http\Controllers\Admin\AdminFaqController;
use App\Http\Controllers\Admin\AdminHomePageController;
use App\Http\Controllers\Admin\AdminOrderController;
use App\Http\Controllers\Admin\AdminProductController;
use App\Http\Controllers\Admin\AdminProfileController;
use App\Http\Controllers\Admin\AdminSettingController;
use App\Http\Controllers\Admin\AdminSlideController;
use App\Http\Controllers\Admin\AdminSubcategoryController;
use App\Http\Controllers\Admin\AdminUserController;
use App\Http\Controllers\Admin\PageContentController;
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\UploadController;
use Illuminate\Support\Facades\Route;


// Admin Authentication Routes
Route::get('/admin/login', [AuthenticatedSessionController::class, 'create'])->middleware('guest')->name('admin.login');
Route::post('/admin/login', [AuthenticatedSessionController::class, 'store'])->middleware('guest');

// Protected Admin Routes
Route::middleware(['auth'])->prefix('admin')->name('admin.')->group(function () {
    Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])->name('logout');

    // Dashboard
    Route::get('/dashboard', [AdminDashboardController::class, 'index'])->name('dashboard');

    // Image Upload
    Route::post('/upload/image', [UploadController::class, 'upload'])->name('upload.image');

    // Profile (Current User)
    Route::get('/profile', [AdminProfileController::class, 'show'])->name('profile.show');
    Route::get('/profile/edit', [AdminProfileController::class, 'edit'])->name('profile.edit');
    Route::put('/profile', [AdminProfileController::class, 'update'])->name('profile.update');

    // Users
    Route::resource('users', AdminUserController::class);

    // Products
    Route::get('products/{product}/duplicate', [AdminProductController::class, 'duplicate'])->name('products.duplicate');
    Route::resource('products', AdminProductController::class);

    // Categories
    Route::resource('categories', AdminCategoryController::class);

    // Subcategories (Separate CRUD)
    Route::resource('subcategories', AdminSubcategoryController::class);

    // Slides
    Route::resource('slides', AdminSlideController::class);

    // FAQs
    Route::resource('faqs', AdminFaqController::class);

    // Orders
    Route::resource('orders', AdminOrderController::class);

    // Settings
    Route::get('/settings', [AdminSettingController::class, 'index'])->name('settings.index');
    Route::put('/settings', [AdminSettingController::class, 'update'])->name('settings.update');

    // Home Page Settings
    Route::get('/home-page', [AdminHomePageController::class, 'index'])->name('home-page.index');
    Route::post('/home-page/{section}', [AdminHomePageController::class, 'updateSection'])->name('home-page.update-section');
    Route::get('/home-page/{section}', [AdminHomePageController::class, 'getSection'])->name('home-page.get-section');
    Route::delete('/home-page/{section}/image', [AdminHomePageController::class, 'removeImage'])->name('home-page.remove-image');

    // Page Content Management
    Route::resource('page-content', PageContentController::class);
});

require __DIR__.'/auth.php';
