<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Admin\MenuController;

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

// Auth Routes
Route::controller(LoginController::class)->group(function() {
    Route::get('/login', 'showLoginForm')->name('login.form');
    Route::post('/login', 'login')->name('login');
    Route::post('/logout', 'logout')->name('logout');
});

// Protected Admin Routes (Menu Management Only)
Route::middleware('auth')->prefix('admin')->name('admin.')->group(function () {
    // Dashboard
    Route::get('/dashboard', [MenuController::class, 'dashboard'])->name('dashboard');
    
    // Menu Categories
    Route::get('/categories', [MenuController::class, 'categories'])->name('categories');
    Route::post('/categories', [MenuController::class, 'storeCategory'])->name('categories.store');
    Route::get('/categories/{id}/edit', [MenuController::class, 'editCategory'])->name('categories.edit');
    Route::put('/categories/{id}', [MenuController::class, 'updateCategory'])->name('categories.update');
    Route::delete('/categories/{id}', [MenuController::class, 'deleteCategory'])->name('categories.delete');
    
    // ROUTE TAMBAHAN
    Route::get('/categories/{id}/duplicate', [MenuController::class, 'duplicateCategory'])
        ->name('categories.duplicate');
    
    // ROUTE UNTUK HAPUS FOTO SAJA
    Route::delete('/categories/{id}/image', [MenuController::class, 'deleteImage'])
        ->name('categories.image.delete');
    
    Route::post('/categories/{id}/toggle', [MenuController::class, 'toggleCategory'])
        ->name('categories.toggle');
    
    Route::post('/categories/{id}/update-order', [MenuController::class, 'updateOrder'])
        ->name('categories.update-order');
    
    // Menu Items
    Route::get('/categories/{categoryId}/items', [MenuController::class, 'items'])->name('categories.items');
    Route::post('/categories/{categoryId}/items', [MenuController::class, 'storeItem'])->name('items.store');
    Route::get('/items/{id}/edit', [MenuController::class, 'editItem'])->name('items.edit');
    Route::put('/items/{id}', [MenuController::class, 'updateItem'])->name('items.update');
    Route::delete('/items/{id}', [MenuController::class, 'deleteItem'])->name('items.delete');
    
    // ✅ TAMBAHKAN ROUTE INI UNTUK TOGGLE MENU ITEM
    Route::post('/items/{id}/toggle', [MenuController::class, 'toggleItem'])->name('items.toggle');
});