<?php

use Illuminate\Support\Facades\Route;

// AUTH
use App\Http\Controllers\AuthController;
use App\Http\Controllers\User\UserController;

// ADMIN
use App\Http\Controllers\Admin\PizzaController;
use App\Http\Controllers\Admin\OrderController as AdminOrderController;
use App\Http\Controllers\Admin\DashboardController;

// USER
use App\Http\Controllers\User\PizzaController as UserPizzaController;
use App\Http\Controllers\User\OrderController;
use App\Http\Controllers\User\PaymentController;
use App\Http\Controllers\User\MenuController;
use App\Http\Controllers\User\CartController;

/*
|--------------------------------------------------------------------------
| HALAMAN UTAMA
|--------------------------------------------------------------------------
*/
Route::get('/', function () {
    return view('page');
});

/*
|--------------------------------------------------------------------------
| LOGIN GLOBAL
|--------------------------------------------------------------------------
*/
Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('/login', [AuthController::class, 'login']);
Route::get('/logout', [AuthController::class, 'logout'])->name('logout');

/*
|--------------------------------------------------------------------------
| LOGIN USER
|--------------------------------------------------------------------------
*/
Route::get('/user/login', [UserController::class, 'showLogin'])->name('user.login');
Route::post('/user/login', [UserController::class, 'login']);

/*
|--------------------------------------------------------------------------
| ADMIN PANEL
|--------------------------------------------------------------------------
*/
Route::prefix('admin')
    ->middleware('auth')
    ->name('admin.')
    ->group(function () {

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

        // CRUD Pizza
        Route::resource('pizzas', PizzaController::class);

        // ORDER ADMIN
        Route::get('/orders', [AdminOrderController::class, 'index'])->name('orders.index');
        Route::get('/orders/{order}', [AdminOrderController::class, 'show'])->name('orders.show');
        Route::post('/orders/{id}/update', [AdminOrderController::class, 'updateStatus'])->name('orders.update');
        Route::delete('/orders/{id}', [AdminOrderController::class, 'destroy'])->name('orders.destroy');
    });

/*
|--------------------------------------------------------------------------
| USER ROUTES
|--------------------------------------------------------------------------
*/
Route::prefix('user')
    ->middleware('auth')
    ->name('user.')
    ->group(function () {

        // Dashboard
        Route::get('/dashboard', function () {
            return view('user.dashboard');
        })->name('dashboard');

        // LIST ORDER USER
        Route::get('/orders', [OrderController::class, 'index'])->name('orders.index');

        // DELETE ORDER USER
        Route::delete('/orders/{id}', [OrderController::class, 'deleteOrder'])->name('order.delete');

        // MENU
        Route::get('/menu', [MenuController::class, 'index'])->name('menu');
        Route::get('/pizzas', [UserPizzaController::class, 'index'])->name('pizzas.index');

        // CART
        Route::get('/cart', [CartController::class, 'index'])->name('cart.index');
        Route::post('/cart/add/{id}', [CartController::class, 'add'])->name('cart.add');
        Route::delete('/cart/delete/{id}', [CartController::class, 'delete'])->name('cart.delete');

        // CHECKOUT
        Route::get('/checkout', [CartController::class, 'showCheckout'])->name('checkout');
        Route::post('/checkout/process', [CartController::class, 'processCheckout'])->name('checkout.process');

        // QRIS
        Route::get('/qris/{id}', [PaymentController::class, 'show'])->name('qris');
        Route::post('/qris/{id}/confirm', [PaymentController::class, 'confirm'])->name('qris.confirm');
    });
