<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\Http\Controllers\PropertyController;
use App\Http\Controllers\Api\PropertyApiController;
use App\Http\Controllers\ContactUsController;
use App\Http\Controllers\FrontendController;
// use App\Http\Controllers\Api\WhatsAppWebhookController;
// use App\Http\Controllers\Api\WhatsAppChatController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/



//api
Route::get('/api', [PropertyApiController::class, 'getAllCategories']);
Route::get('/api/{category}', [PropertyApiController::class, 'getByCategory']);
Route::get('/api/{category}/{slug}', [PropertyApiController::class, 'showByCategoryAndSlug']);

Route::get('/api/property-summary', [PropertyApiController::class, 'summary']);
Route::get('/api/property-filter', [PropertyApiController::class, 'filter']);


//BackEnd
Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified',
])->group(function () {
    Route::get('/dashboard', function () {
        return view('backend.dashboard');
    })->name('dashboard');
});

Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified',
])->group(function () {
    Route::get('/profile', function () {
        return view('profile.show'); 
    })->name('profile.show');
});

Route::get('/user/profile', function () {
    return redirect('/profile');
});

Route::middleware(['auth', 'role:super-admin'])->group(function () {
    Route::get('/admin/list', [UserController::class, 'admin'])->name('super.admin');
    Route::get('/user/list', [UserController::class, 'user'])->name('super.user');

    // Manage Users
    Route::get('/user/create', [UserController::class, 'create'])->name('user.create');
    Route::post('/user/store', [UserController::class, 'store'])->name('user.store');
    Route::get('/user/{id}/edit', [UserController::class, 'edit'])->name('user.edit');
    Route::put('/user/{id}', [UserController::class, 'update'])->name('user.update');
    Route::delete('/user/{id}', [UserController::class, 'destroy'])->name('user.destroy');
    Route::resource('user', UserController::class);
});

Route::middleware(['auth', 'role:admin'])->group(function () {
    Route::get('/properties', [PropertyController::class, 'index'])->name('properties.index');
    Route::get('/properties/create', [PropertyController::class, 'create'])->name('properties.create');
   // Route::post('/properties', [PropertyController::class, 'store'])->name('properties.store');
    Route::post('/properties', [PropertyController::class, 'store'])->name('properties.store');


    Route::get('/properties/{property}/edit', [PropertyController::class, 'edit'])->name('properties.edit');
    Route::put('/properties/{property}', [PropertyController::class, 'update'])->name('properties.update');
    Route::delete('/properties/{property}', [PropertyController::class, 'destroy'])->name('properties.destroy');

    Route::get('/new/user', [UserController::class, 'NewUsers'])->name('new.user');
    Route::post('/new/store', [UserController::class, 'UserStore'])->name('users.store');

    Route::get('/manage-admin', [UserController::class, 'ManageAdmin'])->name('manage.admin');
    
    Route::get('/edit/{id}/user', [UserController::class, 'editUser'])->name('edit.user');
    Route::put('/update/{id}', [UserController::class, 'updateUser'])->name('update.user');

    //delete
    Route::delete('/delete/{id}', [UserController::class, 'UserDestroy'])->name('destroy.user');

});

Route::middleware(['auth', 'role:admin|user'])->group(function () {
    Route::get('/contact-submissions', [UserController::class, 'Lead'])->name('contact.Lead');
});


// Route::get('/whatsapp', [WhatsAppChatController::class, 'showForm']);
// Route::post('/whatsapp/send', [WhatsAppChatController::class, 'sendWhatsAppMessage'])->name('whatsapp.send');
//Route::view('/whatsapp', 'whatsapp');

Route::middleware(['auth', 'role:user'])->group(function () {
  Route::get('/all-properties', [PropertyController::class, 'allProperties'])->name('properties.all');
});

Route::middleware(['auth', 'role:user'])->group(function () {
  Route::get('/all-properties', [PropertyController::class, 'allProperties'])->name('properties.all');
});

//FrontEnd
Route::get('/', [FrontendController::class, 'Home'])->name('Home.Page');

Route::get('/contact', [FrontendController::class, 'Contact'])->name('contact.us');
Route::post('/lead', [ContactUsController::class, 'store'])->name('contact.store');
Route::get('/about-us', [FrontendController::class, 'About'])->name('about.us');
Route::get('/search', [FrontendController::class, 'search'])->name('frontend.search');


// Wildcard routes
Route::get('/{category}', [FrontendController::class, 'Buy'])->name('buy.Page');
Route::get('/{category}/{slug}', [FrontendController::class, 'PropertyDetails'])->name('property.details');
