<?php

use App\Http\Controllers\Backend\DashboardController;
use App\Http\Controllers\Backend\MenuController;
use App\Http\Controllers\Backend\ProductController;
use App\Http\Controllers\Backend\SettingController;
use App\Http\Controllers\Backend\SliderController;
use App\Http\Controllers\Backend\StoreLocationController;
use App\Http\Controllers\Frontend\FaqController;
use App\Http\Controllers\Frontend\MessageController;
use App\Http\Controllers\Frontend\OrderController;
use App\Http\Controllers\Backend\HomeSectionController;
use App\Http\Controllers\Backend\ProductCategoryController; // ✅ NEW
use Illuminate\Support\Facades\Route;

Route::group(['middleware' => ['auth','role:admin'],'prefix' => 'admin', 'as' => 'admin.'], function(){

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

    // Orders
    Route::get('order-all', [OrderController::class, 'index'])->name('order-all');
    Route::get('order-details/{id}', [OrderController::class, 'details'])->name('order-details');
    Route::put('order-update/{id}', [OrderController::class, 'updateStatus'])->name('order-update');
    Route::delete('order-delete/{id}', [OrderController::class, 'destroy'])->name('order-delete');

    // Product & Store Location
    Route::resources([
        'product'        => ProductController::class,
        'store-location' => StoreLocationController::class,
    ]);

    // ✅ Product Multi Category mapping routes
    Route::get('product/{id}/categories',  [ProductCategoryController::class, 'manageCategories'])->name('product.categories');
    Route::post('product/{id}/categories', [ProductCategoryController::class, 'updateCategories'])->name('product.categories.update');

    // Menu (category & subcategory)
    Route::get('menu-index',[MenuController::class, 'index'])->name('menu-item.index');
    Route::get('menu-create',[MenuController::class, 'create'])->name('menu-item.create');
    Route::post('menu-store',[MenuController::class, 'store'])->name('menu-item.store');
    Route::get('menu-edit/{id}',[MenuController::class, 'edit'])->name('menu-item.edit');
    Route::put('menu-update/{id}',[MenuController::class, 'update'])->name('menu-item-update');
    Route::delete('menu-delete/{id}',[MenuController::class, 'destroy'])->name('menu-item-delete');

    // Submenu
    Route::get('submenu-index',[MenuController::class,'subindex'])->name('submenu');
    Route::get('submenu-edit/{id}',[MenuController::class,'subedit'])->name('edit-submenu');
    Route::put('submenu-update/{id}',[MenuController::class,'subUpdate'])->name('submenu-update');
    Route::delete('submenu-delete/{id}',[MenuController::class,'subDestroy'])->name('submenu-delete');

    // Slider
    Route::get('all-slider',[SliderController::class,'index'])->name('slider.index');
    Route::get('create-slider',[SliderController::class,'create'])->name('create-slider');
    Route::post('slider-store',[SliderController::class,'store'])->name('slider.store');
    Route::get('slider-edit/{id}',[SliderController::class,'edit'])->name('slider.edit');
    Route::put('slider-update/{id}',[SliderController::class,'update'])->name('slider.update');
    Route::delete('slider-destroy/{id}',[SliderController::class,'destroy'])->name('slider.destroy');

    // ✅ Home Sections (Homepage dynamic blocks)
    Route::get('home-section',           [HomeSectionController::class, 'index'])->name('home-section.index');
    Route::get('home-section/create',    [HomeSectionController::class, 'create'])->name('home-section.create');
    Route::post('home-section/store',    [HomeSectionController::class, 'store'])->name('home-section.store');
    Route::get('home-section/{id}/edit', [HomeSectionController::class, 'edit'])->name('home-section.edit');
    Route::put('home-section/{id}',      [HomeSectionController::class, 'update'])->name('home-section.update');
    Route::delete('home-section/{id}',   [HomeSectionController::class, 'destroy'])->name('home-section.destroy');

    // Home Section products
    Route::get('home-section/{id}/products',  [HomeSectionController::class, 'manageProducts'])->name('home-section.products');
    Route::post('home-section/{id}/products', [HomeSectionController::class, 'updateProducts'])->name('home-section.products.update');

    // Setting
    Route::post('setting', [SettingController::class, 'updateSetting'])->name('setting');
    Route::get('app-setting',[SettingController::class, 'appSetting'])->name('app-setting');

    // Messages
    Route::get('all-message', [MessageController::class, 'index'])->name('message');
    Route::delete('message-destroy/{id}', [MessageController::class, 'destroy'])->name('message.destroy');

    // FAQ
    Route::get('all-faq',[FaqController::class, 'index'])->name('all-faq');
    Route::get('create-faq',[FaqController::class, 'create'])->name('create-faq');
    Route::post('faq-store',[FaqController::class,'store'])->name('faq.store');
    Route::get('faq-edit/{id}',[FaqController::class,'edit'])->name('faq.edit');
    Route::put('faq-update/{id}',[FaqController::class,'update'])->name('faq.update');
    Route::delete('faq-destroy/{id}',[FaqController::class,'destroy'])->name('faq.destroy');

    // Footer pages
    Route::get('create-about-us',[SettingController::class, 'aboutUs'])->name('create-about-us');
    Route::get('delivery-policy',[SettingController::class, 'deliveryPolict'])->name('create-delivery-policy');
    Route::get('create-terms-condition',[SettingController::class, 'termsCondition'])->name('create-terms-condition');
    Route::get('create-payment-policy',[SettingController::class, 'paymentPolicy'])->name('create-payment-policy');
    Route::get('create-privacy-policy',[SettingController::class, 'privacyPolicy'])->name('create-privacy-policy');
    Route::get('create-exchange-return',[SettingController::class, 'exchangeReturn'])->name('create-exchange-return');
    Route::get('create-size-guide',[SettingController::class, 'size'])->name('create-size-guide');
    Route::get('create-loyality-program',[SettingController::class, 'loyalityProgram'])->name('create-loyality-program');
});
