<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\BookingController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\PhotoController;
use App\Http\Controllers\HomeController;


use App\Http\Controllers\Auth\GoogleController;

Route::get('/auth/google', [GoogleController::class, 'redirectToGoogle'])->name('google.login');
Route::get('/auth/google/callback', [GoogleController::class, 'handleGoogleCallback']);
Route::get('/google/register', [GoogleController::class, 'showPasswordForm'])->name('google.register.form');
Route::post('/google/register', [GoogleController::class, 'registerWithPassword'])->name('google.register.save');

// ✅ Login & Logout
Route::get('/login', [AuthController::class, 'showloginForm'])->name('login');
Route::post('/login', [AuthController::class, 'login']);
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
Route::post('/register/customer', [AuthController::class, 'registerCustomer'])->name('register.customer');
Route::get('/', [AuthController::class, 'dashboardCustomer'])->name('dashboard.customer');
Route::get('/customer/contact', [HomeController::class, 'contact'])->name('customer.contact');


// 🔹 **Dashboard untuk semua pengguna yang login**
Route::middleware('auth')->group(function () {
    Route::get('/dashboard', [AuthController::class, 'dashboard'])->name('dashboard');
});

Route::prefix('admin')->middleware(['auth', 'admin'])->group(function () {
    Route::get('/dashboard', [AdminController::class, 'dashboard'])->name('admin.dashboard');
    // 📌 1. Tampilkan Daftar Booking
    Route::get('/bookings', [AdminController::class, 'showBookings'])->name('admin.bookings');
    Route::delete('/bookings/{id}', [AdminController::class, 'destroy'])->name('admin.bookings.destroy');

    // 📌 2. Terima & Tolak Booking
    Route::post('/bookings/{id}/accept', [AdminController::class, 'acceptBooking'])->name('admin.bookings.accept');
    Route::post('/bookings/{id}/decline', [AdminController::class, 'declineBooking'])->name('admin.bookings.decline');
    // 📌 3. Tampilkan & Hapus Pengguna
    Route::get('/users', [AdminController::class, 'showUsers'])->name('admin.users');
    Route::delete('/users/{id}', [AdminController::class, 'deleteUser'])->name('admin.users.delete');
    Route::get('/users/{id}/edit', [AdminController::class, 'editUser'])->name('admin.users.edit');
    Route::put('/users/{id}', [AdminController::class, 'updateUser'])->name('admin.users.update');
    Route::post('/users/store', [AdminController::class, 'storeUser'])->name('admin.users.store');
    // 📌 4. Upload & Kelola Foto
    Route::get('/upload', [AdminController::class, 'uploadPage'])->name('admin.upload');
    Route::post('/upload', [AdminController::class, 'storeUpload'])->name('admin.upload.store');
    Route::patch('/upload/reset-token/{id}', [AdminController::class, 'resetToken'])->name('admin.upload.resetToken');
    Route::delete('/photo/{photo}/clear-token', [AdminController::class, 'hapustoken'])->name('photo.clearToken');
    // 📌 5. Laporan & Statistik
    Route::get('/reports', [AdminController::class, 'showPricelist'])->name('admin.reports');
    Route::post('/reports/store', [AdminController::class, 'storePricelist'])->name('admin.reports.store');
    Route::get('/reports/{id}/edit', [AdminController::class, 'edit'])->name('admin.reports.edit');
    Route::put('/reports/{id}', [AdminController::class, 'update'])->name('admin.reports.update');
    Route::delete('/reports/{id}', [AdminController::class, 'destroyPricelist'])->name('admin.reports.destroy');
});


Route::prefix('user')->middleware(['auth', 'user'])->group(function () {
    Route::get('/dashboard', [UserController::class, 'dashboard'])->name('user.dashboard');
    Route::get('/bookings', [UserController::class, 'myBookings'])->name('user.bookings');
    Route::post('/bookings/{id}/accept', [UserController::class, 'acceptBooking'])->name('user.bookings.accept');
    Route::post('/bookings/{id}/reject', [UserController::class, 'rejectBooking'])->name('user.bookings.reject');
    Route::post('/bookings/{id}/keterangan', [UserController::class, 'updateKeterangan'])->name('karyawan.booking.keterangan');
    
    Route::post('/bookings/{booking}/bukti-pelunasan', [BookingController::class, 'uploadBuktiPelunasan'])
    ->name('karyawan.bookings.bukti_pelunasan');
    Route::get('/profile', [UserController::class, 'profile'])->name('user.profile');
    Route::get('/upload', [PhotoController::class, 'create'])->name('user.upload.create');
    Route::post('/upload', [PhotoController::class, 'store'])->name('user.upload.store');
    Route::get('/bookings/{customer_id}', [BookingController::class, 'getBookings']);
    Route::get('/photos/{token}', [UserController::class, 'showPhotos'])->name('photos.view');
    Route::get('/customers', [UserController::class, 'showCustomers'])->name('user.customers');
    Route::get('/customers/{id}/edit', [UserController::class, 'edit'])->name('user.customers.edit');
    Route::delete('/customers/{id}', [UserController::class, 'deleteCustomer'])->name('user.customers.delete');  
    Route::post('/profile/update', [UserController::class, 'updateProfile'])->name('user.profile.update');
    Route::put('/customers/{id}', [UserController::class, 'updateCustomer'])->name('user.customers.update');
});


// ✅ **Booking Routes untuk Customer**
Route::middleware('auth')->group(function () {

    Route::get('/booking', [BookingController::class, 'create'])->name('booking.create');
    Route::post('/booking/store', [BookingController::class, 'store'])->name('booking.store');
    Route::post('/booking/{id}/upload-bukti', [BookingController::class, 'uploadBukti'])->name('booking.uploadBukti');
    Route::get('/keranjang', [BookingController::class, 'keranjang'])->name('booking.keranjang');
    Route::get('/photos/verify', [PhotoController::class, 'verifyToken'])->name('photos.verify');
    Route::get('/customer/photos', [PhotoController::class, 'index'])->name('customer.photos');
    Route::get('/photos/download/{token}', [PhotoController::class, 'download'])->name('photo.download');
    Route::get('/photos/download-all', [PhotoController::class, 'downloadAll'])->name('photos.downloadAll');
    Route::put('/customer/profile', [HomeController::class, 'update'])->name('customer.profile.update');
});
// ✅ **Fitur tambahan**
Route::get('/jadwal', function () {
    return view('fitur.jadwal');
})->name('jadwal');
    Route::get('/bookings', [BookingController::class, 'getBookingsCustomer']);