<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\LoginController;
use App\Http\Controllers\Admin\SalesController;
use App\Http\Controllers\Admin\CustomerController;
use App\Http\Controllers\Admin\OrderController;
use App\Http\Controllers\Admin\ProductController;
use App\Http\Controllers\Admin\FrontendController;
use App\Http\Controllers\Frontend\AboutController;
use App\Http\Controllers\Frontend\ServiceController;
use App\Http\Controllers\Frontend\PortfolioController;
use App\Http\Controllers\Frontend\OurproductsController;
use App\Http\Controllers\Frontend\GalleryController;
use App\Http\Controllers\Frontend\ContactController;
use App\Http\Controllers\Frontend\HomeController;


Route::get('/', [HomeController::class, 'index'])->name('home');


Route::get('/about', [AboutController::class, 'index'])->name('about');
Route::get('/services', [ServiceController::class, 'index'])->name('services');
Route::get('/portfolio', [PortfolioController::class, 'index'])->name('portfolio');
Route::get('/products', [OurproductsController::class, 'index'])->name('products');
Route::get('/gallery',[GalleryController::class,'frontendGallery'])->name('gallery');
Route::get('/contact', [ContactController::class, 'index'])->name('contact');
Route::get('/feedback', [ContactController::class, 'feedback'])->name('feedback');
Route::post('/feedback-store', [ContactController::class, 'store'])->name('feedback.store');

Route::prefix('admin')->name('admin.')->group(function () {
    // Only guests can access login page
    Route::middleware('guest:admin')->group(function () {
        Route::get('/', [LoginController::class, 'showLoginForm'])->name('login');
        Route::post('/', [LoginController::class, 'login'])->name('login.submit');
    });

    // Only authenticated admins can access dashboard and logout
    Route::middleware('auth:admin')->group(function () {
        Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
        Route::post('/logout', [LoginController::class, 'logout'])->name('logout');


        Route::get('/new-sale', [SalesController::class,'newsale'])->name('new-sale');
        Route::post('/sale-store', [SalesController::class, 'store'])->name('sales.store');

        Route::get('/add-customer', [CustomerController::class,'customer-index'])->name('customer.add');
        Route::get('/customers/search', [CustomerController::class, 'search'])->name('customers.search');
        Route::get('/customers/list', [CustomerController::class, 'customer_list'])->name('customers.list');
        Route::get('/customers/add', [CustomerController::class, 'add_customer'])->name('customers.add');
        Route::post('/customers/add', [CustomerController::class, 'add_new_customer'])->name('customers.add-new');
        Route::get('/customer/{id}/update', [CustomerController::class, 'customer_update'])->name('customers.update');
        Route::post('/customers/{id}/update', [CustomerController::class, 'update_customer'])->name('customers.update_customer');
        Route::get('/customer/{id}/bills', [CustomerController::class, 'customer_records'])->name('customers.bills');
        Route::get('/customer/order/{id}/detail', [CustomerController::class, 'order_detail'])->name('customers.Order.detail');

        Route::get('/products/search', [ProductController::class, 'search'])->name('products.search');
        Route::get('/products/list', [ProductController::class, 'list'])->name('products.list');
        Route::get('/product/add', [ProductController::class, 'add'])->name('product.add');
        Route::post('/product/store', [ProductController::class, 'store'])->name('product.store');
        Route::put('/product/{id}/unactive', [ProductController::class, 'unactive'])->name('product.unactive');
        Route::put('/product/{id}/active', [ProductController::class, 'active'])->name('product.active');
        Route::put('/product/{id}/remove', [ProductController::class, 'remove'])->name('product.remove');
        Route::get('/product/{id}/update', [ProductController::class, 'update_product'])->name('product.update');
        Route::post('/product/{id}/updates', [ProductController::class, 'product_update'])->name('updateproduct');


         Route::get('/order/pending', [OrderController::class, 'pending_order'])->name('order.pending');
         Route::get('/order/deleverd', [OrderController::class, 'deleverd_order'])->name('order.deleverd');
         Route::get('/order/all', [OrderController::class, 'all_order'])->name('order.all');
         Route::get('/order/{id}/detail', [OrderController::class, 'order_detail'])->name('Order.detail');
         Route::get('/order/{id}/update', [OrderController::class, 'order_update'])->name('Order.update');
         Route::post('/order/{order}/update', [OrderController::class, 'updated_order'])->name('orders.update');
         Route::put('/orders/{id}/delivered', [OrderController::class, 'delivered'])->name('order.delivered');
         Route::put('/orders/{id}/paid', [OrderController::class, 'paid'])->name('order.paid');
         Route::get('/order/food', [OrderController::class, 'food_order'])->name('order.food');
         Route::get('/orders/{id}/invoice', [OrderController::class, 'invoice'])->name('order.invoice');
         Route::get('/orders/{id}/invoiceurdu', [OrderController::class, 'invoice_urdu'])->name('order.invoiceurdu');


         Route::get('/setting/products', [FrontendController::class, 'products'])->name('setting.products');
         Route::get('/setting/gallery', [FrontendController::class, 'gallery'])->name('setting.gallery');
         Route::get('/setting/feedback', [FrontendController::class, 'feedback'])->name('setting.feedback');
         
         Route::put('/feedback/{id}/publish', [FrontendController::class, 'feedback_publish'])->name('feedback.pulish');
         Route::put('/feedback/{id}/un-publish', [FrontendController::class, 'feedback_unpublish'])->name('feedback.unpublish');
         
         
         
         Route::get('/gallery/new', [FrontendController::class, 'createnewgallery'])->name('gallery.new');
         Route::post('/gallery/store', [FrontendController::class, 'gallerystore'])->name('gallery.store');
         Route::get('/gallery/{id}/update', [FrontendController::class, 'update_gallery'])->name('gallery.update');
         Route::put('/gallery/{id}/updates', [FrontendController::class, 'gallery_update'])->name('updategallery');
         Route::put('/gallery/{id}/publish', [FrontendController::class, 'gallery_publish'])->name('gallery.pulish');
         Route::put('/gallery/{id}/un-publish', [FrontendController::class, 'gallery_unpublish'])->name('gallery.unpublish');
         
         
         Route::get('/product/new', [FrontendController::class, 'createnewproducts'])->name('product.new');
         Route::post('/product/store', [FrontendController::class, 'productsstore'])->name('product.store');
         Route::get('/product/{id}/update', [FrontendController::class, 'update_products'])->name('product.update');
         Route::put('/product/{id}/updates', [FrontendController::class, 'products_update'])->name('updateproduct');
         Route::put('/product/{id}/publish', [FrontendController::class, 'products_publish'])->name('product.pulish');
         Route::put('/product/{id}/un-publish', [FrontendController::class, 'product_unpublish'])->name('product.unpublish');

    });

});
