<?php

use App\Http\Controllers\Admin\ArticleController as AdminArticleController;
use App\Http\Controllers\Admin\BrandController as AdminBrandController;
use App\Http\Controllers\Admin\CategoryController as AdminCategoryController;
use App\Http\Controllers\Admin\ContactController as AdminContactController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\DeviceInterfaceController as AdminDeviceInterfaceController;
use App\Http\Controllers\Admin\FaqController as AdminFaqController;
use App\Http\Controllers\Admin\FeatureController as AdminFeatureController;
use App\Http\Controllers\Admin\FlashSaleController as AdminFlashSaleController;
use App\Http\Controllers\Admin\HelpPageController as AdminHelpPageController;
use App\Http\Controllers\Admin\MenuController as AdminMenuController;
use App\Http\Controllers\Admin\OrderController as AdminOrderController;
use App\Http\Controllers\Admin\PageController as AdminPageController;
use App\Http\Controllers\Admin\ProductVersionController as AdminProductVersionController;
use App\Http\Controllers\Admin\SeoPageController as AdminSeoPageController;
use App\Http\Controllers\Admin\ModuleController as AdminModuleController;
use App\Http\Controllers\Admin\PaymentGatewayController as AdminPaymentGatewayController;
use App\Http\Controllers\Admin\PaymentMethodController as AdminPaymentMethodController;
use App\Http\Controllers\Admin\ProductController as AdminProductController;
use App\Http\Controllers\Admin\ServiceController as AdminServiceController;
use App\Http\Controllers\Admin\GooglePluginController as AdminGooglePluginController;
use App\Http\Controllers\Admin\HowItWorkController as AdminHowItWorkController;
use App\Http\Controllers\Admin\PaymentProcessController as AdminPaymentProcessController;
use App\Http\Controllers\Admin\PremiumFeatureController as AdminPremiumFeatureController;
use App\Http\Controllers\Admin\MediaController as AdminMediaController;
use App\Http\Controllers\Admin\SettingController;
use App\Http\Controllers\Admin\TopSellerController as AdminTopSellerController;
use App\Http\Controllers\Admin\SliderController as AdminSliderController;
use App\Http\Controllers\Admin\SubscriberController as AdminSubscriberController;
use App\Http\Controllers\Admin\TestimonialController as AdminTestimonialController;
use App\Http\Controllers\Admin\UpdateController as AdminUpdateController;
use App\Http\Controllers\Admin\UserController as AdminUserController;
use App\Http\Controllers\Admin\VideoPluginController as AdminVideoPluginController;
use App\Http\Controllers\Admin\WhatsAppPluginController as AdminWhatsAppPluginController;
use App\Http\Controllers\Front\CartController;
use App\Http\Controllers\Front\CheckoutController;
use App\Http\Controllers\Front\ContactController;
use App\Http\Controllers\Front\HomeController;
use App\Http\Controllers\Front\PageController;
use App\Http\Controllers\Front\ShopController;
use Illuminate\Support\Facades\Route;

Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/shop', [ShopController::class, 'index'])->name('shop');
Route::get('/shop/{category}', [ShopController::class, 'category'])->name('shop.category');
Route::get('/product/{slug}', [ShopController::class, 'show'])->name('product.show');
Route::get('/search', [ShopController::class, 'search'])->name('shop.search');
Route::get('/shop/brand/{brand}', [ShopController::class, 'brand'])->name('shop.brand');
Route::get('/shop/interface/{slug}', [ShopController::class, 'interface'])->name('shop.interface');
Route::get('/updates', [App\Http\Controllers\Front\UpdatesController::class, 'index'])->name('updates');
Route::post('/subscribe', [App\Http\Controllers\Front\SubscriptionController::class, 'store'])->name('subscribe');

Route::get('/cart', [CartController::class, 'index'])->name('cart');
Route::post('/cart/add', [CartController::class, 'add'])->name('cart.add');
Route::post('/cart/update', [CartController::class, 'update'])->name('cart.update');
Route::post('/cart/remove', [CartController::class, 'remove'])->name('cart.remove');

Route::get('/checkout', [CheckoutController::class, 'index'])->name('checkout');
Route::post('/checkout', [CheckoutController::class, 'store'])->name('checkout.store');
Route::get('/checkout/success/{order}', [CheckoutController::class, 'success'])->name('checkout.success');

Route::get('/contact', [ContactController::class, 'index'])->name('contact');
Route::post('/contact', [ContactController::class, 'store'])->name('contact.store');

Route::get('/page/{slug}', [PageController::class, 'show'])->name('page.show');

Route::middleware(['auth', 'verified'])->group(function () {
    Route::get('/dashboard', function () {
        return view('dashboard');
    })->name('dashboard');

    Route::get('/orders', [App\Http\Controllers\Front\OrderController::class, 'index'])->name('orders');
    Route::get('/orders/{order}', [App\Http\Controllers\Front\OrderController::class, 'show'])->name('orders.show');
});

Route::prefix('admin')->name('admin.')->middleware(['auth', 'admin'])->group(function () {
    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

    Route::resource('categories', AdminCategoryController::class);
    Route::resource('products', AdminProductController::class);
    Route::resource('products.versions', AdminProductVersionController::class);
    Route::resource('orders', AdminOrderController::class);
    Route::resource('pages', AdminPageController::class);
    Route::resource('testimonials', AdminTestimonialController::class);
    Route::resource('sliders', AdminSliderController::class);
    Route::resource('features', AdminFeatureController::class);
    Route::resource('services', AdminServiceController::class);
    Route::resource('flash-sales', AdminFlashSaleController::class);
    Route::resource('contacts', AdminContactController::class)->only(['index', 'show', 'destroy']);
    Route::resource('payment-methods', AdminPaymentMethodController::class);
    Route::get('payment-gateways', [AdminPaymentGatewayController::class, 'index'])->name('payment-gateways.index');
    Route::get('payment-gateways/install/{code}', [AdminPaymentGatewayController::class, 'install'])->name('payment-gateways.install');
    Route::get('payment-gateways/uninstall/{code}', [AdminPaymentGatewayController::class, 'uninstall'])->name('payment-gateways.uninstall');
    Route::get('payment-gateways/{paymentGateway}/toggle', [AdminPaymentGatewayController::class, 'toggle'])->name('payment-gateways.toggle');
    Route::get('payment-gateways/{paymentGateway}/edit', [AdminPaymentGatewayController::class, 'edit'])->name('payment-gateways.edit');
    Route::put('payment-gateways/{paymentGateway}', [AdminPaymentGatewayController::class, 'update'])->name('payment-gateways.update');
    Route::resource('seo-pages', AdminSeoPageController::class);
    Route::resource('users', AdminUserController::class);
    Route::resource('updates', AdminUpdateController::class);
    Route::resource('top-sellers', AdminTopSellerController::class);
    Route::resource('payment-processes', AdminPaymentProcessController::class);
    Route::resource('how-it-works', AdminHowItWorkController::class);
    Route::resource('premium-features', AdminPremiumFeatureController::class);
    Route::resource('media', AdminMediaController::class);
    Route::resource('brands', AdminBrandController::class);
    Route::resource('interfaces', AdminDeviceInterfaceController::class);
    Route::resource('articles', AdminArticleController::class);
    Route::resource('faqs', AdminFaqController::class);
    Route::resource('help-pages', AdminHelpPageController::class);
    Route::post('help-pages/import', [AdminHelpPageController::class, 'import'])->name('admin.help-pages.import');
    Route::post('pages/import', [AdminPageController::class, 'import'])->name('admin.pages.import');
    Route::resource('menus', AdminMenuController::class)->except(['show']);
    Route::resource('subscribers', AdminSubscriberController::class)->only(['index', 'destroy']);

    Route::get('modules', [AdminModuleController::class, 'index'])->name('modules.index');
    Route::get('modules/install/{code}', [AdminModuleController::class, 'install'])->name('modules.install');
    Route::get('modules/uninstall/{code}', [AdminModuleController::class, 'uninstall'])->name('modules.uninstall');
    Route::get('modules/toggle/{code}', [AdminModuleController::class, 'toggle'])->name('modules.toggle');
    Route::get('modules/refresh', [AdminModuleController::class, 'refresh'])->name('modules.refresh');

    Route::get('whatsapp-plugins', [AdminWhatsAppPluginController::class, 'index'])->name('whatsapp-plugins.index');
    Route::get('whatsapp-plugins/install/{code}', [AdminWhatsAppPluginController::class, 'install'])->name('whatsapp-plugins.install');
    Route::get('whatsapp-plugins/uninstall/{code}', [AdminWhatsAppPluginController::class, 'uninstall'])->name('whatsapp-plugins.uninstall');
    Route::get('whatsapp-plugins/{whatsappPlugin}/toggle', [AdminWhatsAppPluginController::class, 'toggle'])->name('whatsapp-plugins.toggle');
    Route::get('whatsapp-plugins/{whatsappPlugin}/edit', [AdminWhatsAppPluginController::class, 'edit'])->name('whatsapp-plugins.edit');
    Route::put('whatsapp-plugins/{whatsappPlugin}', [AdminWhatsAppPluginController::class, 'update'])->name('whatsapp-plugins.update');

    Route::get('google-plugins', [AdminGooglePluginController::class, 'index'])->name('google-plugins.index');
    Route::get('google-plugins/install/{code}', [AdminGooglePluginController::class, 'install'])->name('google-plugins.install');
    Route::get('google-plugins/uninstall/{code}', [AdminGooglePluginController::class, 'uninstall'])->name('google-plugins.uninstall');
    Route::get('google-plugins/{googlePlugin}/toggle', [AdminGooglePluginController::class, 'toggle'])->name('google-plugins.toggle');
    Route::get('google-plugins/{googlePlugin}/edit', [AdminGooglePluginController::class, 'edit'])->name('google-plugins.edit');
    Route::put('google-plugins/{googlePlugin}', [AdminGooglePluginController::class, 'update'])->name('google-plugins.update');

    Route::get('video-plugins', [AdminVideoPluginController::class, 'index'])->name('video-plugins.index');
    Route::get('video-plugins/install/{code}', [AdminVideoPluginController::class, 'install'])->name('video-plugins.install');
    Route::get('video-plugins/uninstall/{code}', [AdminVideoPluginController::class, 'uninstall'])->name('video-plugins.uninstall');
    Route::get('video-plugins/{videoPlugin}/toggle', [AdminVideoPluginController::class, 'toggle'])->name('video-plugins.toggle');
    Route::get('video-plugins/{videoPlugin}/edit', [AdminVideoPluginController::class, 'edit'])->name('video-plugins.edit');
    Route::put('video-plugins/{videoPlugin}', [AdminVideoPluginController::class, 'update'])->name('video-plugins.update');

    Route::get('themes', [App\Http\Controllers\Admin\ThemeController::class, 'index'])->name('themes.index');
    Route::get('themes/create', [App\Http\Controllers\Admin\ThemeController::class, 'create'])->name('themes.create');
    Route::post('themes', [App\Http\Controllers\Admin\ThemeController::class, 'store'])->name('themes.store');
    Route::get('themes/{theme}/edit', [App\Http\Controllers\Admin\ThemeController::class, 'edit'])->name('themes.edit');
    Route::put('themes/{theme}', [App\Http\Controllers\Admin\ThemeController::class, 'update'])->name('themes.update');
    Route::get('themes/{theme}/activate', [App\Http\Controllers\Admin\ThemeController::class, 'activate'])->name('themes.activate');
    Route::delete('themes/{theme}', [App\Http\Controllers\Admin\ThemeController::class, 'destroy'])->name('themes.destroy');
    Route::get('themes/install-mecaprograms', [App\Http\Controllers\Admin\ThemeController::class, 'installFromMecaprograms'])->name('themes.install-mecaprograms');

    Route::get('/settings', [SettingController::class, 'index'])->name('settings');
    Route::post('/settings', [SettingController::class, 'update'])->name('settings.update');

    Route::post('/products/{product}/images', [AdminProductController::class, 'uploadImage'])->name('products.images.upload');
    Route::delete('/products/{product}/images/{image}', [AdminProductController::class, 'deleteImage'])->name('products.images.destroy');
});

require __DIR__.'/auth.php';
