<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Log;

use App\Livewire\Settings\Appearance;
use App\Livewire\Settings\Password;
use App\Livewire\Settings\Profile;
use App\Livewire\FoodOrder;
use App\Livewire\SelectTable;
use App\Livewire\KitchenOrders;
use App\Livewire\Tables;
use App\Livewire\MidtransPayment;
use App\Http\Controllers\TypeItemsController;
use App\Http\Controllers\ItemsController;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\PaymentController;
use Midtrans\Config;
use Midtrans\Snap;

Route::get('/refresh-csrf', function () {
    return response()->json(['csrf_token' => csrf_token()]);
});

// Route::get('/', FoodOrder::class)->name('menu.all');
Route::get('/', function () {
    return redirect()->route('menu.byType', ['typeSlug' => 'makanan']);
})->name('home');
Route::get('/menu', function () {
    return redirect()->route('menu.byType', ['typeSlug' => 'makanan']);
});
Route::get('/menu/{typeSlug?}', FoodOrder::class)->name('menu.byType');
Route::get('/pilih-meja', SelectTable::class)->name('select.table');

Route::get('/payment/{midtrans_transaction_id}', MidtransPayment::class)->name('midtrans.payment');

// Routes untuk hasil pembayaran (bisa pakai Controller biasa untuk hasil akhir)
// Route::get('/payment/success', [PaymentController::class, 'success'])->name('payment.success');
// Route::get('/payment/pending', [PaymentController::class, 'pending'])->name('payment.pending');
// Route::get('/payment/error', [PaymentController::class, 'error'])->name('payment.error');

Route::get('/payment/success/{order_id}', [PaymentController::class, 'success'])->name('payment.success');


// Route untuk webhook Midtrans (penting!)
Route::post('/payment/notification', [PaymentController::class, 'notification'])->name('payment.notification');

Route::post('/order/update-status', [OrderController::class, 'confirmOrder'])->name('order.confirm');
Route::put('/payment/update-status', [PaymentController::class, 'updateStatus']);


Route::view('dashboard', 'dashboard')->middleware(['auth', 'verified'])->name('dashboard');

Route::middleware(['auth'])->group(function () {
    Route::redirect('settings', 'settings/profile');
    Route::redirect('admin', 'dashboard', 301);
    Route::redirect('home', 'dashboard', 301);

    Route::resource('typeitems',TypeItemsController::class);
    Route::resource('items',ItemsController::class);
    // Route::resource('tables',MejaController::class);
    Route::resource('orders',OrderController::class);
    Route::get('/kitchen', KitchenOrders::class)->name('kitchen.index');
    // Route::get('/admin/meja', function () {
    //     return view('tables');
    // })->name('tables.index');
    // Route::get('/admin/meja', Tables::class)->name('tables.index');

    Route::get('settings/profile', Profile::class)->name('settings.profile');
    Route::get('settings/password', Password::class)->name('settings.password');
    Route::get('settings/appearance', Appearance::class)->name('settings.appearance');
});


require __DIR__.'/auth.php';
