<?php

use App\Http\Controllers\admin\AdminAboutusController;
use App\Http\Controllers\admin\AdminContactController;
use App\Http\Controllers\admin\AdminDashboardController;
use App\Http\Controllers\admin\AdminDisclaimerController;
use App\Http\Controllers\admin\AdminFaqController;
use App\Http\Controllers\admin\AdminInquiryController;
use App\Http\Controllers\admin\AdminLoginController;
use App\Http\Controllers\admin\AdminPrivacyPolicyController;
use App\Http\Controllers\admin\AdminProfileController;
use App\Http\Controllers\admin\AdminTermsConditionController;
use App\Http\Controllers\admin\AdminUserProfileController;
use App\Http\Controllers\admin\CustomerController;
use App\Http\Controllers\admin\HomeController as AdminHomeController;
use App\Http\Controllers\admin\PreferenceController;
use App\Http\Controllers\Auth\CustomPasswordResetController;
use App\Http\Controllers\Auth\EmailVerificationController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\ProfileController;
use App\Http\Controllers\Auth\RegisterController;
use App\Http\Controllers\ChatController;
use App\Http\Controllers\TrialController;
use App\Http\Controllers\website\AboutUsController;
use App\Http\Controllers\website\ContactUsController;
use App\Http\Controllers\website\FaqController;
use App\Http\Controllers\website\HomeController;
use App\Http\Controllers\website\PrivacyPolicyController;
use App\Http\Controllers\website\TermAndConditionController;
use App\Http\Controllers\website\VerificationNotification;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\EmailVerificationRequest;

// Email verification routes
// Route::get('/email/verify', function () {
//     return view('auth.verify-email'); // Create this blade if needed
//     // })->middleware('auth')->name('verification.notice');
// })->name('verification.notice');

Route::get('/email/verify', [VerificationNotification::class, 'email_verify'])->name('verification.notice');

// Route::get('/email/verify/{id}/{hash}', [EmailVerificationController::class, 'verify'])
//     ->middleware(['signed'])
//     ->name('verification.verify');
Route::get('/email/verify/{id}/{hash}', [EmailVerificationController::class, 'verify'])
    ->middleware(['signed']) // No 'auth' here
    ->name('verification.verify');



// Route::post('/email/verification-notification', function(){

// });
Route::post('/email/verification-notification', [VerificationNotification::class, 'index'])->name('verification.send');
// Route::post('/email/verification-notification', function (Request $request) {
//     $request->user()->sendEmailVerificationNotification();

//     return redirect()->route('verification.notice')->with('toast', [
//         'type' => 'success',
//         'message' => 'Verification link sent!'
//     ]);
// })->middleware(['auth', 'throttle:6,1'])->name('verification.send');

Route::get('/email/verified-success', function () {
    return view('auth.verified-success');
});


// Route::get('/', function () {
//     return view('welcome');
// });


// Route::middleware(['verified'])->group(function () {
Route::get('/', [HomeController::class, 'index'])->name('website.home');

Route::get('/faq', [FaqController::class, 'index'])->name('website.faq');
Route::get('/about-us', [AboutUsController::class, 'index'])->name('website.about-us');

Route::get('/contact-us', [ContactUsController::class, 'index'])->name('website.contactus');
Route::post('/contact-us', [ContactUsController::class, 'store'])->name('contact.store');

Route::get('/privacy-policy', [PrivacyPolicyController::class, 'index'])->name('website.privacypolicy');
Route::get('/term-and-condition', [TermAndConditionController::class, 'index'])->name('website.termandcondition');
// });

Route::post('/register', [RegisterController::class, 'store'])->name('register.store');

// Route::get('/login', [LoginController::class, 'index'])->name('login');

Route::post('/login', [LoginController::class, 'login'])->name('login.submit');


Route::get('/profile', [ProfileController::class, 'index'])->name('website.profile')->middleware('auth');


// Route::get('/contact', [CustomPasswordResetController::class, 'send'])->name('contact.send');


Route::post('/password/email', [CustomPasswordResetController::class, 'sendResetLink'])->name('password.email');
Route::post('/password/reset', [CustomPasswordResetController::class, 'resetPassword'])->name('password.update');

// Route to handle password reset form with token
Route::get('/password/reset/{token}', function ($token) {
    return view('website.passwords.reset', ['token' => $token, 'email' => request('email')]);
})->name('password.reset');

Route::middleware(['auth', 'verified'])->group(function () {
    // Route::get('/user-profile', [UserProfileController::class, 'create'])->name('user.profile.create');
    Route::get('/profile', [ProfileController::class, 'index'])->name('website.profile');
    Route::post('/user-profile', [ProfileController::class, 'store'])->name('user.profile.store');
    Route::post('/delete-profile-photo', [ProfileController::class, 'deletePhoto'])->name('delete.profile.photo');
    Route::post('/profile/update-password', [ProfileController::class, 'updatePassword'])->name('profile.updatePassword');
    Route::get('/logout', [ProfileController::class, 'logout'])->name('logout');
    Route::delete('/account/delete', [ProfileController::class, 'destroy'])->name('account.delete');

    Route::post('/like-profile', [ProfileController::class, 'likeProfile'])->name('like.profile');

    Route::get('/chat/messages/{receiverId}', [ChatController::class, 'fetchMessages']);
    Route::post('/chat/send', [ChatController::class, 'sendMessage']);
    Route::get('/chat/conversations', [ChatController::class, 'conversations']);

    // Route::get('/preview-message/{id}', [ChatController::class, 'preview'])->name('preview.message');

    Route::post('/start-trial', [TrialController::class, 'start'])->name('start.trial');
    Route::post('/cancel-trial', [TrialController::class, 'cancel'])->name('cancel.trial');
});

// Route::post('/like-profile', [ProfileController::class, 'toggleLike'])->middleware('auth');


Route::group(['prefix' => 'backoffice'], function () {
    Route::group(['middleware' => 'admin.guest'], function () {
        Route::get('/login', [AdminLoginController::class, 'login'])->name('admin.login');
        Route::post('/login/authenticate', [AdminLoginController::class, 'authenticate'])->name('admin.login.authenticate');
    });
    Route::group(['middleware' => 'admin.auth'], function () {
        Route::get('/dashboard', [AdminDashboardController::class, 'index'])->name('admin.dashboard');
        Route::get('/logout', [AdminDashboardController::class, 'logout'])->name('admin.logout');

        Route::get('/home', [AdminHomeController::class, 'index'])->name('admin.home');
        Route::post('/home/store', [AdminHomeController::class, 'store'])->name('home.store');

        Route::get('/inquires', [AdminInquiryController::class, 'index'])->name('admin.inquires');

        Route::get('/about-us', [AdminAboutusController::class, 'index'])->name('admin.aboutus');
        Route::post('/aboutus', [AdminAboutusController::class, 'store'])->name('admin.aboutus.store');

        // Route::get('/contact', [AdminContactController::class, 'index'])->name('admin.contact');
        // Route::post('/contactus', [AdminAboutusController::class, 'store'])->name('admin.contact.store');

        Route::get('/faq', [AdminFaqController::class, 'index'])->name('admin.faq');
        Route::post('/faq', [AdminFaqController::class, 'store'])->name('admin.faq.store');

        Route::get('/privacy-policy', [AdminPrivacyPolicyController::class, 'index'])->name('admin.privacy.policy');
        Route::post('/privacypolicy', [AdminPrivacyPolicyController::class, 'store'])->name('admin.privacypolicy.store');

        Route::get('/terms-and-conditions', [AdminTermsConditionController::class, 'index'])->name('admin.term.condition');
        Route::post('/termandcondition', [AdminTermsConditionController::class, 'store'])->name('admin.termandcondition.store');

        Route::get('/disclaimer', [AdminDisclaimerController::class, 'index'])->name('admin.disclaimer');

        Route::get('preferences', [PreferenceController::class, 'index'])->name('preferences.index');
        Route::post('preferences/store', [PreferenceController::class, 'store'])->name('preferences.store');

        Route::get('customerlist', [CustomerController::class, 'index'])->name('customerlist.index');
        Route::get('customer/{id}/view', [CustomerController::class, 'details'])->name('customerlist.details');
        Route::post('customerlist/toggle/{user}', [CustomerController::class, 'toggleStatus'])->name('customerlist.toggle');
        Route::post('customers/{user}/warning', [CustomerController::class, 'sendWarning'])->name('admin.customer.warning');

        Route::get('profile', [AdminProfileController::class, 'edit'])->name('admin.profile.edit');
        Route::post('profile', [AdminProfileController::class, 'update'])->name('admin.profile.update');

        Route::get('/user-profiles', [AdminUserProfileController::class, 'index'])->name('admin.user_profiles');
        Route::patch('/verify-profile/{id}', [AdminUserProfileController::class, 'verify'])->name('admin.verify.profile');
    });
});
