<?php

use App\Http\Controllers\homeController;
use App\Http\Controllers\CartController;
use App\Http\Controllers\loginController;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\ProdukController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

// Halaman Utama & Autentikasi
Route::get('/', [homeController::class, 'welcome'])->name('welcome');

Route::get('/login', [loginController::class, 'index'])->name('login');
Route::post('/login-proses', [loginController::class, 'login_proses'])->name('login-proses');
Route::get('/logout', [loginController::class, 'logout'])->name('logout');


Route::get('/register', [loginController::class, 'register'])->name('register');
Route::post('/register-proses', [loginController::class, 'register_proses'])->name('register-proses');

Route::resource('products', ProdukController::class);



// Fitur Keranjang & Checkout (khusus user biasa)
Route::middleware(['isUser'])->group(function () {
    Route::get('/cart', [CartController::class, 'index'])->name('cart.index');
    Route::post('/cart/add', [CartController::class, 'add'])->name('cart.add');
    Route::post('/cart/remove', [CartController::class, 'remove'])->name('cart.remove');
    Route::post('/cart/clear', [CartController::class, 'clear'])->name('cart.clear');
    Route::post('/checkout', [CheckoutController::class, 'store'])->name('checkout.store');
});

// Group route untuk admin yang butuh autentikasi
Route::group(['prefix' => 'admin', 'middleware' => ['auth'], 'as' => 'admin.'], function () {
    Route::get('/dashboard', [homeController::class, 'dashboard'])->name('dashboard');
    Route::get('/user', [homeController::class, 'index'])->name('index');
    Route::get('/create', [homeController::class, 'create'])->name('user.create');
    Route::post('/store', [homeController::class, 'store'])->name('user.store');
    Route::get('/edit/{id}', [homeController::class, 'edit'])->name('useredit');
    Route::put('/update/{id}', [homeController::class, 'update'])->name('user.update');
    Route::delete('/delete/{id}', [homeController::class, 'delete'])->name('user.delete');
    //produk
    Route::get('/produk', [ProdukController::class, 'index'])->name('produk_index');
    Route::get('/createProduk', [ProdukController::class, 'create'])->name('produk_create');
    Route::post('/storeProduk', [ProdukController::class, 'store'])->name('produkstore');
    Route::get('/edit/{id}', [ProdukController::class, 'edit'])->name('produkedit');
    Route::put('/update/{id}', [ProdukController::class, 'update'])->name('produkupdate');
    Route::delete('/delete/{id}', [ProdukController::class, 'destroy'])->name('produkdelete');
    Route::get('/testimoni', [homeController::class, 'testimoni'])->name('testimoni');
    Route::delete('/admin/user/delete/{id}', [Produkcontroller::class, 'destroy'])->name('user.delete');
});
