<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin as Admin;
use App\Http\Controllers\User as User;
use App\Http\Controllers\AuthController; // Asumsi controller login dipisah atau di Admin
use App\Http\Controllers\User\TestBookingController;

/*
|--------------------------------------------------------------------------
| 1. PUBLIK / GUEST (Pelanggan)
|--------------------------------------------------------------------------
| Bebas akses, tidak perlu login.
*/

Route::group([], function () {
    Route::get('/', [User\BerandaController::class, 'index'])->name('beranda');

    // Fitur Buket
    Route::get('/pesan-buket', [User\PesanBuketController::class, 'index'])->name('pesan.buket');
    Route::get('/pesan-buket/{id}', [User\PesanBuketController::class, 'detail'])->name('detail.buket');
    Route::get('/formulir-buket/{id}', [User\PesanBuketController::class, 'formulir'])->name('formulir.buket');
    Route::post('/formulir-buket/store', [User\PesanBuketController::class, 'store'])->name('transaksi.buket.store');
    // Fitur Foto
    Route::get('/booking-foto', [User\BookingFotoController::class, 'index'])->name('booking.foto');
    Route::get('/detail-paket-foto/{id}', [User\BookingFotoController::class, 'detail'])->name('detail.foto'); // Tambah {id}
    Route::get('/formulir-pemesanan-foto', [User\BookingFotoController::class, 'formulir'])->name('formulir.foto');

    Route::get('/load-calendar', [User\BookingFotoController::class, 'loadCalendar'])->name('ajax.load-calendar');
    Route::get('/cek-slot-foto', [User\BookingFotoController::class, 'cekSlot'])->name('ajax.check-slot');

    Route::post('/simpan-booking-foto', [User\BookingFotoController::class, 'store'])->name('transaksi.foto.store');
    Route::get('/cancel-booking', [User\BookingFotoController::class, 'cancelBooking'])->name('booking.cancel');
});

/*
|--------------------------------------------------------------------------
| 2. AUTENTIKASI (Login/Logout)
|--------------------------------------------------------------------------
*/
// Menampilkan form login
Route::get('/login', [Admin\AuthController::class, 'login'])->name('login')->middleware('guest');
// Memproses data login (YANG SEBELUMNYA KURANG)
Route::post('/login', [Admin\AuthController::class, 'authenticate'])->name('login.proses');
// Logout
Route::post('/logout', [Admin\AuthController::class, 'logout'])->name('logout');


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

    Route::redirect('/', '/admin/beranda');

    // Dashboard
    Route::get('/beranda', [Admin\BerandaController::class, 'index'])->name('beranda');

    Route::get('/pesanan-buket', [Admin\PesananBuketController::class, 'index'])
        ->name('pesanan-buket.index');

    // Rute Update Status (Put) - Pastikan nama ini unik
    Route::put('/pesanan-buket/update-status/{id}', [Admin\PesananBuketController::class, 'updateStatus'])
        ->name('pesanan-buket.update-status');

    Route::get('/pesanan-foto', [Admin\PesananFotoController::class, 'index'])
        ->name('pesanan-foto.index');

    // Rute Update Status (Put) - Pastikan nama ini unik
    Route::put('/pesanan-foto/update-status/{id}', [Admin\PesananFotoController::class, 'updateStatus'])
        ->name('pesanan-foto.update-status');

    Route::get('/riwayat-pesanan', [Admin\HistoriPesananController::class, 'index'])->name('riwayat');

    // Manajemen Produk (Master Data)
    Route::resource('produk-buket', Admin\BuketController::class); // Perbaiki namespace jika perlu
    Route::resource('paket-foto', Admin\FotoController::class);    // Perbaiki namespace jika perlu
    Route::resource('additional', Admin\AdditionalController::class)->except(['index', 'show']);

    // Manajemen User (Khusus Owner)
    Route::resource('kelola-admin', Admin\ManajemenAdminController::class);

    // Profil Diri
    Route::get('/profil', [Admin\ProfilController::class, 'index'])->name('profil.index');
    Route::put('/profil/update', [Admin\ProfilController::class, 'update'])->name('profil.simpan');
    Route::put('/profil/password', [Admin\ProfilController::class, 'updatePassword'])->name('profil.password');
});
